/** * 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 context an execution context giving access to other relevant data * @param length the length of the argument list, may be less than the length of the args array * for some rule engines * @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(); boolean ok = false; Node a0 = getArg(0, args, context); Node a1 = getArg(1, args, context); if (Util.isNumeric(a0)) { Node newVal = Util.makeIntNode( Util.getIntValue(a0) + 1 ); ok = env.bind(args[1], newVal); } else if (Util.isNumeric(a1)) { Node newVal = Util.makeIntNode( Util.getIntValue(a1) - 1 ); ok = env.bind(args[0], newVal); } return ok; }
/** * 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 context an execution context giving access to other relevant data * @param length the length of the argument list, may be less than the length of the args array * for some rule engines * @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(); boolean ok = false; Node a0 = getArg(0, args, context); Node a1 = getArg(1, args, context); if (Util.isNumeric(a0)) { Node newVal = Util.makeIntNode( Util.getIntValue(a0) + 1 ); ok = env.bind(args[1], newVal); } else if (Util.isNumeric(a1)) { Node newVal = Util.makeIntNode( Util.getIntValue(a1) - 1 ); ok = env.bind(args[0], newVal); } return ok; }
/** * 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 list = getArg(0, args, context); Node index = getArg(1, args, context); if ( ! Util.isNumeric(index) ) return false; Node elt = getEntry(list, Util.getIntValue(index), context); if (elt == null) { return false; } else { env.bind(args[2], elt); return true; } }
/** * 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 list = getArg(0, args, context); Node index = getArg(1, args, context); if ( ! Util.isNumeric(index) ) return false; Node elt = getEntry(list, Util.getIntValue(index), context); if (elt == null) { return false; } else { env.bind(args[2], elt); return true; } }
/** * 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"); } } }
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) {
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) {