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
public class GraphMLReader<G extends Hypergraph<V,E>,V,E>
- extends DefaultHandler
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 data
descriptions
vertex and edge IDs
Each of these is exposed via appropriate 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:
- "http://graphml.graphdrawing.org/specification.html"
Constructor Summary |
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( vertex_factory,
edge_factory)
Creates a GraphMLReader instance with the specified
vertex and edge factories. |
Method Summary |
protected
|
addDatum(Map<String,GraphMLMetadata<T>> metadata,
T current_elt,
String text)
|
protected
|
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()
|
|
getEdgeIDs()
|
Map<String,GraphMLMetadata<E>> |
getEdgeMetadata()
|
Map<G,String> |
getGraphDescriptions()
|
Map<String,GraphMLMetadata<G>> |
getGraphMetadata()
|
Map<V,String> |
getVertexDescriptions()
|
|
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)
|
void |
load(String filename,
G g)
|
List<G> |
loadMultiple(Reader reader,
graph_factory)
|
List<G> |
loadMultiple(String filename,
graph_factory)
|
protected void |
parse(Reader reader)
|
void |
startElement(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, warning |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
saxp
protected SAXParser saxp
default_edgetype
protected EdgeType default_edgetype
current_graph
protected G extends Hypergraph<V,E> current_graph
current_vertex
protected V current_vertex
current_edge
protected E current_edge
current_key
protected String current_key
current_states
protected LinkedList<GraphMLReader.TagState> current_states
tag_state
protected tag_state
graph_factory
protected graph_factory
vertex_factory
protected vertex_factory
edge_factory
protected edge_factory
vertex_ids
protected vertex_ids
edge_ids
protected edge_ids
graph_metadata
protected Map<String,GraphMLMetadata<G extends Hypergraph<V,E>>> graph_metadata
vertex_metadata
protected Map<String,GraphMLMetadata<V>> vertex_metadata
edge_metadata
protected Map<String,GraphMLMetadata<E>> edge_metadata
vertex_desc
protected Map<V,String> vertex_desc
edge_desc
protected Map<E,String> edge_desc
graph_desc
protected Map<G extends Hypergraph<V,E>,String> graph_desc
key_type
protected GraphMLReader.KeyType key_type
hyperedge_vertices
protected Collection<V> hyperedge_vertices
graphs
protected List<G extends Hypergraph<V,E>> graphs
GraphMLReader
public GraphMLReader( vertex_factory,
edge_factory)
throws ParserConfigurationException,
SAXException
- Creates a
GraphMLReader
instance with the specified
vertex and edge factories.
- Parameters:
vertex_factory
- the vertex factory to use to create vertex objectsedge_factory
- the edge factory to use to create edge objects
- Throws:
ParserConfigurationException
SAXException
GraphMLReader
public GraphMLReader()
throws ParserConfigurationException,
SAXException
- Creates a
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
.
- Throws:
ParserConfigurationException
SAXException
loadMultiple
public List<G> loadMultiple(Reader reader,
graph_factory)
throws IOException
- Throws:
IOException
loadMultiple
public List<G> loadMultiple(String filename,
graph_factory)
throws IOException
- Throws:
IOException
load
public void load(Reader reader,
G g)
throws IOException
- Throws:
IOException
- See Also:
load(Reader, Hypergraph)
load
public void load(String filename,
G g)
throws IOException
- Throws:
IOException
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 inside
graphml
rather than graph
.
parse
protected void parse(Reader reader)
throws IOException
- Throws:
IOException
startElement
public void startElement(String uri,
String name,
String qName,
Attributes atts)
throws SAXNotSupportedException
- Specified by:
startElement
in interface ContentHandler
- Overrides:
startElement
in class DefaultHandler
- Throws:
SAXNotSupportedException
addExtraData
protected <T> void addExtraData(Map<String,String> atts,
Map<String,GraphMLMetadata<T>> metadata_map,
T current_elt)
- Parameters:
entry
-
characters
public void characters(char[] ch,
int start,
int length)
throws SAXNotSupportedException
- Specified by:
characters
in interface ContentHandler
- Overrides:
characters
in class DefaultHandler
- Throws:
SAXNotSupportedException
addDatum
protected <T> void addDatum(Map<String,GraphMLMetadata<T>> metadata,
T current_elt,
String text)
throws SAXNotSupportedException
- Throws:
SAXNotSupportedException
endElement
public void endElement(String uri,
String name,
String qName)
throws SAXNotSupportedException
- Specified by:
endElement
in interface ContentHandler
- Overrides:
endElement
in class DefaultHandler
- Throws:
SAXNotSupportedException
getAttributeMap
protected Map<String,String> getAttributeMap(Attributes atts)
handleData
protected void handleData(Attributes atts)
throws SAXNotSupportedException
- Throws:
SAXNotSupportedException
createKey
protected void createKey(Attributes atts)
throws SAXNotSupportedException
- Throws:
SAXNotSupportedException
createVertex
protected void createVertex(Attributes atts)
throws SAXNotSupportedException
- 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
public getVertexIDs()
getEdgeIDs
public getEdgeIDs()
getGraphMetadata
public Map<String,GraphMLMetadata<G>> getGraphMetadata()
getVertexMetadata
public Map<String,GraphMLMetadata<V>> getVertexMetadata()
getEdgeMetadata
public Map<String,GraphMLMetadata<E>> getEdgeMetadata()
getGraphDescriptions
public Map<G,String> getGraphDescriptions()
getVertexDescriptions
public Map<V,String> getVertexDescriptions()
getEdgeDescriptions
public Map<E,String> getEdgeDescriptions()
Copyright © 2008 null. All Rights Reserved.