Hi,

On 29/07/12 23:48, Alejandro Rodríguez González wrote:
Hi Dave,

Sorry, I thought that this was minimal enough  :-)

Just one question: how can I create an inference model without feed the
model with the original model? All the examples that I saw use a Model
object to load the ontology and feed the InfModel (with the reasoner also).

There's no problem creating an InfModel over another model the problem is that you have lines like:

 this.model.add(this.inferenceModel);

Where this.model is the model which is underneath this.inferenceModel, thus adding the data back into itself. This is probably not harmful on its own but makes it hard to trace what you are trying to do.

You can in fact just create an OntModel with the reasoner attached. So a simple example might be:

[[[
        String URI = "file:///C:/ont/ont.owl#";

        // Load rules
        List<Rule> rules = Rule.rulesFromURL("file:data/test.rules");
        GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
        reasoner.setTransitiveClosureCaching(true);
        reasoner.setDerivationLogging(true);

        // Set up inference model
        OntModelSpec reasonerSpec
                   = new OntModelSpec(OntModelSpec.OWL_MEM);
        reasonerSpec.setReasoner(reasoner);
        OntModel ontm = ModelFactory.createOntologyModel(reasonerSpec);

        FileManager.get().readModel(ontm, "data/ont.owl");
        PrintUtil.registerPrefix("ont", URI);

        // Add test test
        Resource c1 = ontm.createResource(URI + "c1");
        Property hasFinding = ontm.getProperty(URI + "hasFinding");
        Property diagnosis = ontm.getProperty(URI + "diagnosis");
        c1
          .addProperty(hasFinding, ontm.createResource(URI + "sA"))
          .addProperty(hasFinding, ontm.createResource(URI + "sB"))
          .addProperty(hasFinding, ontm.createResource(URI + "sC"));

        // Check result
        PrintWriter out = new PrintWriter(System.out);
for (StmtIterator si = ontm.listStatements(c1, diagnosis, (RDFNode)null); si.hasNext();) {
            Statement s = si.next();
            System.out.println("Statement: " + s + "\nDerivation:");
for (Iterator<Derivation> id = ontm.getDerivation(s); id.hasNext(); ) {
                Derivation deriv = (Derivation) id.next();
                deriv.printTrace(out, true);
            }
        }
        out.flush();
]]]

If I run that in a place where data/test.rules has your rule file and data/ont.owl has your ontology file then I get the output:

[[[
Statement: [file:///C:/ont/ont.owl#c1, file:///C:/ont/ont.owl#diagnosis, file:///C:/ont/ont.owl#dX]
Derivation:
Rule rule_dX_SIGN:sC concluded (ont:c1 ont:diagnosis ont:dX) <-
    Fact (ont:c1 ont:hasFinding ont:sA)
    Fact (ont:c1 ont:hasFinding ont:sB)
    Fact (ont:c1 ont:hasFinding ont:sC)
    noValue()
]]]

Dave

Reply via email to