/** * 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); } }
/** * Precompute the implications of a schema graph. The statements in the graph * will be combined with the data when the final InfGraph is created. */ @Override public Reasoner bindSchema(Graph tbox) throws ReasonerException { InfGraph graph = new BasicForwardRuleInfGraph(this, rules, null, tbox); return new BasicForwardRuleReasoner(rules, graph, factory); }
/** * Parse a string as a list a rules. * @return a list of rules * @throws ParserException if there is a problem */ public static List<Rule> parseRules(String source,BuiltinRegistry registry) throws ParserException { return parseRules(new Parser(source,registry)); }
/** * 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); }
/** * Clone a functor, cloning any embedded variables. */ private Functor cloneFunctor(Functor f, Map<Node_RuleVariable, Node> vmap, BindingEnvironment env) { Node[] args = f.getArgs(); Node[] cargs = new Node[args.length]; for (int i = 0; i < args.length; i++) { cargs[i] = cloneNode(args[i], vmap, env); } Functor fn = new Functor(f.getName(), cargs, f.getImplementor()); fn.setImplementor(f.getImplementor()); return fn; }
/** Constructor - loads the rules */ public DebugRules(String rulefileName) { ruleset = Rule.parseRules(Util.loadRuleParserFromResourceFile(rulefileName)); }
/** * 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 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]); }
/** * Cause the inference graph to reconsult both the underlying graph and * the reasoner ruleset, permits the forward rule set to be dynamically changed. * Causes the entire rule engine to be rebuilt from the current ruleset and * reinitialized against the current data. Not needed for normal cases. */ public void rebindAll() { rawRules = ((FBRuleReasoner)reasoner).getRules(); instantiateRuleEngine( rawRules ); rebind(); }
/** * Helper - returns the (singleton) value for the given property on the given * root node in the data graph. */ public static Node getPropValue(Node root, Node prop, RuleContext context) { return doGetPropValue(context.find(root, prop, null)); }
/** * Test the consistency of the bound data. For RDFS this checks that all * instances of datatype-ranged properties have correct data values. * * @return a ValidityReport structure */ @Override public ValidityReport validate() { // The full configuration uses validation rules so check for these StandardValidityReport report = (StandardValidityReport)super.validate(); // Also do a hardwired check to handle the simpler configurations performDatatypeRangeValidation(report); return report; }
/** * 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); }
/** * Clone a functor, cloning any embedded variables. */ private Functor cloneFunctor(Functor f, Map<Node_RuleVariable, Node> vmap, BindingEnvironment env) { Node[] args = f.getArgs(); Node[] cargs = new Node[args.length]; for (int i = 0; i < args.length; i++) { cargs[i] = cloneNode(args[i], vmap, env); } Functor fn = new Functor(f.getName(), cargs, f.getImplementor()); fn.setImplementor(f.getImplementor()); return fn; }
/** Constructor - loads the rules */ public DebugRules(String rulefileName) { ruleset = Rule.parseRules(Util.loadRuleParserFromResourceFile(rulefileName)); }
/** * Precompute the implications of a schema graph. The statements in the graph * will be combined with the data when the final InfGraph is created. */ @Override public Reasoner bindSchema(Graph tbox) throws ReasonerException { InfGraph graph = new BasicForwardRuleInfGraph(this, rules, null, tbox); return new BasicForwardRuleReasoner(rules, graph, factory); }
/** * Parse a string as a list a rules. * @return a list of rules * @throws ParserException if there is a problem */ public static List<Rule> parseRules(String source,BuiltinRegistry registry) throws ParserException { return parseRules(new Parser(source,registry)); }
/** * 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]); }
/** * 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); } }
/** * Cause the inference graph to reconsult both the underlying graph and * the reasoner ruleset, permits the forward rule set to be dynamically changed. * Causes the entire rule engine to be rebuilt from the current ruleset and * reinitialized against the current data. Not needed for normal cases. */ public void rebindAll() { rawRules = ((FBRuleReasoner)reasoner).getRules(); instantiateRuleEngine( rawRules ); rebind(); }
/** * Helper - returns the (singleton) value for the given property on the given * root node in the data graph. */ public static Node getPropValue(Node root, Node prop, RuleContext context) { return doGetPropValue(context.find(root, prop, null)); }