com.bigdata.rdf.inf
Class TruthMaintenance

java.lang.Object
  extended by com.bigdata.rdf.inf.TruthMaintenance

public class TruthMaintenance
extends Object

The TruthMaintenance class facilitates maintaining the RDF(S)+ closure on a database as SPOs are asserted or retracted. This is a flyweight class that accepts a reference to the database and provides a factory for a TempTripleStore on which SPOs may be written. The caller writes SPOs on the TempTripleStore and then invokes either assertAll(TempTripleStore) or retractAll(TempTripleStore) as appropriate to update the closure of the database, at which point the TempTripleStore is discarded (closed and deleted). An instance of this class may be reused, but you need to obtain a new TempTripleStore using newTempTripleStore() each time you want to buffer more SPOs after updating the closure.

Note: Neither this class nor updating closure is thread-safe. In particular, clients MUST NOT write on either the database or the TempTripleStore when the closure is being updated. The truth maintenance algorithm assumes that the database and tempStore are unchanging outside of the actions taken by the algorithm itself. Concurrent writers would violate this assumption and lead to incorrect truth maintenance at the best.

Version:
$Id: TruthMaintenance.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson
TODO:
make sure that we always closeAndDelete the tempStore, even on error?, Provide a means for creating a with-tx tempStore., handle update of closure for scale-out. FIXME integrate with IRIS (magic sets) to avoid the necessity for truth maintenance and recover the space and time lost to the justification chains as well. See http://sourceforge.net/projects/iris-reasoner/ as well.

Field Summary
protected  AbstractTripleStore database
          The target database.
protected static boolean DEBUG
          True iff the log level is DEBUG or less.
protected  InferenceEngine inferenceEngine
          The object used to compute entailments for that database.
protected static boolean INFO
          True iff the log level is INFO or less.
protected static org.apache.log4j.Logger log
          Logger.
 
Constructor Summary
TruthMaintenance(InferenceEngine inferenceEngine)
           
 
Method Summary
static int applyExistingStatements(AbstractTripleStore focusStore, AbstractTripleStore database, IElementFilter<ISPO> filter)
          Any statements in the fousStore that are already in the database are converted to explicit statements (iff they are not already explicit) and removed from the focusStore as a side-effect.
 ClosureStats assertAll(TempTripleStore tempStore)
          Perform truth maintenance for statement assertion.
 AbstractTripleStore getDatabase()
          The database whose closure will be updated.
 TempTripleStore newTempTripleStore()
          Return a new TempTripleStore backed by a shared TemporaryStore that may be used to buffer SPOs to be either asserted or retracted from the database.
 ClosureStats retractAll(TempTripleStore tempStore)
          Perform truth maintenance for statement retraction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log
Logger.


INFO

protected static final boolean INFO
True iff the log level is INFO or less.


DEBUG

protected static final boolean DEBUG
True iff the log level is DEBUG or less.


database

protected final AbstractTripleStore database
The target database.


inferenceEngine

protected final InferenceEngine inferenceEngine
The object used to compute entailments for that database.

Constructor Detail

TruthMaintenance

public TruthMaintenance(InferenceEngine inferenceEngine)
Parameters:
inferenceEngine - The inference engine for the database.
Method Detail

newTempTripleStore

public TempTripleStore newTempTripleStore()
Return a new TempTripleStore backed by a shared TemporaryStore that may be used to buffer SPOs to be either asserted or retracted from the database. It is recommended to use this factory method to provision the tempStore as it disables the lexicon (it will not be used) but leaves other features enabled (such as all access paths) which support truth maintenance.

You can wrap this with an IStatementBuffer using:

 new StatementBuffer(getTempTripleStore(), database, bufferCapacity);
 
and then write on the IStatementBuffer, which will periodically perform batch writes on the tempStore.

Likewise, you can use IRawTripleStore.addStatements(IChunkedOrderedIterator, IElementFilter) and it will automatically perform batch writes.

Regardless, when you have written all data on the tempStore, use assertAll(TempTripleStore) or retractAll(TempTripleStore) to update the closure of the database.

Note: DO NOT use AbstractTripleStore.__tearDownUnitTest() since the backing store is shared!


getDatabase

public AbstractTripleStore getDatabase()
The database whose closure will be updated.


applyExistingStatements

public static int applyExistingStatements(AbstractTripleStore focusStore,
                                          AbstractTripleStore database,
                                          IElementFilter<ISPO> filter)
Any statements in the fousStore that are already in the database are converted to explicit statements (iff they are not already explicit) and removed from the focusStore as a side-effect. This prevents the application of the rules to data that is already known to the database.

Parameters:
focusStore - The store whose closure is being computed.
database - The database.
filter - An optional filter. Statements matching the filter are NOT written on the database, but they are still removed from the focusStore.
Returns:
The #of statements that were removed from the focusStore.
TODO:
this uses some techniques that are not scaleable if the focusStore is extremely large.

assertAll

public ClosureStats assertAll(TempTripleStore tempStore)
Perform truth maintenance for statement assertion.

This method computes the closure of the temporary store against the database, writing entailments into the temporary store. Once all entailments have been computed, it then copies the all statements in the temporary store into the database and deletes the temporary store.

Parameters:
tempStore - A temporary store containing statements to be asserted. The tempStore will be closed as a post-condition.

retractAll

public ClosureStats retractAll(TempTripleStore tempStore)
Perform truth maintenance for statement retraction.

When the closure is computed, each statement to be retracted is examined to determine whether or not it is still entailed by the database without the support of the statements that were explicitly retracted. Statements that were explicit in the database that are still provable are converted to inferences. Statements which can no longer be proven (i.e., that are not supported by a grounded Justification chain) are retracted from the database and added into another temporary store and their justifications are deleted from the database. This process repeats with the new temporary store until no fixed point (no more ungrounded statements are identified).

Parameters:
tempStore - A temporary store containing explicit statements to be retracted from the database. The tempStore will be closed and as a post-condition.
Returns:
statistics about the closure operation.


Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.