/** * 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; } }
private void checkCreateNewList(final RDFNode value, final Resource tail) throws AddDeniedException, AuthenticationRequiredException { checkCreate(new Triple(SecurityEvaluator.FUTURE, listFirst().asNode(), value.asNode())); checkCreate(new Triple(SecurityEvaluator.FUTURE, listRest().asNode(), tail.asNode())); }
/** * 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) } ); }
@Override public SecuredBag getBag(final String uri) throws ReadDeniedException, AuthenticationRequiredException { checkRead(); checkRead(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(), RDF.Bag.asNode())); return SecuredBagImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().getBag(uri)); }
/** * 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) } ); }
/** * 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 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) } ); }
@Override public SecuredSeq getSeq(final String uri) throws ReadDeniedException, AuthenticationRequiredException { checkRead(); checkRead(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(), RDF.Seq.asNode())); return SecuredSeqImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().getSeq(uri)); }
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(); }
/** * 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 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) } ); }
@Override public SecuredAlt createAlt(final String uri) throws UpdateDeniedException, AddDeniedException, AuthenticationRequiredException { checkUpdate(); checkCreate(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(), RDF.Alt.asNode())); return SecuredAltImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().createAlt(uri)); }
@Override public SecuredModel add(final Resource s, final Property p, final String lex, final RDFDatatype datatype) throws UpdateDeniedException, AddDeniedException, AuthenticationRequiredException { checkUpdate(); checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createLiteral(lex, datatype))); holder.getBaseItem().add(s, p, lex, datatype); return holder.getSecuredItem(); }