/** * 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]); }
/** * 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]); }
@Override public boolean bodyCall( final Node[] args, final int length, final RuleContext context ) { checkArgs(length, context); final Node n1 = getArg(0, args, context); final Node n2 = getArg(1, args, context); if (n1.isLiteral() && n2.isLiteral()) { final Node max = Util.compareTypedLiterals(n1, n2) < 0 ? n2 : n1; return context.getEnv().bind(args[2], max); } return false; }
/** * 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) { for (int i = 0; i < length; i++) { if (!context.getEnv().bind(args[i], NodeFactory.createBlankNode())) return false; } 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) { for (int i = 0; i < length; i++) { if (!context.getEnv().bind(args[i], NodeFactory.createBlankNode())) return false; } 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) { if (length < 1) throw new BuiltinException(this, context, "Must have at least 1 argument to " + getName()); StringBuilder buff = new StringBuilder(); for (int i = 0; i < length-1; i++) { buff.append( lex(getArg(i, args, context), context) ); } Node result = NodeFactory.createLiteral(buff.toString()); return context.getEnv().bind(args[length-1], result); }
/** * 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 < 1) throw new BuiltinException(this, context, "Must have at least 1 argument to " + getName()); StringBuilder buff = new StringBuilder(); for (int i = 0; i < length-1; i++) { buff.append( lex(getArg(i, args, context), context) ); } Node result = NodeFactory.createURI( buff.toString() ); return context.getEnv().bind(args[length-1], result); } }
/** * 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 < 1) throw new BuiltinException(this, context, "Must have at least 1 argument to " + getName()); StringBuilder buff = new StringBuilder(); for (int i = 0; i < length-1; i++) { buff.append( lex(getArg(i, args, context), context) ); } Node result = NodeFactory.createLiteral(buff.toString()); return context.getEnv().bind(args[length-1], result); }
/** * 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 * @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 now = NodeFactory.createLiteral( LiteralLabelFactory.createTypedLiteral(new XSDDateTime(Calendar.getInstance())) ); return env.bind(args[0], now); } }
/** * 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 < 1) throw new BuiltinException(this, context, "Must have at least 1 argument to " + getName()); StringBuilder buff = new StringBuilder(); for (int i = 0; i < length-1; i++) { buff.append( lex(getArg(i, args, context), context) ); } Node result = NodeFactory.createURI( buff.toString() ); return context.getEnv().bind(args[length-1], result); } }
/** * 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); }
/** * 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 * @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 now = NodeFactory.createLiteral( LiteralLabelFactory.createTypedLiteral(new XSDDateTime(Calendar.getInstance())) ); return env.bind(args[0], now); } }
/** * 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 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(); int len = getLength(getArg(0, args, context), context); if (len == -1) { return false; } else { env.bind(args[1], Util.makeIntNode(len)); 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(); int len = getLength(getArg(0, args, context), context); if (len == -1) { return false; } else { env.bind(args[1], Util.makeIntNode(len)); 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 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; }
@Override public boolean bodyCall(Node[] args, int length, RuleContext context) { checkArgs(length, context); BindingEnvironment env = context.getEnv(); Triple t = new Triple( NodeFactory.createBlankNode(), NodeFactory.createURI("http://jena.hpl.hp.com/example#"), NodeFactory.createBlankNode()); Node l = NodeFactory.createLiteral( LiteralLabelFactory.createTypedLiteral(t) ); return env.bind(args[0], l); } }
@Override public boolean bodyCall(Node[] args, int length, RuleContext context) { checkArgs(length, context); BindingEnvironment env = context.getEnv(); Triple t = new Triple( NodeFactory.createBlankNode(), NodeFactory.createURI("http://jena.hpl.hp.com/example#"), NodeFactory.createBlankNode()); Node l = NodeFactory.createLiteral( LiteralLabelFactory.createTypedLiteral(t) ); return env.bind(args[0], l); } }