如何为颗粒+ owlapi的个人找到最具体的课程

时间:2014-08-18 03:45:14

标签: semantic-web owl ontology owl-api pellet

我想用本体和颗粒推理器进行分类。 Pellet具有一个功能(即实现()),以找到最具体的个人。我已经尝试但它不起作用,任何人都可以提供一些帮助或给我一些例子。

<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>

例如,HavingDrink是其中一个活动类。现在我创建一个人及其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);

它应该返回HavingDrink类,但它不会。

2 个答案:

答案 0 :(得分:0)

要检查的第一件事是本体包含您希望它包含的类和个体 - 您可以通过在代码中将本体保存到System.out来执行此操作,以便您确定要加载的内容:

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

然后确保前缀管理器解析的IRI与本体中的IRI匹配:

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

一旦这些可能的错误源被排除在外,您需要验证您期望的类型实际上是否可以从本体中推断 - 我们无法看到本体的其余部分,并且可能存在可能会更改的重要信息预期的结果。

编辑: 从本体论来看,HavingDrink(在函数语法中)的定义是:

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

为了使某些内容成为HavingDrink个活动,它必须具有usingArtifact类型FridgeCupsCupboard的值,我无法在其中看到断言本体论。这是一个非常复杂的定义,因此我将开始检查alice_activity是否是交集的各个部分的实例,并确保每个部分都满足。据我所知,中期不满意。

答案 1 :(得分:0)

感谢Joshua和Ignazio,最后我发现了这个问题。当我自己定义本体时,它运行良好。所以我可以得出结论,这里的本体定义可能存在问题:webmind.di.unimi.it/care/snapshot.owl。