首页 > 解决方案 > owl api state ObjectProperty 个人之间的关系来自进口

问题描述

我有一个导入其他本体实例的本体实例,并且我正在尝试使用ObjectProperty导入的个体(professors-instanceacm-ccs-lite-core)与主本体实例的个体(curricula-instance)之间的关系来说明关系。

如果我使用 protege 手动完成,它会创建:

<!-- http://www.semanticweb.org/lsarni/ontologies/professors-instance#Andrés_Calviño -->

<rdf:Description rdf:about="http://www.semanticweb.org/lsarni/ontologies/professors-instance#Andrés_Calviño">
    <curricula:inChargeOf rdf:resource="http://www.semanticweb.org/lsarni/ontologies/curricula-instance#Software_Architecture"/>
</rdf:Description>

<!-- http://www.semanticweb.org/lulas/ontologies/2018/acm-ccs-lite-core#10011119 -->

<rdf:Description rdf:about="http://www.semanticweb.org/lulas/ontologies/2018/acm-ccs-lite-core#10011119">
    <curricula:taughtIn rdf:resource="http://www.semanticweb.org/lsarni/ontologies/curricula-instance#Databases_1"/>
</rdf:Description>

但是我尝试使用 owl api 的方式是NamedIndividual在主本体中创建一个并添加如下关系:

<!-- http://www.semanticweb.org/lsarni/ontologies/professors-instance#Andrés_Calviño -->

<owl:NamedIndividual rdf:about="http://www.semanticweb.org/lsarni/ontologies/professors-instance#Andrés_Calviño">
    <curricula:inChargeOf rdf:resource="http://www.semanticweb.org/lsarni/ontologies/curricula-instance#Software_Architecture"/>
</owl:NamedIndividual>

这是我正在使用的代码:

File file = new File("C:\\Users\\lulas\\Documents\\Curricula Ontology\\curricula-instance.owl");
OWLOntology o = man.loadOntologyFromOntologyDocument(file);
OWLDataFactory df = o.getOWLOntologyManager().getOWLDataFactory();

IRI curriculaIOR = IRI.create("http://www.semanticweb.org/lsarni/ontologies/curricula");
IRI instanceIOR = IRI.create("http://www.semanticweb.org/lsarni/ontologies/curricula-instance");
IRI profInstanceIOR = IRI.create("http://www.semanticweb.org/lsarni/ontologies/professors-instance");

OWLObjectProperty charge = df.getOWLObjectProperty(curriculaIOR + "#inChargeOf");
OWLIndividual individual = df.getOWLNamedIndividual(profInstanceIOR + "#Andrés_Calviño");
OWLIndividual course = df.getOWLNamedIndividual(instanceIOR + "#Software_Architecture");

OWLObjectPropertyAssertionAxiom objAssertion = df.getOWLObjectPropertyAssertionAxiom(charge, individual, course);
AddAxiom addAxiom = new AddAxiom(o, objAssertion);
man.applyChange(addAxiom);

哪个是创建 的正确方法rdf:Description


编辑

我在 Windows 上使用 Protege 5.2.0 版。

正如你们都说代码是正确的,我对其中一个导入的本体使用了不正确的 IRI,这就是为什么它在不同的地方充当 this 的原因NamedIndividual

标签: ontologyprotegeowl-api

解决方案


一个rdf:Description with anrdf:about` IRI 相当于一个命名的个体,因此两个版本之间没有真正的区别。它们将被 OWL API 解析为相同的东西。

不知道为什么 Protege 以这种格式输出它 - 正如 Henriette 在评论中所问的那样,哪个版本的 Protege 正在这样做?


推荐阅读