public class TruthMaintenance extends Object
TruthMaintenance
class facilitates maintaining the RDF(S)+
closure on a database as SPO
s 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 SPO
s may be written.
The caller writes SPO
s 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 SPO
s 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.
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
TruthMaintenance(InferenceEngine inferenceEngine) |
Modifier and Type | Method and Description |
---|---|
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.
|
static int |
applyExistingStatements(AbstractTripleStore focusStore,
AbstractTripleStore database,
IElementFilter<ISPO> filter,
IChangeLog changeLog)
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.
|
ClosureStats |
assertAll(TempTripleStore tempStore,
IChangeLog changeLog)
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 SPO s to be
either asserted or retracted from the database. |
ClosureStats |
retractAll(TempTripleStore tempStore)
Perform truth maintenance for statement retraction.
|
ClosureStats |
retractAll(TempTripleStore tempStore,
IChangeLog changeLog)
Perform truth maintenance for statement retraction.
|
protected static final org.apache.log4j.Logger log
protected static final boolean INFO
log
level is INFO or less.protected static final boolean DEBUG
log
level is DEBUG or less.protected final AbstractTripleStore database
protected final InferenceEngine inferenceEngine
public TruthMaintenance(InferenceEngine inferenceEngine)
inferenceEngine
- The inference engine for the database.public TempTripleStore newTempTripleStore()
TempTripleStore
backed by a shared
TemporaryStore
that may be used to buffer SPO
s 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!
public AbstractTripleStore getDatabase()
public static int applyExistingStatements(AbstractTripleStore focusStore, AbstractTripleStore database, IElementFilter<ISPO> filter)
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.public static int applyExistingStatements(AbstractTripleStore focusStore, AbstractTripleStore database, IElementFilter<ISPO> filter, IChangeLog changeLog)
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.changeLog
- optional change log for change notificationpublic ClosureStats assertAll(TempTripleStore tempStore)
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.
tempStore
- A temporary store containing statements to be asserted. The
tempStore will be closed as a post-condition.public ClosureStats assertAll(TempTripleStore tempStore, IChangeLog changeLog)
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.
tempStore
- A temporary store containing statements to be asserted. The
tempStore will be closed as a post-condition.changeLog
- optional change log for change notificationpublic ClosureStats retractAll(TempTripleStore tempStore)
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).
tempStore
- A temporary store containing explicit statements to be
retracted from the database. The tempStore will be closed and
as a post-condition.public ClosureStats retractAll(TempTripleStore tempStore, IChangeLog changeLog)
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).
tempStore
- A temporary store containing explicit statements to be
retracted from the database. The tempStore will be closed and
as a post-condition.changeLog
- optional change log for change notificationCopyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.