public class GraphMLReader<G extends Hypergraph<V,E>,V,E> extends org.xml.sax.helpers.DefaultHandler
data
data
descriptions
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 com.google.common.base.Supplier<E> |
edge_factory |
protected com.google.common.collect.BiMap<E,String> |
edge_ids |
protected Map<String,GraphMLMetadata<E>> |
edge_metadata |
protected Map<G,String> |
graph_desc |
protected com.google.common.base.Supplier<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 com.google.common.collect.BiMap<String,GraphMLReader.TagState> |
tag_state |
protected Map<V,String> |
vertex_desc |
protected com.google.common.base.Supplier<V> |
vertex_factory |
protected com.google.common.collect.BiMap<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(com.google.common.base.Supplier<V> vertex_factory,
com.google.common.base.Supplier<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 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() |
com.google.common.collect.BiMap<E,String> |
getEdgeIDs()
Returns a bidirectional map relating edges and IDs.
|
Map<String,GraphMLMetadata<E>> |
getEdgeMetadata() |
Map<G,String> |
getGraphDescriptions() |
Map<String,GraphMLMetadata<G>> |
getGraphMetadata() |
Map<V,String> |
getVertexDescriptions() |
com.google.common.collect.BiMap<V,String> |
getVertexIDs() |
Map<String,GraphMLMetadata<V>> |
getVertexMetadata() |
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,
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.
|
List<G> |
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 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, warning
protected 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 com.google.common.collect.BiMap<String,GraphMLReader.TagState> tag_state
protected com.google.common.base.Supplier<G extends Hypergraph<V,E>> graph_factory
protected com.google.common.base.Supplier<V> vertex_factory
protected com.google.common.base.Supplier<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(com.google.common.base.Supplier<V> vertex_factory, com.google.common.base.Supplier<E> edge_factory) throws ParserConfigurationException, SAXException
GraphMLReader
instance with the specified
vertex and edge factories.vertex_factory
- the vertex supplier to use to create vertex objectsedge_factory
- the edge supplier to use to create edge objectsParserConfigurationException
- if a SAX parser cannot be constructedSAXException
- if the SAX parser factory cannot be constructedpublic 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
.ParserConfigurationException
- if a SAX parser cannot be constructedSAXException
- if the SAX parser factory cannot be constructedpublic List<G> loadMultiple(Reader reader, com.google.common.base.Supplier<G> graph_factory) throws IOException
reader
- the source of the graph data in GraphML formatgraph_factory
- used to build graph instancesIOException
- if an error is encountered while parsing the graphpublic List<G> loadMultiple(String filename, com.google.common.base.Supplier<G> graph_factory) throws IOException
filename
- the source of the graph data in GraphML formatgraph_factory
- used to build graph instancesIOException
- if an error is encountered while parsing the graphpublic void load(Reader reader, G g) throws IOException
reader
- the source of the graph data in GraphML formatg
- the graph instance to populateIOException
- if an error is encountered while parsing the graphpublic void load(String filename, G g) throws IOException
filename
- the source of the graph data in GraphML formatg
- the graph instance to populateIOException
- if an error is encountered while parsing the graphprotected void clearData()
protected void initializeData()
graphml
rather than graph
.protected void parse(Reader reader) throws IOException
IOException
public void startElement(String uri, String name, String qName, Attributes atts) throws SAXNotSupportedException
startElement
in interface ContentHandler
startElement
in class org.xml.sax.helpers.DefaultHandler
SAXNotSupportedException
public void characters(char[] ch, int start, int length) throws SAXNotSupportedException
characters
in interface ContentHandler
characters
in class org.xml.sax.helpers.DefaultHandler
SAXNotSupportedException
protected <T> void addDatum(Map<String,GraphMLMetadata<T>> metadata, T current_elt, String text) throws SAXNotSupportedException
SAXNotSupportedException
public void endElement(String uri, String name, String qName) throws SAXNotSupportedException
endElement
in interface ContentHandler
endElement
in class org.xml.sax.helpers.DefaultHandler
SAXNotSupportedException
protected Map<String,String> getAttributeMap(Attributes atts)
protected void handleData(Attributes atts) throws SAXNotSupportedException
SAXNotSupportedException
protected void createKey(Attributes atts) throws SAXNotSupportedException
SAXNotSupportedException
protected void createVertex(Attributes atts) throws SAXNotSupportedException
SAXNotSupportedException
protected void createEdge(Attributes atts, GraphMLReader.TagState state) throws SAXNotSupportedException
SAXNotSupportedException
protected void assignEdgeSourceTarget(E e, Attributes atts, Map<String,String> edge_atts) throws SAXNotSupportedException
SAXNotSupportedException
public com.google.common.collect.BiMap<V,String> getVertexIDs()
public com.google.common.collect.BiMap<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.