耶拿 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"/>

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

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 如何序列化它们(即考虑哪一个 "primary")。为了说明,我会将您的示例序列化为 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>