use of org.apache.jena.reasoner.rulesys.impl.SafeGraph in project jena by apache.
the class BasicForwardRuleInfGraph method createDeductionsGraph.
/**
* Create the graph used to hold the deductions. Can be overridden
* by subclasses that need special purpose graph implementations here.
* Assumes the graph underlying fdeductions and associated SafeGraph
* wrapper can be reused if present thus enabling preservation of
* listeners.
*/
protected Graph createDeductionsGraph() {
if (fdeductions != null) {
Graph dg = fdeductions.getGraph();
if (dg != null) {
// Reuse the old graph in order to preserve any listeners
safeDeductions.clear();
return dg;
}
}
Graph dg = Factory.createGraphMem();
safeDeductions = new SafeGraph(dg);
return dg;
}
use of org.apache.jena.reasoner.rulesys.impl.SafeGraph in project jena by apache.
the class TestSafeModel method testBasics.
/**
* Create a generalized model via inference and check it is
* safe but unwrappable
*/
public void testBasics() {
Model base = ModelFactory.createDefaultModel();
Resource r = base.createResource(egNS + "r");
Property p = base.createProperty(egNS + "p");
Property q = base.createProperty(egNS + "q");
Literal l = base.createLiteral("foo");
Statement asserted = base.createStatement(r, p, l);
r.addProperty(p, l);
List<Rule> rules = Rule.parseRules("(?r eg:p ?v) -> (?v eg:q ?r).");
GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
InfModel inf = ModelFactory.createInfModel(reasoner, base);
TestUtil.assertIteratorValues(this, inf.listStatements(), new Statement[] { asserted });
Model deductions = inf.getDeductionsModel();
TestUtil.assertIteratorValues(this, deductions.listStatements(), new Statement[] {});
Graph safeGraph = deductions.getGraph();
assertTrue(safeGraph instanceof SafeGraph);
Graph rawGraph = ((SafeGraph) safeGraph).getRawGraph();
Triple deduction = new Triple(l.asNode(), q.asNode(), r.asNode());
TestUtil.assertIteratorValues(this, rawGraph.find(Node.ANY, Node.ANY, Node.ANY), new Triple[] { deduction });
}
Aggregations