Package edu.uci.ics.jung.io
Class GraphMLReader<G extends Hypergraph<V,E>,V,E>
java.lang.Object
org.xml.sax.helpers.DefaultHandler
edu.uci.ics.jung.io.GraphMLReader<G,V,E>
- All Implemented Interfaces:
ContentHandler,DTDHandler,EntityResolver,ErrorHandler
Reads in data from a GraphML-formatted file and generates graphs based on
that data. Currently supports the following parts of the GraphML
specification:
- graphs and hypergraphs
- directed and undirected edges
- graph, vertex, edge
data - graph, vertex, edge descriptions and
datadescriptions - vertex and edge IDs
get methods.
Does not currently support nested graphs or ports.
Note that the user is responsible for supplying a graph
Factory that can support the edge types in the supplied
GraphML file. If the graph generated by the Factory 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumprotected static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Eprotected Gprotected Stringprotected LinkedList<GraphMLReader.TagState> protected StringBuilderprotected Vprotected EdgeTypeprotected com.google.common.base.Supplier<E> protected Map<String, GraphMLMetadata<E>> protected com.google.common.base.Supplier<G> protected Map<String, GraphMLMetadata<G>> protected Collection<V> protected GraphMLReader.KeyTypeprotected SAXParserprotected com.google.common.collect.BiMap<String, GraphMLReader.TagState> protected com.google.common.base.Supplier<V> protected Map<String, GraphMLMetadata<V>> -
Constructor Summary
ConstructorsConstructorDescriptionCreates aGraphMLReaderinstance that assigns the vertex and edgeidstrings to be the vertex and edge objects, as well as their IDs.GraphMLReader(com.google.common.base.Supplier<V> vertex_factory, com.google.common.base.Supplier<E> edge_factory) Creates aGraphMLReaderinstance with the specified vertex and edge factories. -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> voidaddDatum(Map<String, GraphMLMetadata<T>> metadata, T current_elt, String text) protected voidassignEdgeSourceTarget(E e, Attributes atts, Map<String, String> edge_atts) voidcharacters(char[] ch, int start, int length) protected voidprotected voidcreateEdge(Attributes atts, GraphMLReader.TagState state) protected voidcreateKey(Attributes atts) protected voidcreateVertex(Attributes atts) voidendElement(String uri, String name, String qName) getAttributeMap(Attributes atts) Returns a bidirectional map relating edges and IDs.protected voidhandleData(Attributes atts) protected voidThis is separate from initialize() because these data structures are shared among all graphs loaded (i.e., they're defined insidegraphmlrather thangraph.voidPopulates the specified graph with the data parsed from the reader.voidPopulates the specified graph with the data parsed from the specified file.loadMultiple(Reader reader, com.google.common.base.Supplier<G> graph_factory) Returns a list of the graphs parsed from the specified reader, as created by the specified Supplier.loadMultiple(String filename, com.google.common.base.Supplier<G> graph_factory) Returns a list of the graphs parsed from the specified file, as created by the specified Supplier.protected voidvoidstartElement(String uri, String name, String qName, Attributes atts) Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warningMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.xml.sax.ContentHandler
declaration
-
Field Details
-
saxp
-
default_edgetype
-
current_graph
-
current_vertex
-
current_edge
-
current_key
-
current_states
-
tag_state
-
graph_factory
-
vertex_factory
-
edge_factory
-
vertex_ids
-
edge_ids
-
graph_metadata
-
vertex_metadata
-
edge_metadata
-
vertex_desc
-
edge_desc
-
graph_desc
-
key_type
-
hyperedge_vertices
-
graphs
-
current_text
-
-
Constructor Details
-
GraphMLReader
public GraphMLReader(com.google.common.base.Supplier<V> vertex_factory, com.google.common.base.Supplier<E> edge_factory) throws ParserConfigurationException, SAXException Creates aGraphMLReaderinstance with the specified vertex and edge factories.- Parameters:
vertex_factory- the vertex supplier to use to create vertex objectsedge_factory- the edge supplier to use to create edge objects- Throws:
ParserConfigurationException- if a SAX parser cannot be constructedSAXException- if the SAX parser factory cannot be constructed
-
GraphMLReader
Creates aGraphMLReaderinstance that assigns the vertex and edgeidstrings to be the vertex and edge objects, as well as their IDs. Note that this requires that (a) each edge have a valid ID, which is not normally a requirement for edges in GraphML, and (b) that the vertex and edge types be assignment-compatible withString.- Throws:
ParserConfigurationException- if a SAX parser cannot be constructedSAXException- if the SAX parser factory cannot be constructed
-
-
Method Details
-
loadMultiple
public List<G> loadMultiple(Reader reader, com.google.common.base.Supplier<G> graph_factory) throws IOException Returns a list of the graphs parsed from the specified reader, as created by the specified Supplier.- Parameters:
reader- the source of the graph data in GraphML formatgraph_factory- used to build graph instances- Returns:
- the graphs parsed from the specified reader
- Throws:
IOException- if an error is encountered while parsing the graph
-
loadMultiple
public List<G> loadMultiple(String filename, com.google.common.base.Supplier<G> graph_factory) throws IOException Returns a list of the graphs parsed from the specified file, as created by the specified Supplier.- Parameters:
filename- the source of the graph data in GraphML formatgraph_factory- used to build graph instances- Returns:
- the graphs parsed from the specified file
- Throws:
IOException- if an error is encountered while parsing the graph
-
load
Populates the specified graph with the data parsed from the reader.- Parameters:
reader- the source of the graph data in GraphML formatg- the graph instance to populate- Throws:
IOException- if an error is encountered while parsing the graph
-
load
Populates the specified graph with the data parsed from the specified file.- Parameters:
filename- the source of the graph data in GraphML formatg- the graph instance to populate- Throws:
IOException- if an error is encountered while parsing the graph
-
clearData
protected void clearData() -
initializeData
protected void initializeData()This is separate from initialize() because these data structures are shared among all graphs loaded (i.e., they're defined insidegraphmlrather thangraph. -
parse
- Throws:
IOException
-
startElement
public void startElement(String uri, String name, String qName, Attributes atts) throws SAXNotSupportedException - Specified by:
startElementin interfaceContentHandler- Overrides:
startElementin classDefaultHandler- Throws:
SAXNotSupportedException
-
characters
- Specified by:
charactersin interfaceContentHandler- Overrides:
charactersin classDefaultHandler- Throws:
SAXNotSupportedException
-
addDatum
protected <T> void addDatum(Map<String, GraphMLMetadata<T>> metadata, T current_elt, String text) throws SAXNotSupportedException- Throws:
SAXNotSupportedException
-
endElement
- Specified by:
endElementin interfaceContentHandler- Overrides:
endElementin classDefaultHandler- Throws:
SAXNotSupportedException
-
getAttributeMap
-
handleData
- Throws:
SAXNotSupportedException
-
createKey
- Throws:
SAXNotSupportedException
-
createVertex
- Throws:
SAXNotSupportedException
-
createEdge
protected void createEdge(Attributes atts, GraphMLReader.TagState state) throws SAXNotSupportedException - Throws:
SAXNotSupportedException
-
assignEdgeSourceTarget
protected void assignEdgeSourceTarget(E e, Attributes atts, Map<String, String> edge_atts) throws SAXNotSupportedException- Throws:
SAXNotSupportedException
-
getVertexIDs
- Returns:
- a bidirectional map relating vertices and IDs.
-
getEdgeIDs
Returns a bidirectional map relating edges and IDs. This is not guaranteed to always be populated (edge IDs are not required in GraphML files.- Returns:
- a bidirectional map relating edges and IDs.
-
getGraphMetadata
- Returns:
- a map from graph type name to type metadata
-
getVertexMetadata
- Returns:
- a map from vertex type name to type metadata
-
getEdgeMetadata
- Returns:
- a map from edge type name to type metadata
-
getGraphDescriptions
- Returns:
- a map from graphs to graph descriptions
-
getVertexDescriptions
- Returns:
- a map from vertices to vertex descriptions
-
getEdgeDescriptions
- Returns:
- a map from edges to edge descriptions
-