0

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.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
ryyral
  • 3
  • 1
  • **"I have tried but it doesn't work"** You told us what you expect it to return; what does it *actually* return? – Joshua Taylor Aug 18 '14 at 12:37
  • Hi it is supposed to return HavingDrink class. it actually returns PersonalActivity class, which is a super and abstract class of HavingDrink – ryyral Aug 19 '14 at 21:47
  • OWL doesn't have abstract classes. It's hard to tell what's actually in your ontology since you've only shown us some of it (the RDF snippet), and the rest you're creating programatically. It would be much easier to diagnose this problem if you can create a minimal ontology that demonstrates the problem, and show the Java code to load it, run the reasoner, and display the problematic result. – Joshua Taylor Aug 19 '14 at 21:50
  • Hi, The ontology is available online here webmind.di.unimi.it/care/snapshot.owl. – ryyral Aug 20 '14 at 22:59

2 Answers2

0

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.

Ignazio
  • 10,504
  • 1
  • 14
  • 25
  • Hi, I have tried what you said, it returned "expected individual http://webmind.dico.unimi.it/CARE/locont.owl#alice_activity". The ontology is available online here http://webmind.di.unimi.it/care/snapshot.owl. This paper "Is ontology-based activity recognition really effective" used this ontology to infer activity, I am interested in it, but do not make it work. – ryyral Aug 19 '14 at 21:56
0

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.

ryyral
  • 3
  • 1