/** * Return the n'th argument node after dereferencing by what ever type of * rule engine binding environment is appropriate. */ public Node getArg(int n, Node[] args, RuleContext context) { return context.getEnv().getGroundVersion(args[n]); }
/** * 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) { if (context.getGraph() instanceof FBRuleInfGraph) { Triple t = new Triple(args[0], args[1], args[2]); ((FBRuleInfGraph)context.getGraph()).addDeduction(t); } else { throw new BuiltinException(this, context, "Only usable in FBrule graphs"); } } }
/** * Execute the given built in as a body clause. * @param context an execution context giving access to other relevant data * @return true if the functor has an implementation and that implementation returns true when evaluated */ public boolean evalAsBodyClause(RuleContext context) { if (getImplementor() == null) { logger.warn("Invoking undefined functor " + getName() + " in " + context.getRule().toShortString()); return false; } return implementor.bodyCall(getBoundArgs(context.getEnv()), args.length, context); }
/** * 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) { 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); context.remove(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"); } } }
InfGraph inf = context.getGraph(); Graph raw = inf.getRawGraph(); Graph deductions = inf.getDeductionsGraph(); 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);
/** * 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) { checkArgs(length, context); List<Node> l = Util.convertList(args[0], context); for ( Node x : l ) { for ( Node y : l ) { if ( !x.sameValueAs( y ) ) { context.add( new Triple( x, OWL.differentFrom.asNode(), y ) ); } } } }
/** * Constructor. * @param builtin the invoking builtin * @param context the invoking rule context * @param message a text explanation of the error */ public BuiltinException(Builtin builtin, RuleContext context, String message) { super("Error in clause of rule (" + context.getRule().toShortString() + ") " + builtin.getName() + ": " + message); } }
/** * Helper - returns the (singleton) value for the given property on the given * root node in the data graph. */ public static Node getPropValue(Node root, Node prop, RuleContext context) { return doGetPropValue(context.find(root, prop, null)); }
pred = null; return !context.contains(subj, pred, obj);
context = bbcontext; context.setRule(clause.getRule()); if (!builtin.bodyCall(argVars, code[pc++], context)) { if (traceOn) logger.info("FAIL " + clause + ", due to " + builtin.getName());
InfGraph inf = context.getGraph(); Graph raw = inf.getRawGraph(); Graph deductions = inf.getDeductionsGraph(); 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);
/** * Execute the given built in as a body clause. * @param context an execution context giving access to other relevant data * @return true if the functor has an implementation and that implementation returns true when evaluated */ public boolean evalAsBodyClause(RuleContext context) { if (getImplementor() == null) { logger.warn("Invoking undefined functor " + getName() + " in " + context.getRule().toShortString()); return false; } return implementor.bodyCall(getBoundArgs(context.getEnv()), args.length, context); }
/** * 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) { 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); context.remove(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"); } } }
/** * 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) { checkArgs(length, context); List<Node> l = Util.convertList(args[0], context); for ( Node x : l ) { for ( Node y : l ) { if ( !x.sameValueAs( y ) ) { context.add( new Triple( x, OWL.differentFrom.asNode(), y ) ); } } } }
/** * Constructor. * @param builtin the invoking builtin * @param context the invoking rule context * @param message a text explanation of the error */ public BuiltinException(Builtin builtin, RuleContext context, String message) { super("Error in clause of rule (" + context.getRule().toShortString() + ") " + builtin.getName() + ": " + message); } }
/** * Helper - returns the (singleton) value for the given property on the given * root node in the data graph. */ public static Node getPropValue(Node root, Node prop, RuleContext context) { return doGetPropValue(context.find(root, prop, null)); }
pred = null; return !context.contains(subj, pred, obj);
context = bbcontext; context.setRule(clause.getRule()); if (!builtin.bodyCall(argVars, code[pc++], context)) { if (traceOn) logger.info("FAIL " + clause + ", due to " + builtin.getName());
/** * Return the n'th argument node after dereferencing by what ever type of * rule engine binding environment is appropriate. */ public Node getArg(int n, Node[] args, RuleContext context) { return context.getEnv().getGroundVersion(args[n]); }