我需要实现这种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>

关于java - 耶拿OWL/RDF功能属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43599490/

10-10 14:31