JENA:创建对象 属性 两个不同个体之间的断言 ontology 类
JENA: Create Object Property Assertions between two individuals of different ontology classes
我正在使用 jena 创建 rdf/xml 格式的 OWL。
我可以为 class 创建个人,如下所示
OntClass wine = model.createClass(uri + "#wine")
OntClass meat = model.createClass(uri + "#meat")
ObjectProperty predicate = model.createObjectProperty(uriBase + "#goes_well_with")
predicate.addDomain(wine)
predicate.addRange(meat)
Individual whiteWine = wine.createIndividual(uri + "white_wine")
Individual redMeat = meat.creatIndividual(uri + "red_meat")
whiteWine.addRDFType(OWL2.NamedIndividual)
redMeat.addRDFType(OWL2.NamedIndividual)
jena 将其写入文件
<!-- classes -->
<owl:Class rdf:about="http://www.example.com/ontology#wine"/>
<owl:Class rdf:about="http://www.example.com/ontology#meat"/>
<!-- object property -->
<owl:ObjectProperty rdf:about="http://www.example.com/ontology#goes_well_with">
<rdfs:domain rdf:resource="http://www.example.com/ontology#wine"/>
<rdfs:range rdf:resource="http://www.example.com/ontology#meat"/>
</owl:ObjectProperty>
<!-- individuals -->
<owl:NamedIndividual rdf:about="http://www.example.com/ontology#white_wine">
<rdf:type rdf:resource="http://www.example.com/ontology#wine"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://www.example.com/ontology#red_meat">
<rdf:type rdf:resource="http://www.example.com/ontology#meat"/>
</owl:NamedIndividual>
现在我想在 个人 white_wine 和 之间创建对象 属性 断言red_meat 在耶拿
这将导致(下面的示例在 protege 中手动创建)
<owl:NamedIndividual rdf:about="http://www.example.com/ontology#white_wine">
<rdf:type rdf:resource="http://www.example.com/ontology#wine"/>
<!-- this is the part I am unable to render with jena -->
<goes_well_with rdf:resource="http://www.example.com/ontology#red_meat"/>
<!-------------------->
</owl:NamedIndividual>
感谢您对此的所有帮助
我找到了一个示例代码片段,它给了我预期的结果。
在创建对象 属性 predicate 和个人 whiteWine 和 redMeat 之后(如有问题的代码)只需在下面添加使用 ModelCon.add(resource,predicate,rdfNode)
的代码
model.add(whiteWine, predicate, redMeat)
或@ASKW 在评论中提到的
whiteWine.addProperty(predicate, redMeat)
同样有效。
这导致
<owl:NamedIndividual rdf:about="http://www.example.com/ontology#white_wine">
<rdf:type rdf:resource="http://www.example.com/ontology#wine"/>
<goes_well_with rdf:resource="http://www.example.com/ontology#red_meat"/>
</owl:NamedIndividual>
现在我得到了我想要的结果,然而
- 代码到底做了什么?
- 它是否添加了断言?
- 它添加了一个三元组吗?
感谢您的帮助。
我正在使用 jena 创建 rdf/xml 格式的 OWL。
我可以为 class 创建个人,如下所示
OntClass wine = model.createClass(uri + "#wine")
OntClass meat = model.createClass(uri + "#meat")
ObjectProperty predicate = model.createObjectProperty(uriBase + "#goes_well_with")
predicate.addDomain(wine)
predicate.addRange(meat)
Individual whiteWine = wine.createIndividual(uri + "white_wine")
Individual redMeat = meat.creatIndividual(uri + "red_meat")
whiteWine.addRDFType(OWL2.NamedIndividual)
redMeat.addRDFType(OWL2.NamedIndividual)
jena 将其写入文件
<!-- classes -->
<owl:Class rdf:about="http://www.example.com/ontology#wine"/>
<owl:Class rdf:about="http://www.example.com/ontology#meat"/>
<!-- object property -->
<owl:ObjectProperty rdf:about="http://www.example.com/ontology#goes_well_with">
<rdfs:domain rdf:resource="http://www.example.com/ontology#wine"/>
<rdfs:range rdf:resource="http://www.example.com/ontology#meat"/>
</owl:ObjectProperty>
<!-- individuals -->
<owl:NamedIndividual rdf:about="http://www.example.com/ontology#white_wine">
<rdf:type rdf:resource="http://www.example.com/ontology#wine"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://www.example.com/ontology#red_meat">
<rdf:type rdf:resource="http://www.example.com/ontology#meat"/>
</owl:NamedIndividual>
现在我想在 个人 white_wine 和 之间创建对象 属性 断言red_meat 在耶拿
这将导致(下面的示例在 protege 中手动创建)
<owl:NamedIndividual rdf:about="http://www.example.com/ontology#white_wine">
<rdf:type rdf:resource="http://www.example.com/ontology#wine"/>
<!-- this is the part I am unable to render with jena -->
<goes_well_with rdf:resource="http://www.example.com/ontology#red_meat"/>
<!-------------------->
</owl:NamedIndividual>
感谢您对此的所有帮助
我找到了一个示例代码片段,它给了我预期的结果。
在创建对象 属性 predicate 和个人 whiteWine 和 redMeat 之后(如有问题的代码)只需在下面添加使用 ModelCon.add(resource,predicate,rdfNode)
的代码model.add(whiteWine, predicate, redMeat)
或@ASKW 在评论中提到的
whiteWine.addProperty(predicate, redMeat)
同样有效。
这导致
<owl:NamedIndividual rdf:about="http://www.example.com/ontology#white_wine">
<rdf:type rdf:resource="http://www.example.com/ontology#wine"/>
<goes_well_with rdf:resource="http://www.example.com/ontology#red_meat"/>
</owl:NamedIndividual>
现在我得到了我想要的结果,然而
- 代码到底做了什么?
- 它是否添加了断言?
- 它添加了一个三元组吗?
感谢您的帮助。