-
Notifications
You must be signed in to change notification settings - Fork 17
Introduction to the XDI graph model
In XDI2, the XDI graph is modeled by a small set of Java interfaces in the xdi2-core component, which are implemented by a number of different backend storage mechanisms.
- xdi2.core.GraphFactory: XDI graph factory
- xdi2.core.Graph: XDI graph interface
- xdi2.core.ContextNode: XDI context node interface
- xdi2.core.Relation: XDI relation interface
- xdi2.core.Literal: XDI literal interface
- xdi2.core.Statement: XDI statement interface
For an example, see:
To create a Graph, an instance of the GraphFactory interface is needed. The simplest GraphFactory is the MemoryGraphFactory, which provides in-memory storage. Example:
Graph graph = MemoryGraphFactory.getInstance().openGraph();
Some implementations of GraphFactory support parameters, e.g. the BDBKeyValueGraphFactory supports specifying the path to a BDB database that should be used for storage. Example:
BDBKeyValueGraphFactory graphFactory = new BDBKeyValueGraphFactory();
graphFactory.setDatabasePath("/path/to/my/database/");
Graph graph = graphFactory.openGraph();
Once a Graph has been opened, the API provides a wide range of methods to work on the ContextNode, Relation, and Literal interfaces. Example:
ContextNode root = graph.getRootContextNode();
ContextNode markus = root.setContextNode(XDIArc.create("=markus"));
ContextNode animesh = root.setContextNode(XDIArc.create("=animesh"));
ContextNode name = markus.setContextNode(XDIArc.create("<#name>"));
ContextNode value = name.setContextNode(XDIArc.create("&"));
Relation relation = markus.setRelation(XDIAddress.create("#friend"), animesh);
Literal literal = value.setLiteral("Markus Sabadello");
An XDI graph can also be thought of as consisting of a set of statements, which can be accessed using the Statement interface. Example:
System.out.println("Statement associated with a context node: " + markus.getStatement());
System.out.println("Statement associated with a relation: " + relation.getStatement());
System.out.println("Statement associated with a literal: " + literal.getStatement());
System.out.println();
graph.setStatement(XDIStatement.create("=alice/#friend/=bob"));
At the end, a Graph should be closed. Example:
graph.close();
Source: XDI2-CLASSES.odg
- XdiGraphModel on the OASIS XDI TC wiki
This work is licensed under a Creative Commons Attribution 4.0 International License.