use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testMakeInstanceBug.
/**
* Test case for makeInstance which failed during development.
*/
public void testMakeInstanceBug() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, ty, r));
data.add(new Triple(r, sC, Functor.makeFunctorNode("some", new Node[] { p, C1 })));
String rules = "[some1: (?C rdfs:subClassOf some(?P, ?D)) ->" + "[some1b: (?X ?P ?T) <- (?X rdf:type ?C), unbound(?T), noValue(?X, ?P), makeInstance(?X, ?P, ?D, ?T) ]" + "[some1b2: (?T rdf:type ?D) <- (?X rdf:type ?C), bound(?T), makeInstance(?X, ?P, ?D, ?T) ]" + "]";
InfGraph infgraph = createInfGraph(rules, data);
Node valueInstance = getValue(infgraph, a, p);
assertNotNull(valueInstance);
Node valueType = getValue(infgraph, valueInstance, ty);
assertEquals(valueType, C1);
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testEmbeddedFunctors.
/**
* Test functor handling
*/
public void testEmbeddedFunctors() {
String rules = "(?C owl:onProperty ?P), (?C owl:allValuesFrom ?D) -> (?C rb:restriction all(?P, ?D))." + "(?C rb:restriction all(eg:p, eg:D)) -> (?C rb:restriction 'allOK')." + "[ -> (eg:foo eg:prop functor(eg:bar, 1)) ]" + "[ (?x eg:prop functor(eg:bar, ?v)) -> (?x eg:propbar ?v) ]" + "[ (?x eg:prop functor(?v, ?*)) -> (?x eg:propfunc ?v) ]" + "";
Model data = ModelFactory.createDefaultModel();
Resource R1 = data.createResource(PrintUtil.egNS + "R1");
Resource D = data.createResource(PrintUtil.egNS + "D");
Property p = data.createProperty(PrintUtil.egNS, "p");
Property propbar = data.createProperty(PrintUtil.egNS, "propbar");
Property rbr = data.createProperty(ReasonerVocabulary.RBNamespace, "restriction");
R1.addProperty(OWL.onProperty, p).addProperty(OWL.allValuesFrom, D);
InfGraph infgraph = createInfGraph(rules, data.getGraph());
Model infModel = ModelFactory.createModelForGraph(infgraph);
Resource foo = infModel.createResource(PrintUtil.egNS + "foo");
RDFNode flit = infModel.getResource(R1.getURI()).getRequiredProperty(rbr).getObject();
assertNotNull(flit);
assertEquals(flit.toString(), "allOK");
// assertTrue(flit instanceof Literal);
// Functor func = (Functor)((Literal)flit).getValue();
// assertEquals("all", func.getName());
// assertEquals(p.getNode(), func.getArgs()[0]);
// assertEquals(D.getNode(), func.getArgs()[1]);
Literal one = (Literal) foo.getRequiredProperty(propbar).getObject();
assertEquals(new Integer(1), one.getValue());
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testBaseRulesXSB1.
/**
* 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<Rule> 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) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testBaseRules4.
/**
* 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) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestBackchainer method testClose.
/**
* Test close and halt operation.
*/
public void testClose() {
Graph data = Factory.createGraphMem();
data.add(new Triple(p, sP, q));
data.add(new Triple(q, sP, r));
data.add(new Triple(C1, sC, C2));
data.add(new Triple(C2, sC, C3));
data.add(new Triple(a, ty, C1));
data.add(new Triple(ty, RDFS.range.asNode(), RDFS.Class.asNode()));
List<Rule> rules = Rule.parseRules("[rdfs8: (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)]" + "[rdfs9: (?x rdfs:subClassOf ?y), (?a rdf:type ?x) -> (?a rdf:type ?y)]" + // "[-> (rdf:type rdfs:range rdfs:Class)]" +
"[rdfs3: (?x ?p ?y), (?p rdfs:range ?c) -> (?y rdf:type ?c)]" + "[rdfs7: (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]");
Reasoner reasoner = createReasoner(rules);
InfGraph infgraph = reasoner.bind(data);
// Get just one result
ExtendedIterator<Triple> it = infgraph.find(a, ty, null);
Triple result = it.next();
assertEquals(result.getSubject(), a);
assertEquals(result.getPredicate(), ty);
it.close();
// Make sure if we start again we get the full listing.
TestUtil.assertIteratorValues(this, infgraph.find(a, ty, null), new Object[] { new Triple(a, ty, C1), new Triple(a, ty, C2), new Triple(a, ty, C3) });
}
Aggregations