/** * 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; }
/** * Return a new Node array containing the bound versions of this Functor's arguments */ public Node[] getBoundArgs(BindingEnvironment env) { Node[] boundargs = new Node[args.length]; for (int i = 0; i < args.length; i++) { boundargs[i] = env.getGroundVersion(args[i]); } return boundargs; }
/** * 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"); } } }
/** * 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; }
/** * Return a new Node array containing the bound versions of this Functor's arguments */ public Node[] getBoundArgs(BindingEnvironment env) { Node[] boundargs = new Node[args.length]; for (int i = 0; i < args.length; i++) { boundargs[i] = env.getGroundVersion(args[i]); } return boundargs; }
Object clause = rule.getBodyElement(i); if (clause instanceof TriplePattern) { matchList.add(env.instantiate((TriplePattern)clause)); Object hClause = rule.getHeadElement(i); if (hClause instanceof TriplePattern) { Triple t = env.instantiate((TriplePattern) hClause);
/** * 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); }
/** * 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]); }
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 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); }
/** * Returns true if the functor is fully ground in the given environment */ public boolean isGround(BindingEnvironment env) { for ( Node n : args ) { if ( env.getGroundVersion( n ).isVariable() ) { return false; } } return true; }
Object clause = rule.getBodyElement(i); if (clause instanceof TriplePattern) { matchList.add(env.instantiate((TriplePattern)clause)); Object hClause = rule.getHeadElement(i); if (hClause instanceof TriplePattern) { Triple t = env.instantiate((TriplePattern) hClause);
/** * 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); } }
/** * 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]); }
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 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); } }
/** * Returns true if the functor is fully ground in the given environment */ public boolean isGround(BindingEnvironment env) { for ( Node n : args ) { if ( env.getGroundVersion( n ).isVariable() ) { return false; } } return true; }
String label = Base64.encodeBase64String(digest); Node skolem = NodeFactory.createBlankNode(label); return context.getEnv().bind(args[0], skolem); } catch (NoSuchAlgorithmException e) { throw new JenaException(e);
/** * Score a Node in terms of groundedness - heuristic. * Treats a variable as better than a wildcard because it constrains * later clauses. Treats rdf:type as worse than any other ground node * because that tends to link to lots of expensive rules. */ public static int scoreNodeBoundness(Node n, BindingEnvironment env) { if (n instanceof Node_ANY) { return 0; } else if (n instanceof Node_RuleVariable) { Node val = env.getGroundVersion(n); if (val == null) { return 1; } else if (val.equals(RDF.type.asNode())) { return 2; } else { return 3; } } else { return 3; } }