/** * 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) { throw new BuiltinException(this, context, "builtin " + getName() + " not usable in rule heads"); }
/** * 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) { throw new BuiltinException(this, context, "builtin " + getName() + " not usable in rule heads"); }
/** * 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) { throw new BuiltinException(this, context, "builtin " + getName() + " not usable in rule bodies"); }
/** * This method is invoked when the builtin is called in a rule head. * Such a use is only valid in a forward rule. * Exected args are the instance to be annotated, the property to use and the type * of the resulting bNode. * @param args the array of argument values for the builtin, this is an array * of Nodes. * @param context an execution context giving access to other relevant data */ public void headAction(Node[] args, RuleContext context) { // Can't be used in the head throw new BuiltinException(this, context, "can't do " + getName() + " in rule heads"); } }
/** * This method is invoked when the builtin is called in a rule head. * Such a use is only valid in a forward rule. * Exected args are the instance to be annotated, the property to use and the type * of the resulting bNode. * @param args the array of argument values for the builtin, this is an array * of Nodes. * @param context an execution context giving access to other relevant data */ public void headAction(Node[] args, RuleContext context) { // Can't be used in the head throw new BuiltinException(this, context, "can't do " + getName() + " in rule heads"); } }
/** * 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) { throw new BuiltinException(this, context, "builtin " + getName() + " not usable in rule bodies"); }
/** * Check the argument length. */ public void checkArgs(int length, RuleContext context) { int expected = getArgLength(); if (expected > 0 && expected != length) { throw new BuiltinException(this, context, "builtin " + getName() + " requires " + expected + " arguments but saw " + length); } }
/** * Check the argument length. */ public void checkArgs(int length, RuleContext context) { int expected = getArgLength(); if (expected > 0 && expected != length) { throw new BuiltinException(this, context, "builtin " + getName() + " requires " + expected + " arguments but saw " + length); } }
/** * Shared implementation applicable to head or body */ private void doHide(Node[] args, int length, RuleContext context ) { InfGraph g = context.getGraph(); if (g instanceof FBRuleInfGraph) { for (int i = 0; i < length; i++) { ((FBRuleInfGraph)g).hideNode(args[i]); } } else { throw new BuiltinException(this, context, "hide only available for FB rule engines"); } } }
/** * Shared implementation applicable to head or body */ private void doHide(Node[] args, int length, RuleContext context ) { InfGraph g = context.getGraph(); if (g instanceof FBRuleInfGraph) { for (int i = 0; i < length; i++) { ((FBRuleInfGraph)g).hideNode(args[i]); } } else { throw new BuiltinException(this, context, "hide only available for FB rule engines"); } } }
/** * Return the lexical form of a literal node, error for other node types */ protected String getString(Node n, RuleContext context) { if (n.isLiteral()) { return n.getLiteralLexicalForm(); } else { throw new BuiltinException(this, context, getName() + " takes only literal arguments"); } }
/** * Return the lexical form of a literal node, error for other node types */ protected String getString(Node n, RuleContext context) { if (n.isLiteral()) { return n.getLiteralLexicalForm(); } else { throw new BuiltinException(this, context, getName() + " takes only literal arguments"); } }
/** * 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.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.createURI( buff.toString() ); return context.getEnv().bind(args[length-1], result); } }
/** * 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"); } } }
/** * 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"); } } }
/** * Return the appropriate lexical form of a node */ protected String lex(Node n, RuleContext context) { if (n.isBlank()) { return n.getBlankNodeLabel(); } else if (n.isURI()) { return n.getURI(); } else if (n.isLiteral()) { return n.getLiteralLexicalForm(); } else { throw new BuiltinException(this, context, "Illegal node type: " + n); } }
/** * Return the appropriate lexical form of a node */ protected String lex(Node n, RuleContext context) { if (n.isBlank()) { return n.getBlankNodeLabel(); } else if (n.isURI()) { return n.getURI(); } else if (n.isLiteral()) { return n.getLiteralLexicalForm(); } else { throw new BuiltinException(this, context, "Illegal node type: " + n); } }