/** * 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); }
/** * 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); }
/** * Precompute the implications of a schema Model. The statements in the graph * will be combined with the data when the final InfGraph is created. */ @Override public Reasoner bindSchema(Model tbox) throws ReasonerException { InfGraph graph = new BasicForwardRuleInfGraph(this, rules, null, tbox.getGraph()); return new BasicForwardRuleReasoner(rules, graph, factory); }
/** * Precompute the implications of a schema Model. The statements in the graph * will be combined with the data when the final InfGraph is created. */ @Override public Reasoner bindSchema(Model tbox) throws ReasonerException { InfGraph graph = new BasicForwardRuleInfGraph(this, rules, null, tbox.getGraph()); return new BasicForwardRuleReasoner(rules, graph, factory); }
/** 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())); } }
/** * Test size bug, used to blow up if size was called before any queries. */ public void testSize() { String rules = "[rule1: (?x p ?y) -> (?x q ?y)]"; List<Rule> ruleList = Rule.parseRules(rules); Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, n2)); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(data); assertEquals(infgraph.size(), 2); }
/** * Test size bug, used to blow up if size was called before any queries. */ public void testSize() { String rules = "[rule1: (?x p ?y) -> (?x q ?y)]"; List<Rule> ruleList = Rule.parseRules(rules); Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, n2)); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(data); assertEquals(infgraph.size(), 2); }
/** * The the minimal machinery for supporting builtins */ public void testBuiltins() { String rules = //"[testRule1: (n1 ?p ?a) -> print('rule1test', ?p, ?a)]" + "[r1: (n1 p ?x), addOne(?x, ?y) -> (n1 q ?y)]" + "[r2: (n1 p ?x), lessThan(?x, 3) -> (n2 q ?x)]" + "[axiom1: -> (n1 p 1)]" + "[axiom2: -> (n1 p 4)]" + ""; List<Rule> ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(Factory.createGraphMem()); TestUtil.assertIteratorValues(this, infgraph.find(n1, q, null), new Triple[] { new Triple(n1, q, Util.makeIntNode(2)), new Triple(n1, q, Util.makeIntNode(5)) }); TestUtil.assertIteratorValues(this, infgraph.find(n2, q, null), new Triple[] { new Triple(n2, q, Util.makeIntNode(1)) }); }
/** * The the minimal machinery for supporting builtins */ public void testBuiltins() { String rules = //"[testRule1: (n1 ?p ?a) -> print('rule1test', ?p, ?a)]" + "[r1: (n1 p ?x), addOne(?x, ?y) -> (n1 q ?y)]" + "[r2: (n1 p ?x), lessThan(?x, 3) -> (n2 q ?x)]" + "[axiom1: -> (n1 p 1)]" + "[axiom2: -> (n1 p 4)]" + ""; List<Rule> ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(Factory.createGraphMem()); TestUtil.assertIteratorValues(this, infgraph.find(n1, q, null), new Triple[] { new Triple(n1, q, Util.makeIntNode(2)), new Triple(n1, q, Util.makeIntNode(5)) }); TestUtil.assertIteratorValues(this, infgraph.find(n2, q, null), new Triple[] { new Triple(n2, q, Util.makeIntNode(1)) }); }
/** * 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 "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)) }); }
/** * 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)) }); }
/** * Test the rebind operation. */ public void testRebind() { String rules = "[rule1: (?x p ?y) -> (?x q ?y)]"; List<Rule> ruleList = Rule.parseRules(rules); Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, n2)); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(data); TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, n2), new Triple(n1, q, n2) }); Graph ndata = Factory.createGraphMem(); ndata.add(new Triple(n1, p, n3)); infgraph.rebind(ndata); TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, n3), new Triple(n1, q, n3) }); }
/** * Test the rebind operation. */ public void testRebind() { String rules = "[rule1: (?x p ?y) -> (?x q ?y)]"; List<Rule> ruleList = Rule.parseRules(rules); Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, n2)); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(data); TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, n2), new Triple(n1, q, n2) }); Graph ndata = Factory.createGraphMem(); ndata.add(new Triple(n1, p, n3)); infgraph.rebind(ndata); TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, n3), new Triple(n1, q, n3) }); }
List<Rule> ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(Factory.createGraphMem()); TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), new Triple[] {
/** * Minimal rule tester to check basic pattern match */ public void testRuleMatcher() { String rules = "[r1: (?a p ?b), (?b q ?c) -> (?a, q, ?c)]" + "[r2: (?a p ?b), (?b p ?c) -> (?a, p, ?c)]" + "[r3: (?a p ?a), (n1 p ?c), (n1, p, ?a) -> (?a, p, ?c)]" + "[r4: (n4 ?p ?a) -> (n4, ?a, ?p)]"; List<Rule> ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(Factory.createGraphMem()); infgraph.add(new Triple(n1, p, n2)); infgraph.add(new Triple(n2, p, n3)); infgraph.add(new Triple(n2, q, n3)); infgraph.add(new Triple(n4, p, n4)); TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), new Triple[] { new Triple(n1, p, n2), new Triple(n2, p, n3), new Triple(n2, q, n3), new Triple(n4, p, n4), new Triple(n1, p, n3), new Triple(n1, q, n3), new Triple(n4, n4, p), }); }
/** * Minimal rule tester to check basic pattern match */ public void testRuleMatcher() { String rules = "[r1: (?a p ?b), (?b q ?c) -> (?a, q, ?c)]" + "[r2: (?a p ?b), (?b p ?c) -> (?a, p, ?c)]" + "[r3: (?a p ?a), (n1 p ?c), (n1, p, ?a) -> (?a, p, ?c)]" + "[r4: (n4 ?p ?a) -> (n4, ?a, ?p)]"; List<Rule> ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(Factory.createGraphMem()); infgraph.add(new Triple(n1, p, n2)); infgraph.add(new Triple(n2, p, n3)); infgraph.add(new Triple(n2, q, n3)); infgraph.add(new Triple(n4, p, n4)); TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), new Triple[] { new Triple(n1, p, n2), new Triple(n2, p, n3), new Triple(n2, q, n3), new Triple(n4, p, n4), new Triple(n1, p, n3), new Triple(n1, q, n3), new Triple(n4, n4, p), }); }
/** * Test schema partial binding machinery */ public void testSchemaBinding() { String rules = "[testRule1: (n1 p ?a) -> (n2, p, ?a)]" + "[testRule2: (n1 q ?a) -> (n2, q, ?a)]" + "[testRule3: (n2 p ?a), (n2 q ?a) -> (res p ?a)]"; List<Rule> ruleList = Rule.parseRules(rules); Graph schema = Factory.createGraphMem(); schema.add(new Triple(n1, p, n3)); Graph data = Factory.createGraphMem(); data.add(new Triple(n1, q, n4)); data.add(new Triple(n1, q, n3)); Reasoner reasoner = new BasicForwardRuleReasoner(ruleList); Reasoner boundReasoner = reasoner.bindSchema(schema); InfGraph infgraph = boundReasoner.bind(data); TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), new Triple[] { new Triple(n1, p, n3), new Triple(n2, p, n3), new Triple(n1, q, n4), new Triple(n2, q, n4), new Triple(n1, q, n3), new Triple(n2, q, n3), new Triple(res, p, n3) }); }