简体   繁体   中英

how to find the most specific class for an individual with pellet+owlapi

I want to perform classification with ontology and pellet reasoner. Pellet has a function(namely realization()) to find the most specific for an individual. I have tried but it doesn't work, could anybody provide some help or give me some examples.

<Class rdf:about="http://webmind.dico.unimi.it/CARE/locont.owl#HavingDrink">
    <equivalentClass>
        <Class>
            <intersectionOf rdf:parseType="Collection">
                <rdf:Description rdf:about="http://webmind.dico.unimi.it/CARE/locont.owl#PersonalActivity"/>
                <Restriction>
                    <onProperty rdf:resource="http://webmind.dico.unimi.it/CARE/locont.owl#hasActor"/>
                    <allValuesFrom>
                        <Class>
                            <intersectionOf rdf:parseType="Collection">
                                <rdf:Description rdf:about="http://webmind.dico.unimi.it/CARE/locont.owl#Person"/>
                                <Restriction>
                                    <onProperty rdf:resource="http://webmind.dico.unimi.it/CARE/locont.owl#hasCurrentSymbolicLocation"/>
                                    <someValuesFrom rdf:resource="http://webmind.dico.unimi.it/CARE/locont.owl#Kitchen"/>
                                </Restriction>
                                <Restriction>
                                    <onProperty rdf:resource="http://webmind.dico.unimi.it/CARE/locont.owl#usingArtifact"/>
                                    <someValuesFrom>
                                        <Class>
                                            <unionOf rdf:parseType="Collection">
                                                <rdf:Description rdf:about="http://webmind.dico.unimi.it/CARE/locont.owl#CupsCupboard"/>
                                                <rdf:Description rdf:about="http://webmind.dico.unimi.it/CARE/locont.owl#Fridge"/>
                                            </unionOf>
                                        </Class>
                                    </someValuesFrom>
                                </Restriction>
                            </intersectionOf>
                        </Class>
                    </allValuesFrom>
                </Restriction>
            </intersectionOf>
        </Class>
    </equivalentClass>
    <rdfs:subClassOf rdf:resource="http://webmind.dico.unimi.it/CARE/locont.owl#PersonalActivity"/>
</Class>

For example, the HavingDrink is one of the activity classes. now I create an individual and its ObjectProperty:

    String file = "file:///home/uqjwen/workspace/Owlapi/snapshot.owl#";
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ont = manager.loadOntology(IRI.create(file));
    OWLDataFactory fac = manager.getOWLDataFactory();

    PrefixManager pm = new DefaultPrefixManager(IRI.create("http://webmind.dico.unimi.it/CARE/locont.owl").toString());


    //////////create hasActor property///////////////////////////////////////
    OWLNamedIndividual currentActivity = fac.getOWLNamedIndividual("#alice_activity", pm);
    OWLNamedIndividual alice = fac.getOWLNamedIndividual("#alice", pm);
    OWLObjectProperty hasActor = fac.getOWLObjectProperty("#hasActor", pm);
    OWLObjectPropertyAssertionAxiom propertyAssertion = fac
            .getOWLObjectPropertyAssertionAxiom(hasActor,currentActivity,alice);
    manager.addAxiom(ont, propertyAssertion);

    ////////////create hasCurrentSymbolicLocation ////////
    OWLNamedIndividual kitchen = fac.getOWLNamedIndividual("#Kitchen", pm);

    OWLObjectProperty hasLocation = fac
            .getOWLObjectProperty("#hasCurrentSymbolicLocation", pm);
    OWLObjectPropertyAssertionAxiom locationAssertion = fac
            .getOWLObjectPropertyAssertionAxiom(hasLocation,alice,kitchen);
    manager.addAxiom(ont, locationAssertion);

    /////////////create using actifact  //////////////
    OWLNamedIndividual cc = fac.getOWLNamedIndividual("#cups_cupboard", pm);
    OWLObjectProperty usingArtifact = fac
            .getOWLObjectProperty("#usingArtifact", pm);
    OWLObjectPropertyAssertionAxiom artifactAssertion =fac
            .getOWLObjectPropertyAssertionAxiom(usingArtifact, alice, cc);
    manager.addAxiom(ont, artifactAssertion);

    OWLNamedIndividual fridge = fac.getOWLNamedIndividual("#fridge", pm);
    artifactAssertion =fac
            .getOWLObjectPropertyAssertionAxiom(usingArtifact, alice, fridge);
    manager.addAxiom(ont, artifactAssertion);


    //////////////reason 
    PelletReasoner reasoner = PelletReasonerFactory.getInstance().createReasoner( ont );
    System.out.println(reasoner.isConsistent());
    reasoner.getKB().classify();
    reasoner.getKB().realize();
    NodeSet<OWLClass> types = reasoner.getTypes(currentActivity, true);

it is supposed to return HavingDrink class, but it does not.

The first thing to check is that the ontology contains the classes and individuals you expect it to contain—you can do this by saving the ontology to System.out in the code, so that you're sure of what is loaded:

manager.saveOntology(ont, new SystemOutDocumentTarget());

Then make sure the IRIs being resolved by the prefix manager match the IRIs in the ontology:

OWLNamedIndividual currentActivity = fac.getOWLNamedIndividual("#alice_activity", pm);
System.put.println("expected individual "+currentActivity.getIRI());

Once these possible sources of error are out of the way, you need to verify that the type you expect is actually inferrable from the ontology—we cannot see the rest of the ontology, and there might be important information there that might change the expected result.

Edit: From the ontology, the definition for HavingDrink (in functional syntax) is:

EquivalentClasses(:HavingDrink ObjectIntersectionOf( ObjectAllValuesFrom(:hasActor ObjectIntersectionOf(:Person ObjectSomeValuesFrom(:hasCurrentSymbolicLocation :Kitchen) ObjectSomeValuesFrom(:usingArtifact ObjectUnionOf(:Fridge :CupsCupboard))) ) :PersonalActivity))

In order for something to be a HavingDrink activity, it must have a value for usingArtifact of type Fridge or CupsCupboard , for which I cannot see assertions in your ontology. It's quite a complex definition, so I would start checking whether alice_activity is an instance of the separate parts of the intersection, and ensure each of them is satisfied. The middle term is not satisfied, as far as I can tell.

Thanks Joshua and Ignazio, finally I found the problem. When I defined the ontology with protege by myself, it worked well. So I can concluded that there might be problems with the definition of the ontology here: webmind.di.unimi.it/care/snapshot.owl.

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