简体   繁体   中英

How to synchronize reasoner in OWLAPI

I got a small ontology with the individuals. Some of these individuals should be connected with each other through symmetric ObjectProperty .

I need to use Pellet reasoner, so that it could synchronize and attach symmetric ObjectProperty to the individuals.

I use the OWLAPI to create the ontology. My code for the creation of ObjectProperty is:

// create the OWLObjectProperty isLinkedTo
OWLObjectProperty isLinkedTo = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#" +hasLinkStr));
// create a set for the axioms (OPAS - Obj.Prop.Axioms Set)
Set<OWLAxiom> isLinkedOPAS = new HashSet<OWLAxiom>();
// add the OWLObjectProperty isLinkedTo to the set isLinkedOPAS
OWLNamedIndividual prevNamedInd = factory.getOWLNamedIndividual(prevIndividual, pm);
isLinkedOPAS.add(factory.getOWLSymmetricObjectPropertyAxiom(isLinkedTo));
//setting the object property for the current (namedInd) and previous (prevNamedInd)individuals
isLinkedOPAS.add(factory.getOWLObjectPropertyAssertionAxiom(isLinkedTo, namedInd, prevNamedInd));
manager.addAxioms(ontology, isLinkedOPAS);

The individuals are created one after each other. Every next individual isLinkedTo previous one with the symmetrical property.

Then, I start the reasoner, but I am not sure if I do it in the right way:

OWLReasoner reasoner = reasonerFactory.createReasoner(ontology, config);
// I am not sure which of these commands is necessary for checking the ObjectProperty assertions
reasoner.precomputeInferences();
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_ASSERTIONS);
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_HIERARCHY);
boolean consistent = reasoner.isConsistent();
System.out.println("Consistent: " + consistent);

When I open this ontology in Protege, it shows me the individuals, but not "connected" symmetrically with the ObjectProperty isLinkedTo:

在此处输入图片说明

It shows the right way only after the running reasoner in Protege:

在此处输入图片说明

So the question is: What should I write in the code in order to obtain the ontology where the Object Properties are synchronized by the reasoner?

These three lines:

reasoner.precomputeInferences();
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_ASSERTIONS);
reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_HIERARCHY);

Can be replaced with:

reasoner.precomputeInferences(InferenceType.OBJECT_PROPERTY_ASSERTIONS,
                              InferenceType.OBJECT_PROPERTY_HIERARCHY);

However, for most reasoners this is not different from:

reasoner.precomputeInferences(InferenceType.values());

In order to see the inferred axioms without running a reasoner you can use an org.semanticweb.owlapi.util.InferredPropertyAssertionGenerator :

InferredPropertyAssertionGenerator generator = new InferredPropertyAssertionGenerator();
Set<OWLAxiom> axioms = generator.createAxioms(factory, reasoner);

This will provide the inferred axioms to add to the ontology.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM