3
votes

I'm noob in Jena and reading this page,more specifically in Figure 5(iii) -"direct inferred relationship" I found exactly what I need. Basically, my OntModel needs to respect the following rule: "Can't be allowed direct statements which can be inferred". But unfortunately I don't know how to materialize this ideas in Jena.

My example code is:

    String baseUri="http://entidades.owl";
    OntModel base = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);

    OntClass studant = base.createClass(baseUri +"#Student");

    OntClass person = base.createClass(baseUri +"#Person");
    OntClass ser = base.createClass(baseUri +"#ThingLive");

    Property isA = base.createTransitiveProperty(baseUri+"#IsA", true);
    nome.addDomain(person);
    base.add(new StatementImpl(studant, isA, person));
    base.add(new StatementImpl(person, isA, ser));

    base.createIndividual(baseUri+"#JonhDoe",studant);
    base.createIndividual(baseUri+"#JonhDoe",person);
    base.createIndividual(baseUri+"#JonhDoe",ser);
    base.write(System.out);

    OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF,base);
    model.write(System.out);

Well,

  1. I try to build a "isA" property as a "transitiveProperty" but the reasoner does not recognize it. How can I fix it ?

  2. If I change: base.add(new StatementImpl(studant, isA, person)); base.add(new StatementImpl(person, isA, ser));

to:

person.addSubClass(student); ser.addSubClass(person);

The reasoner was able to inferrer perfectly, but unfortunatly OntModel "base" and OntModel "model" show me the same RDF. I think that "model" should show me a minimal RDF graph reflected.

What can I do to see this changes in the RDF structure ?

Thank you so much guys!!!!!

1

1 Answers

1
votes

Your code is good, the only problem is that:

model.write(System.out);

calls OntModel.write(), which is defined to write the base model only. This is because many users want to be able to have a workflow of read a model, manipulate the model, save the model and not have the saved version polluted with, for example, the closure of the transitive properties.

If you query the model, your query will see the inferred triples as well as the base model triples. It's only write() that is affected here. If you truly want to write the whole model for debugging, including deduced triples, use OntModel.writeAll().