Skip to content

GML Reader and Writer Library

spmallette edited this page Mar 10, 2012 · 6 revisions
<dependency>
   <groupId>com.tinkerpop.blueprints</groupId>
   <artifactId>blueprints-core</artifactId>
   <version>??</version>
</dependency>

The GML reader and writer package allows an entire graph to be streamed to and from GML (Graph Modelling Language).

The following example shows the format of the graph diagram above in GML:

graph [
	node [
		id 1
		blueprintsId "3"
		name "lop"
		lang "java"
	]
	node [
		id 2
		blueprintsId "2"
		name "vadas"
		age 27
	]
	node [
		id 3
		blueprintsId "1"
		name "marko"
		age 29
	]
	node [
		id 4
		blueprintsId "6"
		name "peter"
		age 35
	]
	node [
		id 5
		blueprintsId "5"
		name "ripple"
		lang "java"
	]
	node [
		id 6
		blueprintsId "4"
		name "josh"
		age 32
	]
	edge [
		source 6
		target 5
		label "created"
		blueprintsId "10"
		weight 1.0
	]
	edge [
		source 3
		target 2
		label "knows"
		blueprintsId "7"
		weight 0.5
	]
	edge [
		source 3
		target 1
		label "created"
		blueprintsId "9"
		weight 0.4
	]
	edge [
		source 3
		target 6
		label "knows"
		blueprintsId "8"
		weight 1.0
	]
	edge [
		source 6
		target 1
		label "created"
		blueprintsId "11"
		weight 0.4
	]
	edge [
		source 4
		target 1
		label "created"
		blueprintsId "12"
		weight 0.2
	]
]

Usage

To output a graph in GML format, pass the graph into the GMLWriter constructor, then call outputGraph:

Graph graph = ...
OutputStream out = ...

GMLWriter writer = new GMLWriter(graph);
writer.outputGraph(out);

The GMLReader works in a similar format. Simply pass what would likely be an empty graph into the constructor, then call inputGraph:

Graph graph = ...
InputStream in = ...

GMLReader reader = new GMLReader(graph);
reader.inputGraph(in);

There are a number of static method overloads that offer more options and control.