📄 basicforwardruleinfgraph.java
字号:
* This implementation assumes that the underlying findWithContinuation
* will have also consulted the raw data.
*/
public ExtendedIterator graphBaseFind(Node subject, Node property, Node object) {
return findWithContinuation(new TriplePattern(subject, property, object), null);
}
/**
* Basic pattern lookup interface.
* This implementation assumes that the underlying findWithContinuation
* will have also consulted the raw data.
* @param pattern a TriplePattern to be matched against the data
* @return a ExtendedIterator over all Triples in the data set
* that match the pattern
*/
public ExtendedIterator find(TriplePattern pattern) {
return findWithContinuation(pattern, null);
}
/**
* Add one triple to the data graph, run any rules triggered by
* the new data item, recursively adding any generated triples.
*/
public synchronized void performAdd(Triple t) {
version++;
fdata.getGraph().add(t);
if (isPrepared) {
engine.add(t);
}
}
/**
* Return the number of triples in the inferred graph
*/
public int graphBaseSize() {
checkOpen();
if (!isPrepared) {
prepare();
}
int baseSize = fdata.getGraph().size();
int dedSize = fdeductions.getGraph().size();
// System.err.println( ">> BasicForwardRuleInfGraph::size = " + baseSize + "(base) + " + dedSize + "(deductions)" );
return baseSize + dedSize;
}
/**
* Removes the triple t (if possible) from the set belonging to this graph.
*/
public void performDelete(Triple t) {
version++;
if (fdata != null) {
Graph data = fdata.getGraph();
if (data != null) {
data.delete(t);
}
}
if (isPrepared) {
fdeductions.getGraph().delete(t);
}
}
/**
* Free all resources, any further use of this Graph is an error.
*/
public void close() {
if (!closed) {
engine = null;
fdeductions = null;
rules = null;
schemaGraph = null;
super.close();
}
}
// =======================================================================
// Implementation of ForwardRuleInfGraphI interface which is used by
// the forward rule engine to invoke functions in this InfGraph
/**
* Adds a new Backward rule as a rules of a forward rule process. Only some
* infgraphs support this.
*/
public void addBRule(Rule brule) {
throw new ReasonerException("Forward reasoner does not support hybrid rules - " + brule.toShortString());
}
/**
* Deletes a new Backward rule as a rules of a forward rule process. Only some
* infgraphs support this.
*/
public void deleteBRule(Rule brule) {
throw new ReasonerException("Forward reasoner does not support hybrid rules - " + brule.toShortString());
}
/**
* Return the Graph containing all the static deductions available so far.
*/
public Graph getDeductionsGraph() {
prepare();
return fdeductions.getGraph();
}
/**
* Create the graph used to hold the deductions. Can be overridden
* by subclasses that need special purpose graph implementations here.
* Assumes the graph underlying fdeductions can be reused if present.
*/
protected Graph createDeductionsGraph() {
if (fdeductions != null) {
Graph dg = fdeductions.getGraph();
if (dg != null) {
// Reuse the old graph in order to preserve any listeners
dg.getBulkUpdateHandler().removeAll();
return dg;
}
}
return Factory.createGraphMem( style );
}
/**
* Return the Graph containing all the static deductions available so far.
* Does not trigger a prepare action.
*/
public Graph getCurrentDeductionsGraph() {
return fdeductions.getGraph();
}
/**
* Search the combination of data and deductions graphs for the given triple pattern.
* This may different from the normal find operation in the base of hybrid reasoners
* where we are side-stepping the backward deduction step.
*/
public ExtendedIterator findDataMatches(Node subject, Node predicate, Node object) {
return find(subject, predicate, object);
}
/**
* Log a dervivation record against the given triple.
*/
public void logDerivation(Triple t, Object derivation) {
derivations.put(t, derivation);
}
/**
* Assert a new triple in the deduction graph, bypassing any processing machinery.
*/
public void silentAdd(Triple t) {
fdeductions.getGraph().add(t);
}
//=======================================================================
// support for proof traces
/**
* Set to true to enable derivation caching
*/
public void setDerivationLogging(boolean recordDerivations) {
this.recordDerivations = recordDerivations;
engine.setDerivationLogging(recordDerivations);
if (recordDerivations) {
derivations = new OneToManyMap();
} else {
derivations = null;
}
}
/**
* Return true if derivation logging is enabled.
*/
public boolean shouldLogDerivations() {
return recordDerivations;
}
/**
* Return the derivation of at triple.
* The derivation is a List of DerivationRecords
*/
public Iterator getDerivation(Triple t) {
if (derivations == null) {
return new NullIterator();
} else {
return derivations.getAll(t);
}
}
/**
* Set the state of the trace flag. If set to true then rule firings
* are logged out to the Log at "INFO" level.
*/
public void setTraceOn(boolean state) {
traceOn = state;
}
/**
* Return true if tracing should be acted on - i.e. if traceOn is true
* and we are past the bootstrap phase.
*/
public boolean shouldTrace() {
return traceOn && engine.shouldTrace();
}
/**
* Return the number of rules fired since this rule engine instance
* was created and initialized
*/
public long getNRulesFired() {
return engine.getNRulesFired();
}
public Reifier constructReifier()
{
BasicFBReifier.GetReifier deductionsReifier = new BasicFBReifier.GetReifier()
{
public Reifier getReifier() { return getDeductionsGraph().getReifier(); }
};
return new BasicFBReifier( this, getRawGraph().getReifier(), deductionsReifier, style );
}
}
/*
(c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -