📄 fbrulereasoner.java
字号:
graph.setDerivationLogging( recordDerivations );
graph.setTraceOn( traceOn );
graph.rebind( data );
return graph;
}
/**
* Set (or change) the rule set that this reasoner should execute.
* @param rules a list of Rule objects
*/
public void setRules(List rules) {
this.rules = rules;
preload = null;
if (schemaGraph != null) {
// The change of rules invalidates the existing precomputed schema graph
// This might be recoverable but for now simply flag the error and let the
// user reorder their code to set the rules before doing a bind!
throw new ReasonerException("Cannot change the rule set for a bound rule reasoner.\nSet the rules before calling bindSchema");
}
}
/**
* Return the list of Rules used by this reasoner
* @return a List of Rule objects
*/
public List getRules() {
return rules;
}
/**
Answer the list of rules loaded from the given filename. May throw a
ReasonerException wrapping an IOException.
*/
public static List loadRules( String fileName ) {
try
{ return Rule.parseRules(Util.loadRuleParserFromResourceFile( fileName ) ); }
catch (WrappedIOException e)
{ throw new ReasonerException("Can't load rules file: " + fileName, e.getCause() ); }
}
/**
* Register an RDF predicate as one whose presence in a goal should force
* the goal to be tabled. This is better done directly in the rule set.
*/
public synchronized void tablePredicate(Node predicate) {
// Create a dummy rule which tables the predicate ...
Rule tablePredicateRule = new Rule("",
new ClauseEntry[]{
new Functor("table", new Node[] { predicate })
},
new ClauseEntry[]{});
// ... end append the rule to the ruleset
rules.add(tablePredicateRule);
}
/**
* Get the single static precomputed rule closure.
*/
protected synchronized InfGraph getPreload() {
if (cachePreload && preload == null) {
preload = (new FBRuleInfGraph(this, rules, null));
preload.prepare();
}
return preload;
}
/**
* Switch on/off drivation logging.
* If set to true then the InfGraph created from the bind operation will start
* life with recording of derivations switched on. This is currently only of relevance
* to rule-based reasoners.
* <p>
* Default - false.
*/
public void setDerivationLogging(boolean logOn) {
recordDerivations = logOn;
}
/**
* 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 the state of the trace flag.If set to true then rule firings
* are logged out to the Log at "INFO" level.
*/
public boolean isTraceOn() {
return traceOn;
}
/**
* Set a configuration parameter for the reasoner. The supported parameters
* are:
* <ul>
* <li>PROPderivationLogging - set to true to enable recording all rule derivations</li>
* <li>PROPtraceOn - set to true to enable verbose trace information to be sent to the logger INFO channel</li>
* </ul>
*
* @param parameter the property identifying the parameter to be changed
* @param value the new value for the parameter, typically this is a wrapped
* java object like Boolean or Integer.
* @throws IllegalParameterException if the parameter is unknown
*/
public void setParameter(Property parameter, Object value) {
if (!doSetParameter(parameter, value)) {
throw new IllegalParameterException("RuleReasoner does not recognize configuration parameter " + parameter);
} else {
// Record the configuration change
if (configuration == null) {
Model configModel = ModelFactory.createDefaultModel();
configuration = configModel.createResource();
}
Util.updateParameter(configuration, parameter, value);
}
}
/**
Set a parameter from a statement, given the property and its RDFNode value.
Most parameters are, historically, set from the string value of the RDFNode,
but newer parameters may have Resource values with embedded models,
for which their toString() is not just suspect, but definitively wrong. Hence the
introduction of this relay station.
@param parameter the propoerty naming the value to set
@param value the RDFNode with the value of that property
@return true if the property was understood, false otherwise
*/
protected boolean doSetRDFNodeParameter( Property parameter, RDFNode value )
{
return
(value instanceof Resource && doSetResourceParameter( parameter, (Resource) value ))
|| doSetParameter( parameter, value.toString() )
;
}
/**
Set a parameter with a Resource value. Answer false if the parameter is not
understood. Default understands no parameters; subclasses may override.
*/
protected boolean doSetResourceParameter( Property parameter, Resource value )
{ return false; }
/**
* Set a configuration parameter for the reasoner. The supported parameters
* are:
* <ul>
* <li>PROPderivationLogging - set to true to enable recording all rule derivations</li>
* <li>PROPtraceOn - set to true to enable verbose trace information to be sent to the logger INFO channel</li>
* </ul>
* @param parameter the property identifying the parameter to be changed
* @param value the new value for the parameter, typically this is a wrapped
* java object like Boolean or Integer.
* @return false if the parameter was not known
*/
protected boolean doSetParameter(Property parameter, Object value) {
if (parameter.equals(ReasonerVocabulary.PROPderivationLogging)) {
recordDerivations = Util.convertBooleanPredicateArg(parameter, value);
return true;
} else if (parameter.equals(ReasonerVocabulary.PROPtraceOn)) {
traceOn = Util.convertBooleanPredicateArg(parameter, value);
return true;
} else {
return false;
}
}
/**
* Return the Jena Graph Capabilties that the inference graphs generated
* by this reasoner are expected to conform to.
*/
public Capabilities getGraphCapabilities() {
if (capabilities == null) {
capabilities = new BaseInfGraph.InfCapabilities();
}
return capabilities;
}
}
/*
(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 + -