/** 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())); } }
/** * 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); }
/** 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())); } }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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 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) }); }
/** * 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)) }); }
R1.addProperty(OWL.onProperty, p).addProperty(OWL.allValuesFrom, D); Reasoner reasoner = new BasicForwardRuleReasoner(ruleList); InfGraph infgraph = reasoner.bind(data.getGraph()); Model infModel = ModelFactory.createModelForGraph(infgraph);
List<Rule> ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(Factory.createGraphMem()); infgraph.setDerivationLogging(true); infgraph.add(new Triple(n1, p, n3));
/** * 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) }); }
/** * 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)) }); }
R1.addProperty(OWL.onProperty, p).addProperty(OWL.allValuesFrom, D); Reasoner reasoner = new BasicForwardRuleReasoner(ruleList); InfGraph infgraph = reasoner.bind(data.getGraph()); Model infModel = ModelFactory.createModelForGraph(infgraph);
List<Rule> ruleList = Rule.parseRules(rules); InfGraph infgraph = new BasicForwardRuleReasoner(ruleList).bind(Factory.createGraphMem()); infgraph.setDerivationLogging(true); infgraph.add(new Triple(n1, p, n3));
List<Rule> rules = new ArrayList<>(); BasicForwardRuleInfGraph inf = new BasicForwardRuleInfGraph( new BasicForwardRuleReasoner(rules), rules, null); TriplePattern p1 = new TriplePattern( new Node_RuleVariable("?a", 0),
/** * 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)) }); }
List<Rule> rules = new ArrayList<>(); BasicForwardRuleInfGraph inf = new BasicForwardRuleInfGraph( new BasicForwardRuleReasoner(rules), rules, null); TriplePattern p1 = new TriplePattern( new Node_RuleVariable("?a", 0),
/** * 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)) }); }