/** * Minimal rule tester to check basic pattern match, forward style. */ 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)]"; InfGraph infgraph = createInfGraph(rules); 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), }); }
/** * 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)) }); }
/** * Minimal rule tester to check basic pattern match, forward style. */ 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)]"; InfGraph infgraph = createInfGraph(rules); 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), }); }
/** * 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 "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)) }); }
/** * 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), }); }
/** * 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)) }); }
try { i.next(); infgraph.add( new Triple(a, p, Util.makeIntNode(4)) ); i.next(); } catch (ConcurrentModificationException e) {
try { i.next(); infgraph.add( new Triple(a, p, Util.makeIntNode(4)) ); i.next(); } catch (ConcurrentModificationException e) {
Node b = NodeFactory.createURI("b"); Node c = NodeFactory.createURI("c"); infgraph.add(new Triple(a, RDFS.subClassOf.asNode(), b)); infgraph.add(new Triple(b, RDFS.subClassOf.asNode(), c)); TestUtil.assertIteratorValues(this, infgraph.find(b, RDFS.subClassOf.asNode(), null), Node q = NodeFactory.createURI("q"); Node r = NodeFactory.createURI("r"); infgraph.add(new Triple(p, RDFS.subPropertyOf.asNode(), q)); infgraph.add(new Triple(q, RDFS.subPropertyOf.asNode(), r)); TestUtil.assertIteratorValues(this, infgraph.find(q, RDFS.subPropertyOf.asNode(), null),