public class GraphMLReader<G extends Hypergraph<V,E>,V,E> extends org.xml.sax.helpers.DefaultHandler
data
graph, vertex, edge descriptions and data descriptions
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.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
GraphMLReader.KeyType |
protected static class |
GraphMLReader.TagState |
| Modifier and Type | Field and Description |
|---|---|
protected E |
current_edge |
protected G |
current_graph |
protected String |
current_key |
protected LinkedList<GraphMLReader.TagState> |
current_states |
protected StringBuilder |
current_text |
protected V |
current_vertex |
protected EdgeType |
default_edgetype |
protected Map<E,String> |
edge_desc |
protected org.apache.commons.collections4.Factory<E> |
edge_factory |
protected org.apache.commons.collections4.BidiMap<E,String> |
edge_ids |
protected Map<String,GraphMLMetadata<E>> |
edge_metadata |
protected Map<G,String> |
graph_desc |
protected org.apache.commons.collections4.Factory<G> |
graph_factory |
protected Map<String,GraphMLMetadata<G>> |
graph_metadata |
protected List<G> |
graphs |
protected Collection<V> |
hyperedge_vertices |
protected GraphMLReader.KeyType |
key_type |
protected SAXParser |
saxp |
protected org.apache.commons.collections4.BidiMap<String,GraphMLReader.TagState> |
tag_state |
protected Map<V,String> |
vertex_desc |
protected org.apache.commons.collections4.Factory<V> |
vertex_factory |
protected org.apache.commons.collections4.BidiMap<V,String> |
vertex_ids |
protected Map<String,GraphMLMetadata<V>> |
vertex_metadata |
| Constructor and Description |
|---|
GraphMLReader()
Creates a
GraphMLReader instance that assigns the vertex
and edge id strings to be the vertex and edge objects,
as well as their IDs. |
GraphMLReader(org.apache.commons.collections4.Factory<V> vertex_factory,
org.apache.commons.collections4.Factory<E> edge_factory)
Creates a
GraphMLReader instance with the specified
vertex and edge factories. |
| Modifier and Type | Method and Description |
|---|---|
protected <T> void |
addDatum(Map<String,GraphMLMetadata<T>> metadata,
T current_elt,
String text) |
protected <T> void |
addExtraData(Map<String,String> atts,
Map<String,GraphMLMetadata<T>> metadata_map,
T current_elt) |
protected void |
assignEdgeSourceTarget(E e,
Attributes atts,
Map<String,String> edge_atts) |
void |
characters(char[] ch,
int start,
int length) |
protected void |
clearData() |
protected void |
createEdge(Attributes atts,
GraphMLReader.TagState state) |
protected void |
createKey(Attributes atts) |
protected void |
createVertex(Attributes atts) |
void |
endElement(String uri,
String name,
String qName) |
protected Map<String,String> |
getAttributeMap(Attributes atts) |
Map<E,String> |
getEdgeDescriptions()
Returns a map from edges to edge descriptions.
|
org.apache.commons.collections4.BidiMap<E,String> |
getEdgeIDs()
Returns a bidirectional map relating edges and IDs.
|
Map<String,GraphMLMetadata<E>> |
getEdgeMetadata()
Returns a map from edge type name to type metadata.
|
Map<G,String> |
getGraphDescriptions()
Returns a map from graphs to graph descriptions.
|
Map<String,GraphMLMetadata<G>> |
getGraphMetadata()
Returns a map from graph type name to type metadata.
|
Map<V,String> |
getVertexDescriptions()
Returns a map from vertices to vertex descriptions.
|
org.apache.commons.collections4.BidiMap<V,String> |
getVertexIDs()
Returns a bidirectional map relating vertices and IDs.
|
Map<String,GraphMLMetadata<V>> |
getVertexMetadata()
Returns a map from vertex type name to type metadata.
|
protected void |
handleData(Attributes atts) |
protected void |
initializeData()
This is separate from initialize() because these data structures are shared among all
graphs loaded (i.e., they're defined inside
graphml rather than graph. |
void |
load(Reader reader,
G g)
Populates the specified graph with the data parsed from the reader.
|
void |
load(String filename,
G g)
Populates the specified graph with the data parsed from the specified file.
|
List<G> |
loadMultiple(Reader reader,
org.apache.commons.collections4.Factory<G> graph_factory)
Returns a list of the graphs parsed from the specified reader, as created by
the specified factory.
|
List<G> |
loadMultiple(String filename,
org.apache.commons.collections4.Factory<G> graph_factory)
Returns a list of the graphs parsed from the specified file, as created by
the specified factory.
|
protected void |
parse(Reader reader) |
void |
startElement(String uri,
String name,
String qName,
Attributes atts) |
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warningprotected SAXParser saxp
protected EdgeType default_edgetype
protected G extends Hypergraph<V,E> current_graph
protected V current_vertex
protected E current_edge
protected String current_key
protected LinkedList<GraphMLReader.TagState> current_states
protected org.apache.commons.collections4.BidiMap<String,GraphMLReader.TagState> tag_state
protected org.apache.commons.collections4.Factory<G extends Hypergraph<V,E>> graph_factory
protected org.apache.commons.collections4.Factory<V> vertex_factory
protected org.apache.commons.collections4.Factory<E> edge_factory
protected Map<String,GraphMLMetadata<G extends Hypergraph<V,E>>> graph_metadata
protected Map<String,GraphMLMetadata<V>> vertex_metadata
protected Map<String,GraphMLMetadata<E>> edge_metadata
protected GraphMLReader.KeyType key_type
protected Collection<V> hyperedge_vertices
protected List<G extends Hypergraph<V,E>> graphs
protected StringBuilder current_text
public GraphMLReader(org.apache.commons.collections4.Factory<V> vertex_factory, org.apache.commons.collections4.Factory<E> edge_factory) throws ParserConfigurationException, SAXException
GraphMLReader instance with the specified
vertex and edge factories.vertex_factory - the vertex factory to use to create vertex objectsedge_factory - the edge factory to use to create edge objectsParserConfigurationExceptionSAXExceptionpublic GraphMLReader()
throws ParserConfigurationException,
SAXException
GraphMLReader instance that assigns the vertex
and edge id strings 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 with String.public List<G> loadMultiple(Reader reader, org.apache.commons.collections4.Factory<G> graph_factory) throws IOException
IOExceptionpublic List<G> loadMultiple(String filename, org.apache.commons.collections4.Factory<G> graph_factory) throws IOException
IOExceptionpublic void load(Reader reader, G g) throws IOException
IOExceptionpublic void load(String filename, G g) throws IOException
IOExceptionprotected void clearData()
protected void initializeData()
graphml rather than graph.protected void parse(Reader reader) throws IOException
IOExceptionpublic void startElement(String uri, String name, String qName, Attributes atts) throws SAXNotSupportedException
startElement in interface ContentHandlerstartElement in class org.xml.sax.helpers.DefaultHandlerSAXNotSupportedExceptionprotected <T> void addExtraData(Map<String,String> atts, Map<String,GraphMLMetadata<T>> metadata_map, T current_elt)
T - atts - metadata_map - current_elt - public void characters(char[] ch,
int start,
int length)
throws SAXNotSupportedException
characters in interface ContentHandlercharacters in class org.xml.sax.helpers.DefaultHandlerSAXNotSupportedExceptionprotected <T> void addDatum(Map<String,GraphMLMetadata<T>> metadata, T current_elt, String text) throws SAXNotSupportedException
SAXNotSupportedExceptionpublic void endElement(String uri, String name, String qName) throws SAXNotSupportedException
endElement in interface ContentHandlerendElement in class org.xml.sax.helpers.DefaultHandlerSAXNotSupportedExceptionprotected Map<String,String> getAttributeMap(Attributes atts)
protected void handleData(Attributes atts) throws SAXNotSupportedException
SAXNotSupportedExceptionprotected void createKey(Attributes atts) throws SAXNotSupportedException
SAXNotSupportedExceptionprotected void createVertex(Attributes atts) throws SAXNotSupportedException
SAXNotSupportedExceptionprotected void createEdge(Attributes atts, GraphMLReader.TagState state) throws SAXNotSupportedException
SAXNotSupportedExceptionprotected void assignEdgeSourceTarget(E e, Attributes atts, Map<String,String> edge_atts) throws SAXNotSupportedException
SAXNotSupportedExceptionpublic org.apache.commons.collections4.BidiMap<V,String> getVertexIDs()
public org.apache.commons.collections4.BidiMap<E,String> getEdgeIDs()
public Map<String,GraphMLMetadata<G>> getGraphMetadata()
public Map<String,GraphMLMetadata<V>> getVertexMetadata()
public Map<String,GraphMLMetadata<E>> getEdgeMetadata()
public Map<G,String> getGraphDescriptions()
public Map<V,String> getVertexDescriptions()
Copyright © 2015. All rights reserved.