/** Run a single test */ public void run() { BasicForwardRuleReasoner reasoner = new BasicForwardRuleReasoner(ruleset); InfGraph result = reasoner.bind(Factory.createGraphMem()); System.out.println("Final graph state"); for (Iterator<Triple> i = result.find(null, null, null); i.hasNext(); ) { System.out.println(PrintUtil.print(i.next())); } }
/** Run a single test */ public void run() { BasicForwardRuleReasoner reasoner = new BasicForwardRuleReasoner(ruleset); InfGraph result = reasoner.bind(Factory.createGraphMem()); System.out.println("Final graph state"); for (Iterator<Triple> i = result.find(null, null, null); i.hasNext(); ) { System.out.println(PrintUtil.print(i.next())); } }
private Node getSkolem(Node x) { String rules = "[r1: (?n p ?x) makeSkolem(?s ?x) -> (?n s ?s)]"; Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, x)); InfGraph infgraph = createInfGraph(rules, data); return infgraph.find(n1, s, Node.ANY).next().getObject(); }
/** * Generic test operation. * @param ruleSrc the source of the rules * @param triples a set of triples to insert in the graph before the query * @param query the Triple to search for * @param results the array of expected results */ private void doTest(String ruleSrc, Triple[] triples, Triple query, Object[] results) { List<Rule> rules = Rule.parseRules(ruleSrc); Graph data = Factory.createGraphMem(); for ( Triple triple : triples ) { data.add( triple ); } InfGraph infgraph = makeInfGraph(rules, data); TestUtil.assertIteratorValues(this, infgraph.find(query), results); }
private Node getSkolem(Node x) { String rules = "[r1: (?n p ?x) makeSkolem(?s ?x) -> (?n s ?s)]"; Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, x)); InfGraph infgraph = createInfGraph(rules, data); return infgraph.find(n1, s, Node.ANY).next().getObject(); }
/** * Generic test operation. * @param ruleSrc the source of the rules * @param triples a set of triples to insert in the graph before the query * @param query the Triple to search for * @param results the array of expected results */ private void doTest(String ruleSrc, Triple[] triples, Triple query, Object[] results) { List<Rule> rules = Rule.parseRules(ruleSrc); Graph data = Factory.createGraphMem(); for ( Triple triple : triples ) { data.add( triple ); } InfGraph infgraph = makeInfGraph(rules, data); TestUtil.assertIteratorValues(this, infgraph.find(query), results); }
/** * Test basic builtin usage. */ public void testBuiltin3() { Graph data = Factory.createGraphMem(); List<Rule> rules = Rule.parseRules( "[r1: (a p b ) <- unbound(?x) ]" ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); TestUtil.assertIteratorValues(this, infgraph.find(a, null, null), new Object[] { new Triple(a, p, b) } ); }
/** * Test basic builtin usage. */ public void testBuiltin3() { Graph data = Factory.createGraphMem(); List<Rule> rules = Rule.parseRules( "[r1: (a p b ) <- unbound(?x) ]" ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); TestUtil.assertIteratorValues(this, infgraph.find(a, null, null), new Object[] { new Triple(a, p, b) } ); }
private Node getSkolem(Node x, Node y) { String rules = "[r1: (?n p ?x) (?n q ?y) makeSkolem(?s ?x ?y) -> (?n s ?s)]"; Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, x)); data.add(new Triple(n1, q, y)); InfGraph infgraph = createInfGraph(rules, data); return infgraph.find(n1, s, Node.ANY).next().getObject(); }
private Node getSkolem(Node x, Node y) { String rules = "[r1: (?n p ?x) (?n q ?y) makeSkolem(?s ?x ?y) -> (?n s ?s)]"; Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, x)); data.add(new Triple(n1, q, y)); InfGraph infgraph = createInfGraph(rules, data); return infgraph.find(n1, s, Node.ANY).next().getObject(); }
/** * Minimal rule tester to check basic pattern match, forward style. */ public void testForward() { Graph test = Factory.createGraphMem(); test.add(new Triple(a, p, b)); test.add(new Triple(b, p, c)); GenericRuleReasoner reasoner = (GenericRuleReasoner)GenericRuleReasonerFactory.theInstance().create(null); reasoner.setRules(ruleList); reasoner.setMode(GenericRuleReasoner.FORWARD); // Check data bind version InfGraph infgraph = reasoner.bind(test); TestUtil.assertIteratorValues(this, infgraph.find(null, p, null), ans); // Check schema bind version infgraph = reasoner.bindSchema(test).bind(Factory.createGraphMem()); TestUtil.assertIteratorValues(this, infgraph.find(null, p, null), ans); }
/** * Report of NPE during processing on an ontology with a faulty intersection list, * from Hugh Winkler. */ public void testIntersectionNPE() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/bad-intersection.owl"); boolean foundBadList = false; try { InfGraph infgraph = ReasonerRegistry.getOWLReasoner().bind(base.getGraph()); ExtendedIterator<Triple> ci = infgraph.find(null, RDF.Nodes.type, OWL.Class.asNode()); ci.close(); } catch (ReasonerException e) { foundBadList = true; } assertTrue("Correctly detected the illegal list", foundBadList); }
/** * Report of NPE during processing on an ontology with a faulty intersection list, * from Hugh Winkler. */ public void testIntersectionNPE() { Model base = ModelFactory.createDefaultModel(); base.read("file:testing/reasoners/bugs/bad-intersection.owl"); boolean foundBadList = false; try { InfGraph infgraph = ReasonerRegistry.getOWLReasoner().bind(base.getGraph()); ExtendedIterator<Triple> ci = infgraph.find(null, RDF.Nodes.type, OWL.Class.asNode()); ci.close(); } catch (ReasonerException e) { foundBadList = true; } assertTrue("Correctly detected the illegal list", foundBadList); }
/** * Test example hybrid rule. */ public void testHybrid1() { Graph data = Factory.createGraphMem(); data.add(new Triple(a, p, b)); data.add(new Triple(p, ty, s)); String rules = "[r1: (?p rdf:type s) -> [r1b: (?x ?p ?y) <- (?y ?p ?x)]]"; InfGraph infgraph = createInfGraph(rules, data); TestUtil.assertIteratorValues(this, infgraph.find(null, p, null), new Object[] { new Triple(a, p, b), new Triple(b, p, a) } ); }
/** * Test example hybrid rule. */ public void testHybrid1() { Graph data = Factory.createGraphMem(); data.add(new Triple(a, p, b)); data.add(new Triple(p, ty, s)); String rules = "[r1: (?p rdf:type s) -> [r1b: (?x ?p ?y) <- (?y ?p ?x)]]"; InfGraph infgraph = createInfGraph(rules, data); TestUtil.assertIteratorValues(this, infgraph.find(null, p, null), new Object[] { new Triple(a, p, b), new Triple(b, p, a) } ); }
/** * Test clause order is right */ public void testClauseOrder() { List<Rule> rules = Rule.parseRules( "[r1: (?x r C1) <- (?x p b)]" + "[r1: (?x r C2) <- (?x p b)]" + "[r2: (?x r C3) <- (?x r C3) (?x p b)]"); Graph data = Factory.createGraphMem(); data.add(new Triple(a, p, b)); InfGraph infgraph = makeInfGraph(rules, data); ExtendedIterator<Triple> i = infgraph.find(Node.ANY, r, Node.ANY); assertTrue(i.hasNext()); assertEquals(i.next(), new Triple(a, r, C1)); i.close(); }
/** * Test clause order is right */ public void testClauseOrder() { List<Rule> rules = Rule.parseRules( "[r1: (?x r C1) <- (?x p b)]" + "[r1: (?x r C2) <- (?x p b)]" + "[r2: (?x r C3) <- (?x r C3) (?x p b)]"); Graph data = Factory.createGraphMem(); data.add(new Triple(a, p, b)); InfGraph infgraph = makeInfGraph(rules, data); ExtendedIterator<Triple> i = infgraph.find(Node.ANY, r, Node.ANY); assertTrue(i.hasNext()); assertEquals(i.next(), new Triple(a, r, C1)); i.close(); }
/** * The the "remove" builtin */ public void testRemoveBuiltin() { String rules = "[rule1: (?x p ?y), (?x q ?y) -> remove(0)]" + ""; InfGraph infgraph = createInfGraph(rules); infgraph.add(new Triple(n1, p, Util.makeIntNode(1))); infgraph.add(new Triple(n1, p, Util.makeIntNode(2))); infgraph.add(new Triple(n1, q, Util.makeIntNode(2))); TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, Util.makeIntNode(1)), new Triple(n1, q, Util.makeIntNode(2)) }); }
/** * The the "drop" builtin */ public void testDropBuiltin() { String rules = "[rule1: (?x p ?y) -> drop(0)]" + ""; List<Rule> ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(Factory.createGraphMem()); infgraph.add(new Triple(n1, p, Util.makeIntNode(1))); infgraph.add(new Triple(n1, p, Util.makeIntNode(2))); infgraph.add(new Triple(n1, q, Util.makeIntNode(2))); TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, q, Util.makeIntNode(2)) }); }
/** * The the "remove" builtin */ public void testRemoveBuiltin() { String rules = "[rule1: (?x p ?y), (?x q ?y) -> remove(0)]" + ""; List<Rule> ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(Factory.createGraphMem()); infgraph.add(new Triple(n1, p, Util.makeIntNode(1))); infgraph.add(new Triple(n1, p, Util.makeIntNode(2))); infgraph.add(new Triple(n1, q, Util.makeIntNode(2))); TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, Util.makeIntNode(1)), new Triple(n1, q, Util.makeIntNode(2)) }); }