com.hp.hpl.jena.reasoner.transitiveReasoner
Class TransitiveGraphCache

java.lang.Object
  extended bycom.hp.hpl.jena.reasoner.transitiveReasoner.TransitiveGraphCache
All Implemented Interfaces:
Finder

public class TransitiveGraphCache
extends java.lang.Object
implements Finder

Datastructure used to represent a closed transitive reflexive relation. This should be more efficient than dynamically computing the relation from a triple store. Designed to be space efficient and not too time inefficient - though more work could be done to pick a real closure algorithm. The cost of space efficiency is that we have to reconstruct the triple set from the core graph which turns over a lot of storage.

The current implementation stores the direct relations as real graph (objects linked together by pointers). As relations are added redundant ones which could be reconstructed from the closure are dropped. To access the direct "minimal" version of the relation we just have to read out these links. To access the transitively closed version we have to walk the graph, however the results of these walks can be optionally cached (switch on using setCaching method). An alternative implementation would represent the closure using adjacency matrices and construct the complete closure in one go using the standard algorithm. This would be more efficient but require more space unless we have a good sparse binary matrix package.

Version:
$Revision: 1.11 $ on $Date: 2003/06/23 13:54:29 $
Author:
Dave Reynolds

Constructor Summary
TransitiveGraphCache(Node directPredicate, Node closedPredicate)
          Constructor - create a new cache to hold the given relation information.
 
Method Summary
 void addRelation(Node start, Node end)
          Register a new relation instance in the cache
 boolean cacheAll(Finder graph, Node predicate)
          Cache all instances of the given predicate which are present in the given Graph.
 void clear()
          Clear the entire cache contents.
 boolean contains(TriplePattern pattern)
          Return true if the given pattern occurs somewhere in the find sequence.
 TransitiveGraphCache deepCopy()
          Create a deep copy of the cache contents.
 ExtendedIterator find(TriplePattern pattern)
          Basic pattern lookup interface.
 ExtendedIterator findWithContinuation(TriplePattern pattern, Finder continuation)
          Extended find interface used in situations where the implementator may or may not be able to answer the complete query.
 Node getClosedPredicate()
          Returns the closedPredicate.
 Node getDirectPredicate()
          Returns the directPredicate.
 boolean isProperty(Node node)
          Return true if the given Node is registered as a property
 ExtendedIterator listAllProperties()
          Return an iterator over all registered property nodes
 void removeRelation(Node start, Node end)
          Remove an instance of a relation from the cache.
 void setCaching(boolean cacheOn)
          Switch on/off caching of transitive closures.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransitiveGraphCache

public TransitiveGraphCache(Node directPredicate,
                            Node closedPredicate)
Constructor - create a new cache to hold the given relation information.

Parameters:
directPredicate - The RDF predicate representing the direct relation
closedPredicate - The RDF predicate representing the closed relation
Method Detail

addRelation

public void addRelation(Node start,
                        Node end)
Register a new relation instance in the cache


removeRelation

public void removeRelation(Node start,
                           Node end)
Remove an instance of a relation from the cache.


clear

public void clear()
Clear the entire cache contents.


setCaching

public void setCaching(boolean cacheOn)
Switch on/off caching of transitive closures. Any time a closure is requested the complete result set will be cached for future reuse.

Parameters:
cacheOn - set to true to start cache, to false to stop caching

cacheAll

public boolean cacheAll(Finder graph,
                        Node predicate)
Cache all instances of the given predicate which are present in the given Graph.

Parameters:
graph - the searchable set of triples to cache
predicate - the predicate to cache, need not be the registered predicate due to subProperty declarations
Returns:
returns true if new information has been cached

find

public ExtendedIterator find(TriplePattern pattern)
Basic pattern lookup interface.

Specified by:
find in interface Finder
Parameters:
pattern - a TriplePattern to be matched against the data
Returns:
a ExtendedIterator over all Triples in the data set that match the pattern

contains

public boolean contains(TriplePattern pattern)
Return true if the given pattern occurs somewhere in the find sequence.

Specified by:
contains in interface Finder

listAllProperties

public ExtendedIterator listAllProperties()
Return an iterator over all registered property nodes


isProperty

public boolean isProperty(Node node)
Return true if the given Node is registered as a property


deepCopy

public TransitiveGraphCache deepCopy()
Create a deep copy of the cache contents. Works by creating a completely new cache and just adding in the direct links.


findWithContinuation

public ExtendedIterator findWithContinuation(TriplePattern pattern,
                                             Finder continuation)
Extended find interface used in situations where the implementator may or may not be able to answer the complete query.

In this case any query on the direct or closed predicates will be assumed complete, any other query will pass on to the continuation.

Specified by:
findWithContinuation in interface Finder
Parameters:
pattern - a TriplePattern to be matched against the data
continuation - either a Finder or a normal Graph which will be asked for additional match results if the implementor may not have completely satisfied the query.

getClosedPredicate

public Node getClosedPredicate()
Returns the closedPredicate.

Returns:
Node

getDirectPredicate

public Node getDirectPredicate()
Returns the directPredicate.

Returns:
Node


Copyright © 2001-2003 Hewlett-Packard. All Rights Reserved.