use of org.apache.jena.reasoner.rulesys.RuleDerivation in project jena by apache.
the class TestLPDerivation method doTest.
/**
* Run a single derivation test. Only tests the first derivation found.
* @param ruleSrc source for a set of rules
* @param tabled array of predicate nodes which should be tabled by the rules
* @param triples inital array of triple data
* @param query the query to be tested the first result will be checked
* @param matches the set of triple matches which should occur in the derivation
* @param rulenumber the index of the rule in the rule list which should occur in the derivation
*/
private void doTest(String ruleSrc, Node[] tabled, Triple[] triples, Triple query, Triple[] matches, int rulenumber) {
List<Rule> rules = Rule.parseRules(ruleSrc);
Graph data = Factory.createGraphMem();
for (Triple triple : triples) {
data.add(triple);
}
InfGraph infgraph = makeInfGraph(rules, data, tabled);
ExtendedIterator<Triple> results = infgraph.find(query);
assertTrue(results.hasNext());
Triple result = results.next();
results.close();
Rule rule = rules.get(rulenumber);
List<Triple> matchList = Arrays.asList(matches);
Iterator<Derivation> derivations = infgraph.getDerivation(result);
assertTrue(derivations.hasNext());
RuleDerivation derivation = (RuleDerivation) derivations.next();
// PrintWriter pw = new PrintWriter(System.out);
// derivation.printTrace(pw, true);
// pw.close();
assertEquals(result, derivation.getConclusion());
assertEquals(matchList, derivation.getMatches());
assertEquals(rule, derivation.getRule());
}
Aggregations