Package edu.uci.ics.jung.io.graphml
Class GraphMLReader2<G extends Hypergraph<V,E>,V,E>
- java.lang.Object
-
- edu.uci.ics.jung.io.graphml.GraphMLReader2<G,V,E>
-
- Type Parameters:
G
- The graph type to be read from the GraphML fileV
- the vertex type The vertex type used by the graphV
- the edge type The edge type used by the graph
- All Implemented Interfaces:
GraphReader<G,V,E>
public class GraphMLReader2<G extends Hypergraph<V,E>,V,E> extends java.lang.Object implements GraphReader<G,V,E>
Reads in data from a GraphML-formatted file and generates graphs based on that data. Does not currently support nested graphs.Note that the user is responsible for supplying a graph
Transformer
that will create graphs capable of supporting the edge types in the supplied GraphML file. If the graph generated by theFactory
is not compatible (for example: if the graph does not accept directed edges, and the GraphML file contains a directed edge) then the results are graph-implementation-dependent.- See Also:
- "http://graphml.graphdrawing.org/specification.html"
-
-
Field Summary
Fields Modifier and Type Field Description protected GraphMLDocument
document
protected com.google.common.base.Function<EdgeMetadata,E>
edgeTransformer
protected java.io.Reader
fileReader
protected com.google.common.base.Function<GraphMetadata,G>
graphTransformer
protected com.google.common.base.Function<HyperEdgeMetadata,E>
hyperEdgeTransformer
protected boolean
initialized
private java.io.InputStream
inputStream
protected ElementParserRegistry<G,V,E>
parserRegistry
protected com.google.common.base.Function<NodeMetadata,V>
vertexTransformer
protected javax.xml.stream.XMLEventReader
xmlEventReader
-
Constructor Summary
Constructors Constructor Description GraphMLReader2(java.io.InputStream inputStream, com.google.common.base.Function<GraphMetadata,G> graphTransformer, com.google.common.base.Function<NodeMetadata,V> vertexTransformer, com.google.common.base.Function<EdgeMetadata,E> edgeTransformer, com.google.common.base.Function<HyperEdgeMetadata,E> hyperEdgeTransformer)
Constructs a GraphML reader around the given reader.GraphMLReader2(java.io.Reader fileReader, com.google.common.base.Function<GraphMetadata,G> graphTransformer, com.google.common.base.Function<NodeMetadata,V> vertexTransformer, com.google.common.base.Function<EdgeMetadata,E> edgeTransformer, com.google.common.base.Function<HyperEdgeMetadata,E> hyperEdgeTransformer)
Constructs a GraphML reader around the given reader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the GraphML reader and disposes of any resources.com.google.common.base.Function<EdgeMetadata,E>
getEdgeTransformer()
Gets the current Function that is being used for edge objects.GraphMLDocument
getGraphMLDocument()
Returns the object that contains the metadata read in from the GraphML documentcom.google.common.base.Function<GraphMetadata,G>
getGraphTransformer()
Gets the current Function that is being used for graph objects.com.google.common.base.Function<HyperEdgeMetadata,E>
getHyperEdgeTransformer()
Gets the current Function that is being used for hyperedge objects.com.google.common.base.Function<NodeMetadata,V>
getVertexTransformer()
Gets the current Function that is being used for vertex objects.void
init()
Verifies the object state and initializes this reader.G
readGraph()
Reads a single graph object from the GraphML document.
-
-
-
Field Detail
-
xmlEventReader
protected javax.xml.stream.XMLEventReader xmlEventReader
-
fileReader
protected java.io.Reader fileReader
-
graphTransformer
protected com.google.common.base.Function<GraphMetadata,G extends Hypergraph<V,E>> graphTransformer
-
vertexTransformer
protected com.google.common.base.Function<NodeMetadata,V> vertexTransformer
-
edgeTransformer
protected com.google.common.base.Function<EdgeMetadata,E> edgeTransformer
-
hyperEdgeTransformer
protected com.google.common.base.Function<HyperEdgeMetadata,E> hyperEdgeTransformer
-
initialized
protected boolean initialized
-
document
protected final GraphMLDocument document
-
parserRegistry
protected final ElementParserRegistry<G extends Hypergraph<V,E>,V,E> parserRegistry
-
inputStream
private java.io.InputStream inputStream
-
-
Constructor Detail
-
GraphMLReader2
public GraphMLReader2(java.io.Reader fileReader, com.google.common.base.Function<GraphMetadata,G> graphTransformer, com.google.common.base.Function<NodeMetadata,V> vertexTransformer, com.google.common.base.Function<EdgeMetadata,E> edgeTransformer, com.google.common.base.Function<HyperEdgeMetadata,E> hyperEdgeTransformer)
Constructs a GraphML reader around the given reader. This constructor requires the user to supply transformation functions to convert from the GraphML metadata to Graph, Vertex, Edge instances. These Function functions can be used as purely factories (i.e. the metadata is disregarded) or can use the metadata to set particular fields in the objects.- Parameters:
fileReader
- the reader for the input GraphML document.graphTransformer
- Transformation function to convert from GraphML GraphMetadata to graph objects. This must be non-null.vertexTransformer
- Transformation function to convert from GraphML NodeMetadata to vertex objects. This must be non-null.edgeTransformer
- Transformation function to convert from GraphML EdgeMetadata to edge objects. This must be non-null.hyperEdgeTransformer
- Transformation function to convert from GraphML HyperEdgeMetadata to edge objects. This must be non-null.- Throws:
java.lang.IllegalArgumentException
- thrown if any of the arguments are null.
-
GraphMLReader2
public GraphMLReader2(java.io.InputStream inputStream, com.google.common.base.Function<GraphMetadata,G> graphTransformer, com.google.common.base.Function<NodeMetadata,V> vertexTransformer, com.google.common.base.Function<EdgeMetadata,E> edgeTransformer, com.google.common.base.Function<HyperEdgeMetadata,E> hyperEdgeTransformer)
Constructs a GraphML reader around the given reader. This constructor requires the user to supply transformation functions to convert from the GraphML metadata to Graph, Vertex, Edge instances. These Function functions can be used as purely factories (i.e. the metadata is disregarded) or can use the metadata to set particular fields in the objects.- Parameters:
inputStream
- the inputstream for the input GraphML document.graphTransformer
- Transformation function to convert from GraphML GraphMetadata to graph objects. This must be non-null.vertexTransformer
- Transformation function to convert from GraphML NodeMetadata to vertex objects. This must be non-null.edgeTransformer
- Transformation function to convert from GraphML EdgeMetadata to edge objects. This must be non-null.hyperEdgeTransformer
- Transformation function to convert from GraphML HyperEdgeMetadata to edge objects. This must be non-null.- Throws:
java.lang.IllegalArgumentException
- thrown if any of the arguments are null.
-
-
Method Detail
-
getGraphTransformer
public com.google.common.base.Function<GraphMetadata,G> getGraphTransformer()
Gets the current Function that is being used for graph objects.- Returns:
- the current Function.
-
getVertexTransformer
public com.google.common.base.Function<NodeMetadata,V> getVertexTransformer()
Gets the current Function that is being used for vertex objects.- Returns:
- the current Function.
-
getEdgeTransformer
public com.google.common.base.Function<EdgeMetadata,E> getEdgeTransformer()
Gets the current Function that is being used for edge objects.- Returns:
- the current Function.
-
getHyperEdgeTransformer
public com.google.common.base.Function<HyperEdgeMetadata,E> getHyperEdgeTransformer()
Gets the current Function that is being used for hyperedge objects.- Returns:
- the current Function.
-
init
public void init() throws GraphIOException
Verifies the object state and initializes this reader. All Function properties must be set and be non-null or aGraphReaderException
will be thrown. This method may be called more than once. Successive calls will have no effect.- Throws:
GraphIOException
- thrown if an error occurred.
-
close
public void close() throws GraphIOException
Closes the GraphML reader and disposes of any resources.- Specified by:
close
in interfaceGraphReader<G extends Hypergraph<V,E>,V,E>
- Throws:
GraphIOException
- thrown if an error occurs.
-
getGraphMLDocument
public GraphMLDocument getGraphMLDocument()
Returns the object that contains the metadata read in from the GraphML document- Returns:
- the GraphML document
-
readGraph
public G readGraph() throws GraphIOException
Reads a single graph object from the GraphML document. Automatically callsinit
to initialize the state of the reader.- Specified by:
readGraph
in interfaceGraphReader<G extends Hypergraph<V,E>,V,E>
- Returns:
- the graph that was read if one was found, otherwise null.
- Throws:
GraphIOException
- thrown if an error occurred.
-
-