Search in sources :

Example 1 with RuleDerivation

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());
}
Also used : InfGraph(org.apache.jena.reasoner.InfGraph) FBRuleInfGraph(org.apache.jena.reasoner.rulesys.FBRuleInfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) FBRuleInfGraph(org.apache.jena.reasoner.rulesys.FBRuleInfGraph) Derivation(org.apache.jena.reasoner.Derivation) RuleDerivation(org.apache.jena.reasoner.rulesys.RuleDerivation) Rule(org.apache.jena.reasoner.rulesys.Rule) RuleDerivation(org.apache.jena.reasoner.rulesys.RuleDerivation)

Aggregations

Derivation (org.apache.jena.reasoner.Derivation)1 InfGraph (org.apache.jena.reasoner.InfGraph)1 FBRuleInfGraph (org.apache.jena.reasoner.rulesys.FBRuleInfGraph)1 Rule (org.apache.jena.reasoner.rulesys.Rule)1 RuleDerivation (org.apache.jena.reasoner.rulesys.RuleDerivation)1