Reputation: 3006
I need to achieve such OWL format:
<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"/>
I am using Jena and when I try to do next:
DatatypeProperty datatypeProperty = ontModel.createDatatypeProperty(OWL.NS + "Role-description");
datatypeProperty.addRDFType(OWL.FunctionalProperty);
datatypeProperty.asDatatypeProperty();
Get all vise a versa.
<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>
Will appreciate any advice
Upvotes: 1
Views: 207
Reputation: 3481
The output you are getting is not vice versa. What you basically have is an RDF resource with multiple types. It's up to Jena how to serialise them (i.e. which one to consider "primary"). To illustrate, I will serialise your example to Turtle (slightly modified to use custom namespace):
@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 .
Now, here is how you can manipulate the order of the types for a convenient serialisation:
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);
}
It produces the following output:
<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>
Upvotes: 3