private static Graph make(int N) { Graph graph = Factory.createGraphMem(); for ( int i = 0 ; i < N ; i++ ) { Triple t = GraphTestBase.triple("a P 'x"+i+"'"); graph.add(t); } return graph ; }
/** * Test basic rule operations - simple AND rule */ public void testBaseRules1() { List<Rule> rules = Rule.parseRules("[r1: (?a r ?c) <- (?a p ?b),(?b p ?c)]"); Graph data = Factory.createGraphMem(); data.add(new Triple(a, p, b)); data.add(new Triple(b, p, c)); data.add(new Triple(b, p, d)); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); TestUtil.assertIteratorValues(this, infgraph.find(null, r, null), new Object[] { new Triple(a, r, c), new Triple(a, r, d) } ); }
@Test public void rdfjson_escapes() { Graph g = GraphFactory.createGraphMem(); Node s = NodeFactory.createBlankNode(); Node p = NodeFactory.createURI("http://predicate"); g.add(new Triple(s, p, NodeFactory.createLiteral("quote \" character"))); g.add(new Triple(s, p, NodeFactory.createLiteral("new \n\r lines"))); g.add(new Triple(s, p, NodeFactory.createLiteral("tab \t character"))); test(g); }
/** * 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) } ); }
/** * 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 public void testUpdateScript5() { DatasetGraph gStore = getEmptyDatasetGraph() ; script(gStore, "data-2.ru") ; Graph g = GraphFactory.createPlainGraph() ; Node b = org.apache.jena.graph.NodeFactory.createBlankNode() ; g.add(new Triple(s, p, b)) ; g.add(new Triple(b, q, v)) ; assertTrue(g.isIsomorphicWith(gStore.getDefaultGraph())) ; }
/** * Test basic rule operations - simple AND rule check with tabling. */ public void testBaseRules3() { List<Rule> rules = Rule.parseRules("[rule: (?a rdfs:subPropertyOf ?c) <- (?a rdfs:subPropertyOf ?b),(?b rdfs:subPropertyOf ?c)]"); Reasoner reasoner = createReasoner(rules); Graph data = Factory.createGraphMem(); data.add(new Triple(p, sP, q) ); data.add(new Triple(q, sP, r) ); data.add(new Triple(p, sP, s) ); data.add(new Triple(s, sP, t) ); data.add(new Triple(a, p, b) ); InfGraph infgraph = reasoner.bind(data); TestUtil.assertIteratorValues(this, infgraph.find(null, RDFS.subPropertyOf.asNode(), null), new Object[] { new Triple(p, sP, q), new Triple(q, sP, r), new Triple(p, sP, s), new Triple(s, sP, t), new Triple(p, sP, t), new Triple(p, sP, r) } ); }
/** * Test example hybrid rules for rdfs. */ public void testHybridRDFS2() { Graph data = Factory.createGraphMem(); data.add(new Triple(a, p, b)); data.add(new Triple(p, sP, r)); data.add(new Triple(r, RDFS.range.asNode(), C1)); String rules = "[rdfs3: (?p rdfs:range ?c) -> [(?y rdf:type ?c) <- (?x ?p ?y)] ]" + "[rdfs6: (?p rdfs:subPropertyOf ?q) -> [ (?a ?q ?b) <- (?a ?p ?b)] ]" ; InfGraph infgraph = createInfGraph(rules, data); // ((FBRuleInfGraph)infgraph).setTraceOn(true); TestUtil.assertIteratorValues(this, infgraph.find(b, ty, C1), new Object[] { new Triple(b, ty, C1) } ); }
/** * Internals of makeList. */ private static Node doMakeList(Node[] nodes, int next, Graph graph) { if (next < nodes.length) { Node listNode = NodeFactory.createBlankNode(); graph.add(new Triple(listNode, RDF.Nodes.first, nodes[next])); graph.add(new Triple(listNode, RDF.Nodes.rest, doMakeList(nodes, next+1, graph))); return listNode; } else { return RDF.Nodes.nil; } }
/** * 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 static Graph make(int N) { Graph graph = Factory.createGraphMem(); for ( int i = 0 ; i < N ; i++ ) { Triple t = GraphTestBase.triple("a P 'x"+i+"'"); graph.add(t); } return graph ; }
/** * Test basic rule operations - simple AND/OR with tabling. */ public void testBaseRules4() { Graph data = Factory.createGraphMem(); data.add(new Triple(a, r, b)); data.add(new Triple(b, r, c)); data.add(new Triple(b, r, b)); data.add(new Triple(b, r, d)); List<Rule> rules = Rule.parseRules( "[r1: (?x p ?y) <- (?x r ?y)]" + "[r2: (?x p ?z) <- (?x p ?y), (?y r ?z)]" ); Reasoner reasoner = createReasoner(rules); InfGraph infgraph = reasoner.bind(data); TestUtil.assertIteratorValues(this, infgraph.find(a, p, null), new Object[] { new Triple(a, p, b), new Triple(a, p, d), new Triple(a, p, c) } ); }
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(); }
/** * Generic test operation. * @param ruleSrc the source of the rules * @param tabled the predicates that should be tabled * @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, Node[] tabled, 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, tabled); TestUtil.assertIteratorValues(this, infgraph.find(query), results); }