Previous Topic

Next Topic

Searching the Graph

You can search a graph using it's find(Triple triple) method. The nodes in the triple are used to match the nodes in the graph. Any null nodes in the triple are treated as wildcards and match to any node in the graph.

Triples are returned in the form of a ClosableIterator, which extends Iterator and has a close() method that is used to free resources. Calling next() on a ClosableIterator returns a triple object. Triples are not guaranteed to be returned in any specific order.

The following code examples demonstrate using the find(Triple triple) method to search a graph.

To search for all triples:

//get all Triples 
Triple findAll = elementFactory.createTriple(null, null, null); 
ClosableIterator allTriples = graph.find(findAll);

This returns:

http://example.org/staffid#85740  http://example.org/terms#address     _blankNode123
_blankNode123                     http://example.org/terms#street      "1501 Grant Avenue"
_blankNode123                     http://example.org/terms#city        "Bedford"
_blankNode123                     http://example.org/terms#state       "Massachusetts"
_blankNode123                     http://example.org/terms#postalCode  "01730"

To search for all addresses:

//search for address (as a subject)
Triple findAddress = elementFactory.createTriple(address, null, null);
ClosableIterator addressSubject = graph.find(findAddress);

This returns:

_blankNode123  http://example.org/terms#street      "1501 Grant Avenue"
_blankNode123  http://example.org/terms#city        "Bedford"
_blankNode123  http://example.org/terms#state       "Massachusetts"
_blankNode123  http://example.org/terms#postalCode  "01730"

To search for a city:

//search for the city: "Bedford"
Triple findCity = elementFactory.createTriple(null, null, city);
ClosableIterator bedfordCity = graph.find(findCity);

This returns:

_blankNode123  http://example.org/terms#city  "Bedford"

To search for subjects with an address property:

//search for any subject that has an address
Triple findAddresses = elementFactory.createTriple(null, hasAddress, null);
ClosableIterator addresses = graph.find(findAddresses);

This returns:

http://example.org/staffid#85740  http://example.org/terms#address     _blankNode123

See Also

JRDF Tutorial

Prerequisites

Obtaining a Session from a Kowari Server

Comparison of JRDF Graph Implementations

Creating the Graph

Creating Nodes and Triples

Adding Triples to the Graph

Reify Triples

Removing Triples from the Graph

Latest News

Kowari 1.1.0 Pre-release 1 Released

Kowari 1.0.5 Released

Kowari 1.0.4.1 Released

Kowari 1.0.4 Released

DAWG Evaluates iTQL

Kowari article in XML.com

Kowari mentioned on XML.com

Kowari 1.0.3 Released

Kowari Lite Introduced

Kowari 1.0.2 Released

Kowari 1.0.1 Released

View all news items


Open Source logo Tucana Technologies Logo SourceForge.net Logo

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