mulgara - semantic store

skip navigation


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:     _blankNode123
_blankNode123                 "1501 Grant Avenue"
_blankNode123                   "Bedford"
_blankNode123                  "Massachusetts"
_blankNode123             "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      "1501 Grant Avenue"
_blankNode123        "Bedford"
_blankNode123       "Massachusetts"
_blankNode123  "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  "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:     _blankNode123

Valid XHTML 1.0 TransitionalValid CSS 3.0!