/** * 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); } }
/** * 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); } }
/** * 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); }
/** * 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); }
/** * Execute the given built in as a body clause, only if it is side-effect-free. * @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 safeEvalAsBodyClause(RuleContext context) { if (getImplementor() == null) { logger.warn("Invoking undefined functor " + getName() + " in " + context.getRule().toShortString()); return false; } if (implementor.isSafe()) { return implementor.bodyCall(getBoundArgs(context.getEnv()), args.length, context); } else { return false; } }
/** * Execute the given built in as a body clause, only if it is side-effect-free. * @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 safeEvalAsBodyClause(RuleContext context) { if (getImplementor() == null) { logger.warn("Invoking undefined functor " + getName() + " in " + context.getRule().toShortString()); return false; } if (implementor.isSafe()) { return implementor.bodyCall(getBoundArgs(context.getEnv()), args.length, context); } else { return false; } }
/** * 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) { 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"); } } }
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);
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);