繁体   English   中英

Jena OWL / RDF FunctionalProperty

[英]Jena OWL/RDF FunctionalProperty

我需要实现这样的OWL格式:

<owl:DatatypeProperty rdf:ID="Role-description"> <rdfs:range
rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdfs:domain rdf:resource="#Role"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>

我正在使用耶拿,当我尝试下一步时:

DatatypeProperty datatypeProperty = ontModel.createDatatypeProperty(OWL.NS + "Role-description");
datatypeProperty.addRDFType(OWL.FunctionalProperty);
datatypeProperty.asDatatypeProperty();

获得所有老虎钳。

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
  <owl:Class rdf:about="http://www.w3.org/2002/07/owl#Task"/>
  <owl:Class rdf:about="http://www.w3.org/2002/07/owl#Actor"/>
  <owl:ObjectProperty rdf:about="http://www.w3.org/2002/07/owl#Task-performedBy-Actor"/>
  <owl:ObjectProperty rdf:about="http://www.w3.org/2002/07/owl#Actor-performs-Task"/>
  <owl:FunctionalProperty rdf:about="http://www.w3.org/2002/07/owl#Role-description">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
  </owl:FunctionalProperty>
</rdf:RDF>

将不胜感激任何建议

你得到的输出反之亦然 您基本上拥有的是具有多种类型的RDF资源。 这取决于Jena如何序列化它们(即哪一个被认为是“主要的”)。 为了说明,我将您的示例序列化为Turtle(稍微修改为使用自定义命名空间):

@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix roles: <http://example.com/ns/roles#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .

roles:Role-description
        a       owl:DatatypeProperty , owl:FunctionalProperty .

现在,以下是如何操作类型的顺序以方便序列化:

public static final String ROLES_NS = "http://example.com/ns/roles#";

public static void main(String[] args) {
    OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
    ontModel.setNsPrefix("roles", ROLES_NS);

    DatatypeProperty prop = ontModel.createDatatypeProperty(
            ROLES_NS + "Role-description");
    prop.setRDFType(OWL.FunctionalProperty);
    prop.addRDFType(OWL.DatatypeProperty);

    RDFDataMgr.write(System.out, ontModel, RDFFormat.RDFXML_PRETTY);
}

它产生以下输出:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:roles="http://example.com/ns/roles#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
  <owl:DatatypeProperty rdf:about="http://example.com/ns/roles#Role-description">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>
  </owl:DatatypeProperty>
</rdf:RDF>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM