org.jrdf.graph.global.molecule
Interface Molecule

All Known Implementing Classes:
MoleculeImpl, NullMolecule

public interface Molecule

A molecule is a container of a subgraph of RDF triples. It contains a collection of triples that share some common chain of blank nodes. Molecules consist of a set of root triples. These share a blank node - typically the subject but it can be the object as well. For example, _1 p o, s p2 _1 is a simple molecule. The highest in this set of root triples (as defined by some ordering) is the head triple. The typical ordering is most grounded (fewest blank nodes), followed by URIs, Literals and then alphabetical ordering. The chain of blank nodes creates a molecule that contains submolecules. If a triple in the root has a blank node as its object it is a linking triple. This is how the chains to submolecules are created. From one molecule to the next the object and subject nodes are swapped. For example, the linking triple _1 p _2 will link to a triple in a submolecule _2 p o.

Version:
$Id: Molecule.java 2894 2009-01-27 21:25:13Z newmana $
Author:
Andrew Newman

Method Summary
 Molecule add(MergeSubmolecules merger, Molecule subMolecule)
          Adds a molecule based on head triple matching.
 Molecule add(Triple triple)
          Add a triple to the root set of triples.
 Molecule add(Triple linkingTriple, Molecule subMolecule)
          Add a submolecule to a molecule using the given root triple.
 Molecule add(Triple linkingTriple, Triple subMoleculeTriple)
          Add a triple to a submolecule which has the given linking triple.
 boolean contains(Triple triple)
          Checks for existence of a triple in the root triples.
 Iterator<Triple> find(SubjectNode subject, PredicateNode predicateNode, ObjectNode object)
           
 Iterator<Triple> find(Triple triple)
           
 Triple getHeadTriple()
          Returns the highest triple (as defined by some ordering).
 Iterator<Triple> getRootTriples()
          Returns an iterator of all the triples in the root set.
 Set<Triple> getRootTriplesAsSet()
          Creates an (usually) in memory version of the root set of triples.
 SortedSet<Molecule> getSubMolecules(Triple rootTriple)
          Returns a set of submolecules for a given root triple.
 boolean isTopLevelMolecule()
          Returns true if this molecule has no parent molecule (it's not a submolecule).
 Iterator<Triple> iterator()
           
 void remove(Triple triple)
          Remove a triple from the root set of triples.
 boolean removeMolecule(Triple triple, Molecule subMolecule)
          Removes the submolecule from the triple.
 int size()
          Returns the number of triples in the molecule.
 void specialAdd(Molecule molecule)
          Copies the top level (from the root triples) of the given molecule into this molecule.
 

Method Detail

add

Molecule add(Triple triple)
Add a triple to the root set of triples. The molecule may not be returned in future versions (and current implementations just mutate as well as return a copy).

Parameters:
triple - the triple to add.
Returns:
a new molecule with the added triple.

add

Molecule add(Triple linkingTriple,
             Molecule subMolecule)
Add a submolecule to a molecule using the given root triple. The molecule may not be returned in future versions (and current implementations just mutate as well as return a copy).

Parameters:
linkingTriple - the root triple to hang the submolecule off of.
subMolecule - the submolecule to add.
Returns:
a new molecule with the submolecule added.

add

Molecule add(Triple linkingTriple,
             Triple subMoleculeTriple)
Add a triple to a submolecule which has the given linking triple. The molecule may not be returned in future versions (and current implementations just mutate as well as return a copy).

Parameters:
linkingTriple - the linking triple.
subMoleculeTriple - the triple of the submolecule.
Returns:
a new molecule with the submolecule added.

contains

boolean contains(Triple triple)
Checks for existence of a triple in the root triples.

Parameters:
triple - the triple to check for existance.
Returns:
if the triple exists in the root triple.

getHeadTriple

Triple getHeadTriple()
Returns the highest triple (as defined by some ordering). Typically, this is the most grounded (least number of blank nodes) and alphabetically highest triple in the root triples.

Returns:
the highest, by order, triple.

getRootTriples

Iterator<Triple> getRootTriples()
Returns an iterator of all the triples in the root set.

Returns:
an iterator of all the triples in the root set.

getRootTriplesAsSet

Set<Triple> getRootTriplesAsSet()
Creates an (usually) in memory version of the root set of triples.

Returns:
the root set of triples.

getSubMolecules

SortedSet<Molecule> getSubMolecules(Triple rootTriple)
Returns a set of submolecules for a given root triple.

Parameters:
rootTriple - the root triple to use to get the submolecules.
Returns:
a set of submolecules for a given root triple.

remove

void remove(Triple triple)
Remove a triple from the root set of triples.

Parameters:
triple - the triple to remove.

size

int size()
Returns the number of triples in the molecule.

Returns:
the number of triples in the molecule.

isTopLevelMolecule

boolean isTopLevelMolecule()
Returns true if this molecule has no parent molecule (it's not a submolecule).

Returns:
if this molecule has no parent molecule (it's not a submolecule).

add

Molecule add(MergeSubmolecules merger,
             Molecule subMolecule)
Adds a molecule based on head triple matching. If the head triples of this molecule and the one to be added matches it takes the submolecules and adds it to the current head triple's submolecule. Otherwise, if the head triples don't match, it just adds the submolecule to the head triple's submolecule with no merging. This maybe removed in the future.

Parameters:
merger - the code which merges the two submolecules together.
subMolecule - the submolecule to add.
Returns:
a new molecule with the submolecule added.

specialAdd

void specialAdd(Molecule molecule)
Copies the top level (from the root triples) of the given molecule into this molecule. This maybe removed in the future.

Parameters:
molecule - the molecule to add to this one.

removeMolecule

boolean removeMolecule(Triple triple,
                       Molecule subMolecule)
Removes the submolecule from the triple. The set of submolecules must contain be equal to the given molecule. This maybe removed in the future.

Parameters:
triple - The triple which contains the submolecules.
subMolecule - The submolecule to remove.
Returns:
if the submolecule was removed.

iterator

Iterator<Triple> iterator()

find

Iterator<Triple> find(Triple triple)

find

Iterator<Triple> find(SubjectNode subject,
                      PredicateNode predicateNode,
                      ObjectNode object)