"";
Graph data = Factory.createGraphMem();
data.add(new Triple(n1, q, Util.makeIntNode(2)) );
data.add(new Triple(n2, q, Util.makeIntNode(2)) );
data.add(new Triple(n3, q, Util.makeIntNode(3)) );
InfGraph infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(n1, null, n2),
new Triple[] {
new Triple(n1, eq, n2),
new Triple(n1, le, n2),
new Triple(n1, ge, n2),
});
TestUtil.assertIteratorValues(this, infgraph.find(n1, null, n3),
new Triple[] {
new Triple(n1, ne, n3),
new Triple(n1, lt, n3),
new Triple(n1, le, n3),
});
TestUtil.assertIteratorValues(this, infgraph.find(n3, null, n1),
new Triple[] {
new Triple(n3, ne, n1),
new Triple(n3, gt, n1),
new Triple(n3, ge, n1),
});
// Floating point comparisons
data = Factory.createGraphMem();
data.add(new Triple(n1, q, Util.makeIntNode(2)) );
data.add(new Triple(n2, q, Util.makeDoubleNode(2.2)) );
data.add(new Triple(n3, q, Util.makeDoubleNode(2.3)) );
infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(n1, null, n2),
new Triple[] {
new Triple(n1, ne, n2),
new Triple(n1, le, n2),
new Triple(n1, lt, n2),
});
TestUtil.assertIteratorValues(this, infgraph.find(n2, null, n3),
new Triple[] {
new Triple(n2, ne, n3),
new Triple(n2, le, n3),
new Triple(n2, lt, n3),
});
// XSD timeDate point comparisons
data = Factory.createGraphMem();
XSDDatatype dt = new XSDDatatype("dateTime");
data.add(new Triple(n1, q, NodeFactory.createLiteral("2000-03-04T20:00:00Z", "", XSDDatatype.XSDdateTime)));
data.add(new Triple(n2, q, NodeFactory.createLiteral("2001-03-04T20:00:00Z", "", XSDDatatype.XSDdateTime)));
data.add(new Triple(n3, q, NodeFactory.createLiteral("2002-03-04T20:00:00Z", "", XSDDatatype.XSDdateTime)));
infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(n1, null, n2),
new Triple[] {
new Triple(n1, ne, n2),
new Triple(n1, le, n2),
new Triple(n1, lt, n2),
});
TestUtil.assertIteratorValues(this, infgraph.find(n2, null, n3),
new Triple[] {
new Triple(n2, ne, n3),
new Triple(n2, le, n3),
new Triple(n2, lt, n3),
});
TestUtil.assertIteratorValues(this, infgraph.find(n2, null, n1),
new Triple[] {
new Triple(n2, ne, n1),
new Triple(n2, ge, n1),
new Triple(n2, gt, n1),
});
TestUtil.assertIteratorValues(this, infgraph.find(n3, null, n2),
new Triple[] {
new Triple(n3, ne, n2),
new Triple(n3, ge, n2),
new Triple(n3, gt, n2),
});
// Support for now(?x)
rules = "[r1: now(?x) -> (a p ?x)]";
infgraph = createInfGraph(rules);
infgraph.prepare();
Graph result = infgraph.getDeductionsGraph();
assertEquals(1, result.size());
Triple tr = result.find(null, null, null).next();
Node nowN = tr.getObject();
assertTrue(nowN.isLiteral());
Object nowO = nowN.getLiteralValue();
assertTrue(nowO instanceof XSDDateTime);
// Arithmetic
rules =
"[r1: (?x p ?a), (?x q ?b), sum(?a, ?b, ?c) -> (?x s ?c)]" +
"[r2: (?x p ?a), (?x q ?b), product(?a, ?b, ?c) -> (?x t ?c)]" +
"[r3: (?x p ?a), (?x q ?b), difference(?b, ?a, ?c) -> (?x u ?c)]" +
"[r4: (?x p ?a), (?x q ?b), quotient(?b, ?a, ?c) -> (?x v ?c)]" +
"[r4: (?x p ?a), (?x q ?b), min(?b, ?a, ?c) -> (?x r ?c)]" +
"[r4: (?x p ?a), (?x q ?b), max(?b, ?a, ?c) -> (?x x ?c)]" +
"";
data = Factory.createGraphMem();
data.add(new Triple(n1, p, Util.makeIntNode(3)) );
data.add(new Triple(n1, q, Util.makeIntNode(5)) );
infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null),
new Triple[] {
new Triple(n1, p, Util.makeIntNode(3)),
new Triple(n1, q, Util.makeIntNode(5)),
new Triple(n1, s, Util.makeIntNode(8)),
new Triple(n1, t, Util.makeIntNode(15)),
new Triple(n1, u, Util.makeIntNode(2)),
new Triple(n1, v, Util.makeIntNode(1)),
new Triple(n1, r, Util.makeIntNode(3)),
new Triple(n1, x, Util.makeIntNode(5)),
});
// Note type checking
rules =
"[r1: (?x p ?y), isLiteral(?y) -> (?x s 'literal')]" +
"[r1: (?x p ?y), notLiteral(?y) -> (?x s 'notLiteral')]" +
"[r1: (?x p ?y), isBNode(?y) -> (?x s 'bNode')]" +
"[r1: (?x p ?y), notBNode(?y) -> (?x s 'notBNode')]" +
"";
data = Factory.createGraphMem();
data.add(new Triple(n1, p, Util.makeIntNode(3)) );
data.add(new Triple(n2, p, res));
data.add(new Triple(n3, p, NodeFactory.createAnon()));
infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(n1, s, null),
new Triple[] {
new Triple(n1, s, NodeFactory.createLiteral("literal", "", null)),
new Triple(n1, s, NodeFactory.createLiteral("notBNode", "", null)),
});
TestUtil.assertIteratorValues(this, infgraph.find(n2, s, null),
new Triple[] {
new Triple(n2, s, NodeFactory.createLiteral("notLiteral", "", null)),
new Triple(n2, s, NodeFactory.createLiteral("notBNode", "", null)),
});
TestUtil.assertIteratorValues(this, infgraph.find(n3, s, null),
new Triple[] {
new Triple(n3, s, NodeFactory.createLiteral("notLiteral", "", null)),
new Triple(n3, s, NodeFactory.createLiteral("bNode", "", null)),
});
// Data type checking
rules =
"[r1: (?x p ?y), isDType(?y, rdfs:Literal) -> (?x s 'isLiteral')]" +
"[r1: (?x p ?y), isDType(?y, http://www.w3.org/2001/XMLSchema#int) -> (?x s 'isXSDInt')]" +
"[r1: (?x p ?y), isDType(?y, http://www.w3.org/2001/XMLSchema#string) -> (?x s 'isXSDString')]" +
"[r1: (?x p ?y), notDType(?y, rdfs:Literal) -> (?x s 'notLiteral')]" +
"[r1: (?x p ?y), notDType(?y, http://www.w3.org/2001/XMLSchema#int) -> (?x s 'notXSDInt')]" +
"[r1: (?x p ?y), notDType(?y, http://www.w3.org/2001/XMLSchema#string) -> (?x s 'notXSDString')]" +
"";
data = Factory.createGraphMem();
data.add(new Triple(n1, p, Util.makeIntNode(3)) );
data.add(new Triple(n2, p, NodeFactory.createLiteral("foo", "", null)) );
data.add(new Triple(n3, p, NodeFactory.createLiteral("foo", "", XSDDatatype.XSDstring)) );
data.add(new Triple(n4, p, n4));
data.add(new Triple(n5, p, NodeFactory.createLiteral("-1", "", XSDDatatype.XSDnonNegativeInteger)) );
infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(null, s, null),
new Triple[] {
new Triple(n1, s, NodeFactory.createLiteral("isLiteral", "", null)),
new Triple(n1, s, NodeFactory.createLiteral("isXSDInt", "", null)),
new Triple(n1, s, NodeFactory.createLiteral("notXSDString", "", null)),
new Triple(n2, s, NodeFactory.createLiteral("isLiteral", "", null)),
new Triple(n2, s, NodeFactory.createLiteral("notXSDInt", "", null)),
new Triple(n2, s, NodeFactory.createLiteral("isXSDString", "", null)),
new Triple(n3, s, NodeFactory.createLiteral("isLiteral", "", null)),
new Triple(n3, s, NodeFactory.createLiteral("notXSDInt", "", null)),
new Triple(n3, s, NodeFactory.createLiteral("isXSDString", "", null)),
new Triple(n4, s, NodeFactory.createLiteral("notLiteral", "", null)),
new Triple(n4, s, NodeFactory.createLiteral("notXSDInt", "", null)),
new Triple(n4, s, NodeFactory.createLiteral("notXSDString", "", null)),
new Triple(n5, s, NodeFactory.createLiteral("notLiteral", "", null)),
new Triple(n5, s, NodeFactory.createLiteral("notXSDInt", "", null)),
new Triple(n5, s, NodeFactory.createLiteral("notXSDString", "", null)),
});
// Literal counting
rules = "[r1: (?x p ?y), countLiteralValues(?x, p, ?c) -> (?x s ?c)]";
data = Factory.createGraphMem();
data.add(new Triple(n1, p, Util.makeIntNode(2)) );
data.add(new Triple(n1, p, Util.makeIntNode(2)) );
data.add(new Triple(n1, p, Util.makeIntNode(3)) );
data.add(new Triple(n1, p, n2) );
infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(n1, s, null),
new Triple[] {
new Triple(n1, s, Util.makeIntNode(2)),
});
// Map list operation
rules = "[r1: (n1 p ?l) -> listMapAsSubject(?l, q, C1)]" +
"[r2: (n1 p ?l) -> listMapAsObject ( a, q, ?l)]";
data = Factory.createGraphMem();
data.add(new Triple(n1, p, Util.makeList(new Node[]{b, c, d}, data) ));
infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(null, q, null),
new Triple[] {
new Triple(b, q, C1),
new Triple(c, q, C1),
new Triple(d, q, C1),
new Triple(a, q, b),