本文整理汇总了Java中com.hp.hpl.jena.reasoner.rulesys.RuleContext类的典型用法代码示例。如果您正苦于以下问题:Java RuleContext类的具体用法?Java RuleContext怎么用?Java RuleContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RuleContext类属于com.hp.hpl.jena.reasoner.rulesys包,在下文中一共展示了RuleContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
if (n1.isLiteral()) {
Object v1 = n1.getLiteralValue();
Node cos = null;
if (v1 instanceof Number) {
Number nv1 = (Number)v1;
double absd = Math.cos(nv1.doubleValue());
cos = Util.makeDoubleNode(absd);
return env.bind(args[1], cos);
}
}
// Doesn't (yet) handle partially bound cases
return false;
}
示例2: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
if (n1.isLiteral()) {
Object v1 = n1.getLiteralValue();
Node asin = null;
if (v1 instanceof Number) {
Number nv1 = (Number)v1;
double absd = Math.asin(nv1.doubleValue());
asin = Util.makeDoubleNode(absd);
return env.bind(args[1], asin);
}
}
// Doesn't (yet) handle partially bound cases
return false;
}
示例3: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
if (n1.isLiteral()) {
Object v1 = n1.getLiteralValue();
Node acos = null;
if (v1 instanceof Number) {
Number nv1 = (Number)v1;
double absd = Math.acos(nv1.doubleValue());
acos = Util.makeDoubleNode(absd);
return env.bind(args[1], acos);
}
}
// Doesn't (yet) handle partially bound cases
return false;
}
示例4: averageOfList
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
private double averageOfList(Node lst, RuleContext context) {
java.util.List<Node> l = Util.convertList(lst, context);
int cnt = 0;
double sum = 0;
for (int i = 0; l != null && i < l.size(); i++) {
Node elt = (Node) l.get(i);
if (elt != null && elt.isLiteral()) {
Object v1 = elt.getLiteralValue();
if (v1 instanceof Number) {
sum += ((Number) v1).doubleValue();
cnt++;
}
else {
throw new BuiltinException(this, context, "Element of list input to max not a number: " + v1.toString());
}
}
else {
throw new BuiltinException(this, context, "Element of list input to max not a Literal: " + elt.toString());
}
}
if (cnt < 1) {
throw new BuiltinException(this, context, "Can't average an empty List!");
}
return sum / cnt;
}
示例5: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
if (n1.isURI()) {
String ln = n1.getLocalName();
logger.debug("returning localname '" + ln + "'");
Node lnn = NodeFactory.createLiteral(LiteralLabelFactory.create(ln));
return env.bind(args[1], lnn);
}
else {
logger.debug("Node '" + n1.toString() + "' is not a URI, can't extract localname");
}
// Doesn't (yet) handle partially bound cases
return false;
}
示例6: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
if (n1.isLiteral()) {
Object v1 = n1.getLiteralValue();
Node floor = null;
if (v1 instanceof Number) {
Number nv1 = (Number)v1;
double absd = Math.floor(nv1.doubleValue());
floor = Util.makeLongNode((long) absd);
return env.bind(args[1], floor);
}
}
// Doesn't (yet) handle partially bound cases
return false;
}
示例7: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
if (n1.isLiteral()) {
Object v1 = n1.getLiteralValue();
Node tan = null;
if (v1 instanceof Number) {
Number nv1 = (Number)v1;
double absd = Math.tan(nv1.doubleValue());
tan = Util.makeDoubleNode(absd);
return env.bind(args[1], tan);
}
}
// Doesn't (yet) handle partially bound cases
return false;
}
示例8: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
if (n1.isLiteral()) {
Object v1 = n1.getLiteralValue();
Node atan = null;
if (v1 instanceof Number) {
Number nv1 = (Number)v1;
double absd = Math.atan(nv1.doubleValue());
atan = Util.makeDoubleNode(absd);
return env.bind(args[1], atan);
}
}
// Doesn't (yet) handle partially bound cases
return false;
}
示例9: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
if (n1.isLiteral()) {
Object v1 = n1.getLiteralValue();
Node sqrtn = null;
if (v1 instanceof Number) {
Number nv1 = (Number)v1;
double sqrtd = Math.sqrt(nv1.doubleValue());
sqrtn = Util.makeDoubleNode(sqrtd);
return env.bind(args[1], sqrtn);
}
}
// Doesn't (yet) handle partially bound cases
return false;
}
示例10: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
if (n1.isLiteral()) {
Object v1 = n1.getLiteralValue();
Node sin = null;
if (v1 instanceof Number) {
Number nv1 = (Number)v1;
double absd = Math.sin(nv1.doubleValue());
sin = Util.makeDoubleNode(absd);
return env.bind(args[1], sin);
}
}
// Doesn't (yet) handle partially bound cases
return false;
}
示例11: addObjectProperty
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* Call this method to add a triple to the context when the URI is known for subject, property, and object value.
* @param context - the RuleContext from the calling built-in
* @param subject - the subject node
* @param predUri - the property URI
* @param object - the object value node
*/
public static synchronized void addObjectProperty(RuleContext context, Node_URI subject, String predUri, Node_URI object) {
if (subject == null) {
_logger.error("addObjectProperty called with null subject");
return;
}
if (predUri == null) {
_logger.error("addObjectProperty called with null property URI");
return;
}
if (object == null) {
_logger.error("addObjectProperty called with null object");
return;
}
Node_URI prop = (Node_URI) NodeFactory.createURI(predUri);
Triple t = new Triple(subject, prop, object);
doAddTriple(t, context, true);
if (_logger.isDebugEnabled()) {
_logger.debug("in Rule " + context.getRule().getName() + " added new triple (" + t.toString() + ") (notify deductions true)");
}
// Utils.deleteReplaceCreateValue(context, subject, prop, object);
}
示例12: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
if (n1.isLiteral()) {
Object v1 = n1.getLiteralValue();
Node ceiling = null;
if (v1 instanceof Number) {
Number nv1 = (Number)v1;
double absd = Math.ceil(nv1.doubleValue());
ceiling = Util.makeLongNode((long) absd);
return env.bind(args[1], ceiling);
}
}
// Doesn't (yet) handle partially bound cases
return false;
}
示例13: headAction
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule head.
* Such a use is only valid in a forward rule.
* @param args the array of argument values for the builtin, this is an array
* of Nodes.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
*/
@Override
public void headAction(Node[] args, int length, RuleContext context) {
boolean ok = false;
InfGraph inf = context.getGraph();
Graph raw = inf.getRawGraph();
Graph deductions = inf.getDeductionsGraph();
for (int i = 0; i < length; i++) {
Node clauseN = getArg(i, args, context);
if (Util.isNumeric(clauseN)) {
int clauseIndex = Util.getIntValue(clauseN);
Object clause = context.getRule().getBodyElement(clauseIndex);
if (clause instanceof TriplePattern) {
Triple t = context.getEnv().instantiate((TriplePattern)clause);
raw.delete(t);
deductions.delete(t);
} else {
throw new BuiltinException(this, context, "illegal triple to remove non-triple clause");
}
} else {
throw new BuiltinException(this, context, "illegal arg to remove (" + clauseN + "), must be an integer");
}
}
}
示例14: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
@Override
public boolean bodyCall(Node[] args, int length, RuleContext context) {
if (length < 2)
throw new BuiltinException(this, context, "Must have at least 2 arguments to " + getName());
String text = getString( getArg(0, args, context), context );
String pattern = getString( getArg(1, args, context), context );
Matcher m = Pattern.compile(pattern).matcher(text);
if ( ! m.matches()) return false;
if (length > 2) {
// bind any capture groups
BindingEnvironment env = context.getEnv();
for (int i = 0; i < Math.min(length-2, m.groupCount()); i++) {
String gm = m.group(i+1);
Node match = (gm != null) ? Node.createLiteral( gm ) : Node.createLiteral("");
if ( !env.bind(args[i+2], match) ) return false;
}
}
return true;
}
示例15: bodyCall
import com.hp.hpl.jena.reasoner.rulesys.RuleContext; //导入依赖的package包/类
/**
* This method is invoked when the builtin is called in a rule body.
* @param args the array of argument values for the builtin, this is an array
* of Nodes, some of which may be Node_RuleVariables.
* @param length the length of the argument list, may be less than the length of the args array
* for some rule engines
* @param context an execution context giving access to other relevant data
* @return return true if the buildin predicate is deemed to have succeeded in
* the current environment
*/
@Override
public boolean bodyCall(Node[] args, int length, RuleContext context) {
checkArgs(length, context);
BindingEnvironment env = context.getEnv();
Node n1 = getArg(0, args, context);
Node n2 = getArg(1, args, context);
if (n1.isLiteral() && n2.isLiteral()) {
Object v1 = n1.getLiteralValue();
Object v2 = n2.getLiteralValue();
Node sum = null;
if (v1 instanceof Number && v2 instanceof Number) {
Number nv1 = (Number)v1;
Number nv2 = (Number)v2;
if (v1 instanceof Float || v1 instanceof Double
|| v2 instanceof Float || v2 instanceof Double) {
sum = Util.makeDoubleNode(nv1.doubleValue() / nv2.doubleValue());
} else {
sum = Util.makeLongNode(nv1.longValue() / nv2.longValue());
}
return env.bind(args[2], sum);
}
}
// Doesn't (yet) handle partially bound cases
return false;
}