📄 testbackchainer.java
字号:
*/
public void testBaseRules2b() {
List rules = Rule.parseRules(
"[r1: (?a r ?b) <- (?a p ?b)]" +
"[r2: (?a r ?b) <- (?a q ?b)]" +
"[r3: (?a r ?b) <- (?a t ?c), (?c t ?b)]" +
"[r4: (?a t ?b) <- (?a s ?b)]"
);
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(b, q, c));
data.add(new Triple(a, s, b));
data.add(new Triple(b, s, d));
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(null, r, null),
new Object[] {
new Triple(a, r, b),
new Triple(b, r, c),
new Triple(a, r, d)
} );
}
/**
* Test basic rule operations - simple AND rule check with tabling.
*/
public void testBaseRules3() {
List 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 basic rule operations - simple AND rule check with tabling.
*/
public void testBaseRules3b() {
List 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(r, sP, t) );
data.add(new Triple(q, sP, s) );
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(r, sP, t),
new Triple(q, sP, s),
new Triple(p, sP, s),
new Triple(p, sP, r),
new Triple(p, sP, t),
new Triple(q, sP, t),
new Triple(p, sP, r)
} );
}
/**
* 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 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)
} );
}
/**
* Test basic rule operations - simple AND/OR with tabling.
*/
public void testBaseRulesXSB1() {
Graph data = Factory.createGraphMem();
data.add(new Triple(p, c, q));
data.add(new Triple(q, c, r));
data.add(new Triple(p, d, q));
data.add(new Triple(q, d, r));
List rules = Rule.parseRules(
"[r1: (?x a ?y) <- (?x c ?y)]" +
"[r2: (?x a ?y) <- (?x b ?z), (?z c ?y)]" +
"[r3: (?x b ?y) <- (?x d ?y)]" +
"[r4: (?x b ?y) <- (?x a ?z), (?z d ?y)]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(p, a, null),
new Object[] {
new Triple(p, a, q),
new Triple(p, a, r)
} );
}
/**
* Test basic functor usage.
*/
public void testFunctors1() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(a, q, c));
List rules = Rule.parseRules(
"[r1: (?x r f(?y,?z)) <- (?x p ?y), (?x q ?z)]" +
"[r2: (?x s ?y) <- (?x r f(?y, ?z))]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, s, null),
new Object[] {
new Triple(a, s, b)
} );
}
/**
* Test basic functor usage.
*/
public void testFunctors2() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(a, q, c));
data.add(new Triple(a, t, d));
List rules = Rule.parseRules(
"[r1: (?x r f(?y,?z)) <- (?x p ?y), (?x q ?z)]" +
"[r2: (?x s ?y) <- (?x r f(?y, ?z))]" +
"[r3: (?x r g(?y,?z)) <- (?x p ?y), (?x t ?z)]" +
"[r4: (?x s ?z) <- (?x r g(?y, ?z))]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, s, null),
new Object[] {
new Triple(a, s, b),
new Triple(a, s, d)
} );
}
/**
* Test basic functor usage.
*/
public void testFunctors3() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, s, b));
data.add(new Triple(a, t, c));
List rules = Rule.parseRules(
"[r1: (a q f(?x,?y)) <- (a s ?x), (a t ?y)]" +
"[r2: (a p ?x) <- (a q ?x)]" +
"[r3: (a r ?y) <- (a p f(?x, ?y))]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, r, null),
new Object[] {
new Triple(a, r, c)
} );
}
/**
* Test basic builtin usage.
*/
public void testBuiltin1() {
Graph data = Factory.createGraphMem();
List rules = Rule.parseRules(
"[a1: -> (a p 2) ]" +
"[a2: -> (a q 3) ]" +
"[r1: (?x r ?s) <- (?x p ?y), (?x q ?z), sum(?y, ?z, ?s)]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, r, null),
new Object[] {
new Triple(a, r, Util.makeIntNode(5))
} );
}
/**
* Test basic builtin usage.
*/
public void testBuiltin2() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(a, q, c));
List rules = Rule.parseRules(
"[r1: (?x r ?y ) <- bound(?x), (?x p ?y) ]" +
"[r2: (?x r ?y) <- unbound(?x), (?x q ?y)]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, r, null),
new Object[] {
new Triple(a, r, b)
} );
TestUtil.assertIteratorValues(this,
infgraph.find(null, r, null),
new Object[] {
new Triple(a, r, c)
} );
}
/**
* Test basic builtin usage.
*/
public void testBuiltin3() {
Graph data = Factory.createGraphMem();
List rules = Rule.parseRules(
"[r1: (a p b ) <- unbound(?x) ]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, null, null),
new Object[] {
new Triple(a, p, b)
} );
}
/**
* Test basic ground head patterns.
*/
public void testGroundHead() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, r, b));
List rules = Rule.parseRules(
"[r1: (a p b ) <- (a r b) ]"
);
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this,
infgraph.find(a, null, null),
new Object[] {
new Triple(a, p, b),
new Triple(a, r, b)
} );
}
// /**
// * Test multiheaded rule.
// */
// public void testMutliHead() {
// Graph data = new GraphMem();
// data.add(new Triple(a, p, b));
// data.add(new Triple(b, r, c));
// List rules = Rule.parseRules(
// "[r1: (?x s ?z), (?z s ?x) <- (?x p ?y) (?y r ?z) ]"
// );
// Reasoner reasoner = createReasoner(rules);
// InfGraph infgraph = reasoner.bind(data);
// TestUtil.assertIteratorValues(this,
// infgraph.find(null, s, null),
// new Object[] {
// new Triple(a, s, c),
// new Triple(c, s, a)
// } );
// }
/**
* Test rebind operation
*/
public void testRebind() {
List 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)
} );
Graph ndata = Factory.createGraphMem();
ndata.add(new Triple(a, p, d));
ndata.add(new Triple(d, p, b));
infgraph.rebind(ndata);
TestUtil.assertIteratorValues(this,
infgraph.find(null, r, null),
new Object[] {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -