use of org.apache.jena.reasoner.rulesys.FBRuleInfGraph in project jena by apache.
the class TestLPBRuleEngine method testTabledGoalsLeak.
@Test
public void testTabledGoalsLeak() throws Exception {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, ty, C1));
List<Rule> rules = Rule.parseRules("[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)]");
FBRuleInfGraph infgraph = (FBRuleInfGraph) createReasoner(rules).bind(data);
LPBRuleEngine engine = getEngineForGraph(infgraph);
assertEquals(0, engine.activeInterpreters.size());
assertEquals(0, engine.tabledGoals.size());
ExtendedIterator<Triple> it = infgraph.find(a, ty, C1);
it.close();
// how many were cached
assertEquals(1, engine.tabledGoals.size());
// and no leaks of activeInterpreters
assertEquals(0, engine.activeInterpreters.size());
// Now ask again:
it = infgraph.find(a, ty, C1);
it.close();
// if it was a cache hit, no change here:
assertEquals(1, engine.tabledGoals.size());
assertEquals(0, engine.activeInterpreters.size());
//the cached generator should not have any consumingCP left
for (Generator generator : engine.tabledGoals.asMap().values()) {
assertEquals(0, generator.consumingCPs.size());
}
}
use of org.apache.jena.reasoner.rulesys.FBRuleInfGraph in project jena by apache.
the class TestLPBRuleEngine method testSaturateTabledGoals.
@Test
public void testSaturateTabledGoals() throws Exception {
final int MAX = 1024;
// Set the cache size very small just for this test
System.setProperty("jena.rulesys.lp.max_cached_tabled_goals", "" + MAX);
try {
Graph data = Factory.createGraphMem();
data.add(new Triple(a, ty, C1));
List<Rule> rules = Rule.parseRules("[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)]");
FBRuleInfGraph infgraph = (FBRuleInfGraph) createReasoner(rules).bind(data);
LPBRuleEngine engine = getEngineForGraph(infgraph);
assertEquals(0, engine.activeInterpreters.size());
assertEquals(0, engine.tabledGoals.size());
// Let's ask about lots of unknown subjects
for (int i = 0; i < MAX * 128; i++) {
Node test = NodeFactory.createURI("test" + i);
ExtendedIterator<Triple> it = infgraph.find(test, ty, C2);
assertFalse(it.hasNext());
it.close();
}
// Let's see how many were cached
assertEquals(MAX, engine.tabledGoals.size());
// and no leaks of activeInterpreters (this will happen if we forget
// to call hasNext above)
assertEquals(0, engine.activeInterpreters.size());
} finally {
System.clearProperty("jena.rulesys.lp.max_cached_tabled_goals");
}
}
use of org.apache.jena.reasoner.rulesys.FBRuleInfGraph in project jena by apache.
the class TestLPDerivation method makeInfGraph.
/**
* Return an inference graph working over the given rule set and raw data.
* Can be overridden by subclasses of this test class.
* @param rules the rule set to use
* @param data the graph of triples to process
* @param tabled an array of predicates that should be tabled
*/
public static InfGraph makeInfGraph(List<Rule> rules, Graph data, Node[] tabled) {
FBRuleReasoner reasoner = new FBRuleReasoner(rules);
FBRuleInfGraph infgraph = (FBRuleInfGraph) reasoner.bind(data);
for (Node aTabled : tabled) {
infgraph.setTabled(aTabled);
}
// infgraph.setTraceOn(true);
infgraph.setDerivationLogging(true);
return infgraph;
}
use of org.apache.jena.reasoner.rulesys.FBRuleInfGraph in project jena by apache.
the class TestOWLMisc method hiddenTestOWLLoop.
/**
* Test looping on recursive someValuesFrom.
*/
public void hiddenTestOWLLoop() {
Model data = FileManager.get().loadModel("file:testing/reasoners/bugs/loop.owl");
InfModel infmodel = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), data);
((FBRuleInfGraph) infmodel.getGraph()).setTraceOn(true);
String baseURI = "http://jena.hpl.hp.com/eg#";
Resource C = infmodel.getResource(baseURI + "C");
Resource I = infmodel.getResource(baseURI + "i");
Property R = infmodel.getProperty(baseURI, "R");
// ((FBRuleInfGraph)infmodel.getGraph()).setTraceOn(true);
System.out.println("Check that the instance does have an R property");
Statement s = I.getProperty(R);
System.out.println(" - " + s);
System.out.println("And that the type of the R property is C");
Statement s2 = ((Resource) s.getObject()).getProperty(RDF.type);
System.out.println(" - " + s2);
System.out.println("But does that have an R property?");
Statement s3 = ((Resource) s.getObject()).getProperty(R);
System.out.println(" - " + s3);
System.out.println("List all instances of C");
int count = 0;
for (Iterator<Statement> i = infmodel.listStatements(null, RDF.type, C); i.hasNext(); ) {
Statement st = i.next();
System.out.println(" - " + st);
count++;
}
System.out.println("OK");
// infmodel.write(System.out);
// System.out.flush();
}
use of org.apache.jena.reasoner.rulesys.FBRuleInfGraph in project jena by apache.
the class WebOntTestHarness method doRunTest.
/**
* Run a single test of any sort, return true if the test succeeds.
*/
public boolean doRunTest(Resource test) throws IOException {
if (test.hasProperty(RDF.type, OWLTest.PositiveEntailmentTest) || test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest) || test.hasProperty(RDF.type, OWLTest.OWLforOWLTest) || test.hasProperty(RDF.type, OWLTest.ImportEntailmentTest) || test.hasProperty(RDF.type, OWLTest.TrueTest)) {
// Entailment tests
boolean processImports = test.hasProperty(RDF.type, OWLTest.ImportEntailmentTest);
Model premises = getDoc(test, RDFTest.premiseDocument, processImports);
Model conclusions = getDoc(test, RDFTest.conclusionDocument);
comprehensionAxioms(premises, conclusions);
long t1 = System.currentTimeMillis();
InfGraph graph = reasoner.bind(premises.getGraph());
if (printProfile) {
((FBRuleInfGraph) graph).resetLPProfile(true);
}
Model result = ModelFactory.createModelForGraph(graph);
boolean correct = WGReasonerTester.testConclusions(conclusions.getGraph(), result.getGraph());
long t2 = System.currentTimeMillis();
lastTestDuration = t2 - t1;
if (printProfile) {
((FBRuleInfGraph) graph).printLPProfile();
}
if (test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest)) {
correct = !correct;
}
return correct;
} else if (test.hasProperty(RDF.type, OWLTest.InconsistencyTest)) {
// System.out.println("Starting: " + test);
Model input = getDoc(test, RDFTest.inputDocument);
long t1 = System.currentTimeMillis();
InfGraph graph = reasoner.bind(input.getGraph());
boolean correct = !graph.validate().isValid();
long t2 = System.currentTimeMillis();
lastTestDuration = t2 - t1;
return correct;
} else if (test.hasProperty(RDF.type, OWLTest.ConsistencyTest)) {
// Not used normally becase we are not complete enough to prove consistency
// System.out.println("Starting: " + test);
Model input = getDoc(test, RDFTest.inputDocument);
long t1 = System.currentTimeMillis();
InfGraph graph = reasoner.bind(input.getGraph());
boolean correct = graph.validate().isValid();
long t2 = System.currentTimeMillis();
lastTestDuration = t2 - t1;
return correct;
} else {
for (StmtIterator i = test.listProperties(RDF.type); i.hasNext(); ) {
System.out.println("Test type = " + i.nextStatement().getObject());
}
throw new ReasonerException("Unknown test type");
}
}
Aggregations