V
- the graph vertex typeE
- the graph edge typepublic class GraphMLImporter<V,E> extends Object implements GraphImporter<V,E>
For a description of the format see http://en.wikipedia.org/wiki/ GraphML or the GraphML Primer.
Below is small example of a graph in GraphML format.
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key id="d0" for="node" attr.name="color" attr.type="string">
<default>yellow</default>
</key>
<key id="d1" for="edge" attr.name="weight" attr.type="double"/>
<graph id="G" edgedefault="undirected">
<node id="n0">
<data key="d0">green</data>
</node>
<node id="n1"/>
<node id="n2">
<data key="d0">blue</data>
</node>
<node id="n3">
<data key="d0">red</data>
</node>
<node id="n4"/>
<node id="n5">
<data key="d0">turquoise</data>
</node>
<edge id="e0" source="n0" target="n2">
<data key="d1">1.0</data>
</edge>
<edge id="e1" source="n0" target="n1">
<data key="d1">1.0</data>
</edge>
<edge id="e2" source="n1" target="n3">
<data key="d1">2.0</data>
</edge>
<edge id="e3" source="n3" target="n2"/>
<edge id="e4" source="n2" target="n4"/>
<edge id="e5" source="n3" target="n5"/>
<edge id="e6" source="n5" target="n4">
<data key="d1">1.1</data>
</edge>
</graph>
</graphml>
The importer reads the input into a graph which is provided by the user. In case the graph is an
instance of WeightedGraph
and the corresponding edge key with
attr.name="weight" is defined, the importer also reads edge weights. Otherwise edge weights are
ignored.
GraphML-Attributes Values are read as string key-value pairs and passed on to the
VertexProvider
and EdgeProvider
respectively.
The provided graph object, where the imported graph will be stored, must be able to support the features of the graph that is read. For example if the GraphML file contains self-loops then the graph provided must also support self-loops. The same for multiple edges. Moreover, the parser completely ignores the attribute "edgedefault" which denotes whether an edge is directed or not. Whether edges are directed or not depends on the underlying implementation of the user provided graph object.
The importer validates the input using the 1.0 GraphML Schema.
Constructor and Description |
---|
GraphMLImporter(VertexProvider<V> vertexProvider,
EdgeProvider<V,E> edgeProvider)
Constructs a new importer.
|
Modifier and Type | Method and Description |
---|---|
EdgeProvider<V,E> |
getEdgeProvider()
Get the edge provider
|
String |
getEdgeWeightAttributeName()
Get the attribute name for edge weights
|
VertexProvider<V> |
getVertexProvider()
Get the vertex provider
|
void |
importGraph(Graph<V,E> graph,
Reader input)
Import a graph.
|
void |
setEdgeProvider(EdgeProvider<V,E> edgeProvider)
Set the edge provider.
|
void |
setEdgeWeightAttributeName(String edgeWeightAttributeName)
Set the attribute name to use for edge weights.
|
void |
setVertexProvider(VertexProvider<V> vertexProvider)
Set the vertex provider
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
importGraph, importGraph
public GraphMLImporter(VertexProvider<V> vertexProvider, EdgeProvider<V,E> edgeProvider)
vertexProvider
- provider for the generation of vertices. Must not be null.edgeProvider
- provider for the generation of edges. Must not be null.public VertexProvider<V> getVertexProvider()
public void setVertexProvider(VertexProvider<V> vertexProvider)
vertexProvider
- the new vertex provider. Must not be null.public EdgeProvider<V,E> getEdgeProvider()
public void setEdgeProvider(EdgeProvider<V,E> edgeProvider)
edgeProvider
- the new edge provider. Must not be null.public String getEdgeWeightAttributeName()
public void setEdgeWeightAttributeName(String edgeWeightAttributeName)
edgeWeightAttributeName
- the attribute namepublic void importGraph(Graph<V,E> graph, Reader input) throws ImportException
The provided graph must be able to support the features of the graph that is read. For example if the GraphML file contains self-loops then the graph provided must also support self-loops. The same for multiple edges.
If the provided graph is a weighted graph, the importer also reads edge weights.
GraphML-Attributes Values are read as string key-value pairs and passed on to the
VertexProvider
and EdgeProvider
respectively.
importGraph
in interface GraphImporter<V,E>
graph
- the output graphinput
- the input readerImportException
- in case an error occurs, such as I/O or parse errorCopyright © 2016. All rights reserved.