Previous Topic

Next Topic

Creating Nodes and Triples

Nodes and tiples are created using a GraphElementFactory that is obtained from a JRDF graph using the graph's getElementFactory() method. The following code creates example nodes and triples:

//get the Factory
GraphElementFactory elementFactory = graph.getElementFactory();

//create resources
URIReference person = elementFactory.createResource(new URI("http://example.org/staffid#85740"));
BlankNode address = elementFactory.createResource();

//create properties
URIReference hasAddress = elementFactory.createResource(new URI("http://example.org/terms#address"));
URIReference hasStreet = elementFactory.createResource(new URI("http://example.org/terms#street"));
URIReference hasCity = elementFactory.createResource(new URI("http://example.org/terms#city"));
URIReference hasState = elementFactory.createResource(new URI("http://example.org/terms#state"));
URIReference hasPostCode = elementFactory.createResource
(new URI("http://example.org/terms#postalCode"));

//create values
Literal street = elementFactory.createLiteral("1501 Grant Avenue");
Literal city = elementFactory.createLiteral("Bedford");
Literal state = elementFactory.createLiteral("Massachusetts");
Literal postCode = elementFactory.createLiteral("01730");

//create statements
Triple addressStatement = elementFactory.createTriple(person, hasAddress, address);
Triple streetStatement = elementFactory.createTriple(address, hasStreet, street);
Triple cityStatement = elementFactory.createTriple(address, hasCity, city);
Triple stateStatement = elementFactory.createTriple(address, hasState, state);
Triple postCodeStatement = elementFactory.createTriple(address, hasPostCode, postCode);

See Also

JRDF Tutorial

Prerequisites

Obtaining a Session from a Mulgara Server

Comparison of JRDF Graph Implementations

Creating the Graph

Adding Triples to the Graph

Searching the Graph

Reify Triples

Removing Triples from the Graph

Open Source logo

© 2001-2004 Tucana Technologies, Inc. Some rights reserved.

© 2006 The Mulgara Project. Some rights reserved.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".