> Betreff: Problems with Reasoning - even the simple explamples from Docu does
> not work!
>
> Hi
>
> i have a serious problem to get any reasoner up and running.
> Also the examples from the documentation:
> https://jena.apache.org/documentation/inference/
> does not work here.
> I transferred the example into a unit test, so that the problem might be
> easier reproduced.
>
> Is reasoning limited to certain environment like a spatial JDK or so on, or
> am i getting something wrong?
>
> Thanks
>
> Here the (your example) code (as java unit test):
>
> import static org.junit.Assert.assertNotNull;
>
> import java.io.PrintWriter;
> import java.util.Iterator;
>
> import org.junit.Before;
> import org.junit.Test;
>
> import com.hp.hpl.jena.rdf.model.InfModel;
> import com.hp.hpl.jena.rdf.model.Model;
> import com.hp.hpl.jena.rdf.model.ModelFactory;
> import com.hp.hpl.jena.rdf.model.Property;
> import com.hp.hpl.jena.rdf.model.Resource;
> import com.hp.hpl.jena.rdf.model.Statement;
> import com.hp.hpl.jena.rdf.model.StmtIterator;
> import com.hp.hpl.jena.reasoner.Derivation;
> import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
> import com.hp.hpl.jena.reasoner.rulesys.Rule;
> import com.hp.hpl.jena.vocabulary.RDFS;
>
> public class ReasonerTest {
>
> String NS = "urn:x-hp-jena:eg/";
>
> // Build a trivial example data set
> Model model = ModelFactory.createDefaultModel();
> InfModel inf;
>
> Resource A = model.createResource(NS + "A");
> Resource B = model.createResource(NS + "B");
> Resource C = model.createResource(NS + "C");
> Resource D = model.createResource(NS + "D");
>
> Property p = model.createProperty(NS, "p");
> Property q = model.createProperty(NS, "q");
>
>
> @Before
> public void init() {
>
> // Some small examples (subProperty)
> model.add(p, RDFS.subPropertyOf, q);
> model.createResource(NS + "A").addProperty(p, "foo");
>
> String rules = "[rule1: (?a eg:p ?b) (?b eg:p ?c) -> (?a eg:p ?c)]";
> GenericRuleReasoner reasoner = new
> GenericRuleReasoner(Rule.parseRules(rules));
> reasoner.setDerivationLogging(true);
> inf = ModelFactory.createInfModel(reasoner, model);
>
> // Derivations
> A.addProperty(p, B);
> B.addProperty(p, C);
> C.addProperty(p, D);
> }
>
>
> @Test
> public void subProperty() {
> Statement statement = A.getProperty(q);
> System.out.println("Statement: " + statement);
> assertNotNull(statement);
> }
>
>
> @Test
> public void derivations() {
> String trace = null;
> PrintWriter out = new PrintWriter(System.out);
> for (StmtIterator i = inf.listStatements(A, p, D); i.hasNext(); ) {
> Statement s = i.nextStatement();
> System.out.println("Statement is " + s);
> for (Iterator id = inf.getDerivation(s); id.hasNext(); ) {
> Derivation deriv = (Derivation) id.next();
> deriv.printTrace(out, true);
> trace += deriv.toString();
> }
> }
> out.flush();
> assertNotNull(trace);
> }
>
> @Test
> public void listStatements() {
> StmtIterator stmtIterator = inf.listStatements();
> while(stmtIterator.hasNext()) {
> System.out.println(stmtIterator.nextStatement());
> }
> }
> }
>
>