use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testMakeInstance.
/**
* Test access to makeInstance machinery from a Brule.
*/
public void testMakeInstance() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, ty, C1));
String rules = "[r1: (?x p ?t) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]" + "[r2: (?t rdf:type C2) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]";
InfGraph infgraph = createInfGraph(rules, data);
Node valueInstance = getValue(infgraph, a, p);
assertNotNull(valueInstance);
Node valueInstance2 = getValue(infgraph, a, p);
assertEquals(valueInstance, valueInstance2);
Node valueType = getValue(infgraph, valueInstance, RDF.type.asNode());
assertEquals(valueType, C2);
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testDuplicatesEC4.
/**
* Investigate a suspicious case in the OWL ruleset, is the backchainer
* returning duplicate values?
*/
public void testDuplicatesEC4() {
boolean prior = JenaParameters.enableFilteringOfHiddenInfNodes;
try {
JenaParameters.enableFilteringOfHiddenInfNodes = false;
Model premisesM = FileManager.get().loadModel("file:testing/wg/equivalentClass/premises004.rdf");
Graph data = premisesM.getGraph();
Reasoner reasoner = new OWLFBRuleReasoner(OWLFBRuleReasonerFactory.theInstance());
InfGraph infgraph = reasoner.bind(data);
Node rbPrototypeProp = NodeFactory.createURI(ReasonerVocabulary.RBNamespace + "prototype");
int count = 0;
for (Iterator<Triple> i = infgraph.find(null, rbPrototypeProp, null); i.hasNext(); ) {
Object t = i.next();
// System.out.println(" - " + PrintUtil.print(t));
count++;
}
// listFBGraph("direct databind case", (FBRuleInfGraph)infgraph);
assertEquals(5, count);
infgraph = reasoner.bindSchema(data).bind(Factory.createGraphMem());
count = 0;
for (Iterator<Triple> i = infgraph.find(null, rbPrototypeProp, null); i.hasNext(); ) {
Triple t = i.next();
// System.out.println(" - " + PrintUtil.print(t));
count++;
}
// listFBGraph("bindSchema case", (FBRuleInfGraph)infgraph);
assertEquals(5, count);
} finally {
JenaParameters.enableFilteringOfHiddenInfNodes = prior;
}
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testBackchain3.
/**
* Test restriction example
*/
public void testBackchain3() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, ty, r));
data.add(new Triple(a, p, b));
data.add(new Triple(r, sC, C1));
data.add(new Triple(C1, ty, OWL.Restriction.asNode()));
data.add(new Triple(C1, OWL.onProperty.asNode(), p));
data.add(new Triple(C1, OWL.allValuesFrom.asNode(), c));
String rules = "[rdfs9: (?a rdf:type ?y) <- (?x rdfs:subClassOf ?y) (?a rdf:type ?x)]" + "[restriction2: (?C owl:equivalentClass all(?P, ?D)) <- (?C rdf:type owl:Restriction), (?C owl:onProperty ?P), (?C owl:allValuesFrom ?D)]" + "[rs2: (?X rdf:type all(?P,?C)) <- (?D owl:equivalentClass all(?P,?C)), (?X rdf:type ?D)]" + "[rp4: (?Y rdf:type ?C) <- (?X rdf:type all(?P, ?C)), (?X ?P ?Y)]";
InfGraph infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(b, ty, c), new Object[] { new Triple(b, ty, c) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testRebind.
/**
* Test the rebind operation.
*/
public void testRebind() {
String rules = "[rule1: (?x p ?y) -> (?x q ?y)]";
Graph data = Factory.createGraphMem();
data.add(new Triple(n1, p, n2));
InfGraph infgraph = createInfGraph(rules, data);
TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, n2), new Triple(n1, q, n2) });
Graph ndata = Factory.createGraphMem();
ndata.add(new Triple(n1, p, n3));
infgraph.rebind(ndata);
TestUtil.assertIteratorValues(this, infgraph.find(n1, null, null), new Triple[] { new Triple(n1, p, n3), new Triple(n1, q, n3) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testHybridRDFS.
/**
* Test example hybrid rules for rdfs.
*/
public void testHybridRDFS() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(p, RDFS.range.asNode(), C1));
String rules = "[rdfs2: (?p rdfs:domain ?c) -> [(?x rdf:type ?c) <- (?x ?p ?y)] ]" + "[rdfs3: (?p rdfs:range ?c) -> [(?y rdf:type ?c) <- (?x ?p ?y)] ]" + "[rdfs5a: (?a rdfs:subPropertyOf ?b), (?b rdfs:subPropertyOf ?c) -> (?a rdfs:subPropertyOf ?c)]" + "[rdfs5b: (?a rdf:type rdf:Property) -> (?a rdfs:subPropertyOf ?a)]" + "[rdfs6: (?p rdfs:subPropertyOf ?q) -> [ (?a ?q ?b) <- (?a ?p ?b)] ]" + "[rdfs7: (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]" + "[rdfs8: (?a rdfs:subClassOf ?b), (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)]" + "[rdfs9: (?x rdfs:subClassOf ?y) -> [ (?a rdf:type ?y) <- (?a rdf:type ?x)] ]";
InfGraph infgraph = createInfGraph(rules, data);
// ((FBRuleInfGraph)infgraph).setTraceOn(true);
TestUtil.assertIteratorValues(this, infgraph.find(b, ty, null), new Object[] { new Triple(b, ty, C1) });
}
Aggregations