JENA:在不同本体类的两个个体之间创建对象属性断言

问题描述 投票:1回答:1

我正在用耶拿创建rdf / xml格式的OWL。

我可以为如下所示的班级创建个人

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>

现在我想在耶拿的[[个人 白葡萄酒红肉之间创建对象属性声明

这将导致(下面的例子是在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>

感谢您对此的所有帮助
java jena owl
1个回答
0
投票
我发现了一个示例代码片段,该片段为我带来了预期的结果。

创建对象属性

predicate和个体whiteWine and redMeat(就像所讨论的代码之后),只需使用ModelCon.add(resource,predicate,rdfNode)添加以下代码model.add(whiteWine, 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>

现在我得到了想要的结果,但是

    代码只是做什么?
  • 它添加了断言吗?
  • 是否添加了三元组?
  • 感谢您的帮助。
  • © www.soinside.com 2019 - 2024. All rights reserved.