/** * Constructor * @param name the name of the functor * @param args an array of nodes defining the arguments * @param registry a table of builtins to consult to check for * implementations of this functor when used as a rule clause */ public Functor(String name,Node[] args, BuiltinRegistry registry) { this(name, args,registry.getImplementation(name)); }
@Override public Builtin getImplementationByURI(String uri) { Builtin that=builtinsByURI.get(uri); return that==null ? innerRegistry.getImplementationByURI(uri) : that; } }
BuiltinRegistry.theRegistry.register(new Deduce()); Map<String, String> prefixes = new HashMap<>(); List<Rule> rules = loadRules(filenameArgs.get(0), prefixes);
r.register(b); assertEquals(b,r.getImplementation("groo")); List<Rule> rules=new ArrayList<>();
BuiltinRegistry.theRegistry.register(new Deduce()); Map<String, String> prefixes = new HashMap<>(); List<Rule> rules = loadRules(filenameArgs.get(0), prefixes);
r.register(b); assertEquals(b,r.getImplementation("groo")); List<Rule> rules=new ArrayList<>();
/** * Return the Builtin that implements this functor * @return the Builtin or null if there isn't one */ public Builtin getImplementor() { if (implementor == null) { implementor = BuiltinRegistry.theRegistry.getImplementation(name); } return implementor; }
/** * Check ability to report literals as well as resources as culprits */ public void testLiteralsInErrorReports() { RDFNode culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 42). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?X)."); assertEquals( culprit, ResourceFactory.createTypedLiteral( new Integer(42) )); culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 'foo'). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?X)."); assertEquals( culprit, ResourceFactory.createPlainLiteral("foo")); BuiltinRegistry.theRegistry.register( new SomeTriple() ); culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 42). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?Y), someTriple(?X)."); assertTrue( culprit.isLiteral() ); Object val = ((Literal)culprit).getValue(); assertTrue( val instanceof Triple); }
@Override public Builtin getImplementationByURI(String uri) { Builtin that=builtinsByURI.get(uri); return that==null ? innerRegistry.getImplementationByURI(uri) : that; } }
/** * Constructor * @param name the name of the functor * @param args an array of nodes defining the arguments * @param registry a table of builtins to consult to check for * implementations of this functor when used as a rule clause */ public Functor(String name,Node[] args, BuiltinRegistry registry) { this(name, args,registry.getImplementation(name)); }
/** * Check ability to report literals as well as resources as culprits */ public void testLiteralsInErrorReports() { RDFNode culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 42). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?X)."); assertEquals( culprit, ResourceFactory.createTypedLiteral( new Integer(42) )); culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 'foo'). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?X)."); assertEquals( culprit, ResourceFactory.createPlainLiteral("foo")); BuiltinRegistry.theRegistry.register( new SomeTriple() ); culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 42). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?Y), someTriple(?X)."); assertTrue( culprit.isLiteral() ); Object val = ((Literal)culprit).getValue(); assertTrue( val instanceof Triple); }
/** * Constructor * @param name the name of the functor * @param args a list of nodes defining the arguments * @param registry a table of builtins to consult to check for * implementations of this functor when used as a rule clause */ public Functor(String name, List<Node> args, BuiltinRegistry registry) { this(name, args,registry.getImplementation(name)); }
/** * Test closure of grounded choice points */ public void testGroundClosure2() { Flag myFlag = new Flag(); BuiltinRegistry.theRegistry.register(myFlag); List<Rule> rules = Rule.rulesFromURL("file:testing/reasoners/bugs/groundClosure2.rules"); GenericRuleReasoner reasoner = new GenericRuleReasoner( rules ); InfModel inf = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel()); String NS = "http://jena.hpl.hp.com/example#"; Resource Phil = inf.getResource(NS + "Phil"); Resource Paul = inf.getResource(NS + "Paul"); Property parent = inf.getProperty(NS + "parent"); assertTrue ( inf.contains(Paul, parent, Phil) ); assertTrue( ! myFlag.fired ); }
/** * Constructor * @param name the name of the functor * @param args a list of nodes defining the arguments * @param registry a table of builtins to consult to check for * implementations of this functor when used as a rule clause */ public Functor(String name, List<Node> args, BuiltinRegistry registry) { this(name, args,registry.getImplementation(name)); }
/** * Test closure of grounded choice points */ public void testGroundClosure2() { Flag myFlag = new Flag(); BuiltinRegistry.theRegistry.register(myFlag); List<Rule> rules = Rule.rulesFromURL("file:testing/reasoners/bugs/groundClosure2.rules"); GenericRuleReasoner reasoner = new GenericRuleReasoner( rules ); InfModel inf = ModelFactory.createInfModel(reasoner, ModelFactory.createDefaultModel()); String NS = "http://jena.hpl.hp.com/example#"; Resource Phil = inf.getResource(NS + "Phil"); Resource Paul = inf.getResource(NS + "Paul"); Property parent = inf.getProperty(NS + "parent"); assertTrue ( inf.contains(Paul, parent, Phil) ); assertTrue( ! myFlag.fired ); }
/** * Return the Builtin that implements this functor * @return the Builtin or null if there isn't one */ public Builtin getImplementor() { if (implementor == null) { implementor = BuiltinRegistry.theRegistry.getImplementation(name); } return implementor; }
/** * Test closure of grounded choice points */ public void testGroundClosure() { Flag myFlag = new Flag(); BuiltinRegistry.theRegistry.register(myFlag); String NS = "http://ont.com/"; PrintUtil.registerPrefix("ns", NS); String rules = "[r1: (ns:a ns:p ns:b) <- (ns:a ns:p ns:a)] " + "[r2: (ns:a ns:p ns:b) <- flag()] " + "[rt: (?a ns:q ?b) <- (?a ns:p ?b)] "; Model m = ModelFactory.createDefaultModel(); Resource a = m.createResource(NS + "a"); Resource b = m.createResource(NS + "b"); Property p = m.createProperty(NS + "p"); Property q = m.createProperty(NS + "q"); m.add(a, p, a); GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules)); InfModel infModel = ModelFactory.createInfModel(reasoner, m); assertTrue( infModel.contains(a, q, b) ); assertTrue( ! myFlag.fired ); }
@Override public Builtin getImplementation(String functor) { Builtin that=builtins.get(functor); return that==null ? innerRegistry.getImplementation(functor) : that; }
/** * Test closure of grounded choice points */ public void testGroundClosure() { Flag myFlag = new Flag(); BuiltinRegistry.theRegistry.register(myFlag); String NS = "http://ont.com/"; PrintUtil.registerPrefix("ns", NS); String rules = "[r1: (ns:a ns:p ns:b) <- (ns:a ns:p ns:a)] " + "[r2: (ns:a ns:p ns:b) <- flag()] " + "[rt: (?a ns:q ?b) <- (?a ns:p ?b)] "; Model m = ModelFactory.createDefaultModel(); Resource a = m.createResource(NS + "a"); Resource b = m.createResource(NS + "b"); Property p = m.createProperty(NS + "p"); Property q = m.createProperty(NS + "q"); m.add(a, p, a); GenericRuleReasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules)); InfModel infModel = ModelFactory.createInfModel(reasoner, m); assertTrue( infModel.contains(a, q, b) ); assertTrue( ! myFlag.fired ); }
@Override public Builtin getImplementation(String functor) { Builtin that=builtins.get(functor); return that==null ? innerRegistry.getImplementation(functor) : that; }