- java.lang.Object
-
- org.jgrapht.nio.BaseEventDrivenImporter<java.lang.String,Triple<java.lang.String,java.lang.String,java.lang.Double>>
-
- org.jgrapht.nio.graphml.SimpleGraphMLEventDrivenImporter
-
- All Implemented Interfaces:
EventDrivenImporter<java.lang.String,Triple<java.lang.String,java.lang.String,java.lang.Double>>
public class SimpleGraphMLEventDrivenImporter extends BaseEventDrivenImporter<java.lang.String,Triple<java.lang.String,java.lang.String,java.lang.Double>> implements EventDrivenImporter<java.lang.String,Triple<java.lang.String,java.lang.String,java.lang.Double>>
Imports a graph from a GraphML data source. The importer does not construct a graph but calls the provided consumers with the appropriate arguments. Vertices are returned simply by their vertex id and edges are returns as triples (source, target, weight) where weight maybe null.The importer notifies lazily and completely out-of-order for any additional vertex, edge or graph attributes in the input file. Users can register consumers for vertex, edge and graph attributes after construction of the importer. Finally, default attribute values are completely ignored. Lazily here means that an edge is first reported with a null weight and its weight is reported later using the edge attribute consumer. Since the same triple instance is used in all cases, an edge may appear having a null weight when it is first reported and having a non-null weight after the edge weight is reported.
This is a simple implementation with supports only a limited set of features of the GraphML specification. For a more rigorous parser use
GraphMLImporter
. This version is oriented towards parsing speed.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" /> <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"> <data key="d0">black</data> </node> <node id="n2"> <data key="d0">blue</data> </node> <node id="n3"> <data key="d0">red</data> </node> <node id="n4"> <data key="d0">white</data> </node> <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 by default validates the input using the 1.0 GraphML Schema. The user can (not recommended) disable the validation by calling
setSchemaValidation(boolean)
.- Author:
- Dimitrios Michail
-
-
Constructor Summary
Constructors Constructor Description SimpleGraphMLEventDrivenImporter()
Constructs a new importer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getEdgeWeightAttributeName()
Get the attribute name for edge weightsvoid
importInput(java.io.Reader input)
Import a graphboolean
isSchemaValidation()
Whether the importer validates the inputvoid
setEdgeWeightAttributeName(java.lang.String edgeWeightAttributeName)
Set the attribute name to use for edge weights.void
setSchemaValidation(boolean schemaValidation)
Set whether the importer should validate the input-
Methods inherited from class org.jgrapht.nio.BaseEventDrivenImporter
addEdgeAttributeConsumer, addEdgeConsumer, addEdgeCountConsumer, addGraphAttributeConsumer, addImportEventConsumer, addVertexAttributeConsumer, addVertexConsumer, addVertexCountConsumer, notifyEdge, notifyEdgeAttribute, notifyEdgeCount, notifyGraphAttribute, notifyImportEvent, notifyVertex, notifyVertexAttribute, notifyVertexCount, removeEdgeAttributeConsumer, removeEdgeConsumer, removeEdgeCountConsumer, removeGraphAttributeConsumer, removeImportEventConsumer, removeVertexAttributeConsumer, removeVertexConsumer, removeVertexCountConsumer
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jgrapht.nio.EventDrivenImporter
addEdgeAttributeConsumer, addEdgeConsumer, addEdgeCountConsumer, addGraphAttributeConsumer, addImportEventConsumer, addVertexAttributeConsumer, addVertexConsumer, addVertexCountConsumer, importInput, importInput, removeEdgeAttributeConsumer, removeEdgeConsumer, removeEdgeCountConsumer, removeGraphAttributeConsumer, removeImportEventConsumer, removeVertexAttributeConsumer, removeVertexConsumer, removeVertexCountConsumer
-
-
-
-
Method Detail
-
getEdgeWeightAttributeName
public java.lang.String getEdgeWeightAttributeName()
Get the attribute name for edge weights- Returns:
- the attribute name
-
setEdgeWeightAttributeName
public void setEdgeWeightAttributeName(java.lang.String edgeWeightAttributeName)
Set the attribute name to use for edge weights.- Parameters:
edgeWeightAttributeName
- the attribute name
-
isSchemaValidation
public boolean isSchemaValidation()
Whether the importer validates the input- Returns:
- true if the importer validates the input
-
setSchemaValidation
public void setSchemaValidation(boolean schemaValidation)
Set whether the importer should validate the input- Parameters:
schemaValidation
- value for schema validation
-
importInput
public void importInput(java.io.Reader input)
Description copied from interface:EventDrivenImporter
Import a graph- Specified by:
importInput
in interfaceEventDrivenImporter<java.lang.String,Triple<java.lang.String,java.lang.String,java.lang.Double>>
- Parameters:
input
- the input reader
-
-