use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testRegexNulls.
/**
* Test regex handling of null groups
*/
public void testRegexNulls() {
String rules = "[r2: (?x p ?y) regex(?y, '((Boys)|(Girls))(.*)', ?m1, ?m2, ?m3, ?m4) -> (?x q ?m2) (?x r ?m3) (?x s ?m4) ] \n" + "";
Graph data = Factory.createGraphMem();
data.add(new Triple(n1, p, NodeFactory.createLiteral("Girls44")));
InfGraph infgraph = createInfGraph(rules, data);
infgraph.prepare();
TestUtil.assertIteratorValues(this, infgraph.getDeductionsGraph().find(null, null, null), new Triple[] { new Triple(n1, q, NodeFactory.createLiteral("")), new Triple(n1, r, NodeFactory.createLiteral("Girls")), new Triple(n1, s, NodeFactory.createLiteral("44")) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testRemoveBuiltin.
/**
* The the "remove" builtin
*/
public void testRemoveBuiltin() {
String rules = "[rule1: (?x p ?y), (?x q ?y) -> remove(0)]" + "";
InfGraph infgraph = createInfGraph(rules);
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)) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testHybridRDFS2.
/**
* Test example hybrid rules for rdfs.
*/
public void testHybridRDFS2() {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, p, b));
data.add(new Triple(p, sP, r));
data.add(new Triple(r, RDFS.range.asNode(), C1));
String rules = "[rdfs3: (?p rdfs:range ?c) -> [(?y rdf:type ?c) <- (?x ?p ?y)] ]" + "[rdfs6: (?p rdfs:subPropertyOf ?q) -> [ (?a ?q ?b) <- (?a ?p ?b)] ]";
InfGraph infgraph = createInfGraph(rules, data);
// ((FBRuleInfGraph)infgraph).setTraceOn(true);
TestUtil.assertIteratorValues(this, infgraph.find(b, ty, C1), new Object[] { new Triple(b, ty, C1) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class TestFBRules method testSchemaBinding.
/**
* Test schmea partial binding machinery, forward subset.
*/
public void testSchemaBinding() {
String rules = "[testRule1: (n1 p ?a) -> (n2, p, ?a)]" + "[testRule2: (n1 q ?a) -> (n2, q, ?a)]" + "[testRule3: (n2 p ?a), (n2 q ?a) -> (res p ?a)]" + "[testBRule4: (n3 p ?a) <- (n1, p, ?a)]";
List<Rule> ruleList = Rule.parseRules(rules);
Graph schema = Factory.createGraphMem();
schema.add(new Triple(n1, p, n3));
Graph data = Factory.createGraphMem();
data.add(new Triple(n1, q, n4));
data.add(new Triple(n1, q, n3));
Reasoner reasoner = createReasoner(ruleList);
Reasoner boundReasoner = reasoner.bindSchema(schema);
InfGraph infgraph = boundReasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), new Triple[] { new Triple(n1, p, n3), new Triple(n2, p, n3), new Triple(n3, p, n3), new Triple(n1, q, n4), new Triple(n2, q, n4), new Triple(n1, q, n3), new Triple(n2, q, n3), new Triple(res, p, n3) });
}
use of org.apache.jena.reasoner.InfGraph in project jena by apache.
the class GenericRuleReasoner method bind.
/**
* Attach the reasoner to a set of RDF data to process.
* The reasoner may already have been bound to specific rules or ontology
* axioms (encoded in RDF) through earlier bindRuleset calls.
*
* @param data the RDF data to be processed, some reasoners may restrict
* the range of RDF which is legal here (e.g. syntactic restrictions in OWL).
* @return an inference graph through which the data+reasoner can be queried.
* @throws ReasonerException if the data is ill-formed according to the
* constraints imposed by this reasoner.
*/
@Override
public InfGraph bind(Graph data) throws ReasonerException {
Graph schemaArg = schemaGraph == null ? getPreload() : schemaGraph;
InfGraph graph = null;
if (mode == FORWARD) {
graph = new BasicForwardRuleInfGraph(this, rules, schemaArg);
((BasicForwardRuleInfGraph) graph).setTraceOn(traceOn);
} else if (mode == FORWARD_RETE) {
graph = new RETERuleInfGraph(this, rules, schemaArg);
((BasicForwardRuleInfGraph) graph).setTraceOn(traceOn);
((BasicForwardRuleInfGraph) graph).setFunctorFiltering(filterFunctors);
} else if (mode == BACKWARD) {
graph = new LPBackwardRuleInfGraph(this, getBruleStore(), data, schemaArg);
((LPBackwardRuleInfGraph) graph).setTraceOn(traceOn);
} else {
List<Rule> ruleSet = ((FBRuleInfGraph) schemaArg).getRules();
FBRuleInfGraph fbgraph = new FBRuleInfGraph(this, ruleSet, schemaArg);
graph = fbgraph;
if (enableTGCCaching)
fbgraph.setUseTGCCache();
fbgraph.setTraceOn(traceOn);
fbgraph.setFunctorFiltering(filterFunctors);
if (preprocessorHooks != null) {
for (RulePreprocessHook preprocessorHook : preprocessorHooks) {
fbgraph.addPreprocessingHook(preprocessorHook);
}
}
}
graph.setDerivationLogging(recordDerivations);
graph.rebind(data);
return graph;
}
Aggregations