How to access the datatype of a property

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to access the datatype of a property

jonathanunderwood
When reading in an existing ontology file I am wondering what is the correct way to access the underlying data type of a datatype property. For example, I am reading in an ontology which has a datatype property of type http://www.w3.org/2001/XMLSchema#unsignedLong. Examining the .range attribute for this once owlready2 has parsed the ontology, I see it represented as the python int type. However, writing out the ontology to a new file persists the datatype as XMLSchema#unsignedLong as expected, so somehow the type information is persisted. The question is: how is that underlying data type accessed from Python? I can't find any attribute that seems to reference it.
Reply | Threaded
Open this post in threaded view
|

Re: How to access the datatype of a property

Jiba
Administrator
Hi,

You're right: the exact datatype is stored in the quadstore but was not available in Python.

In the development version of Owlready (on Bitbucket), I've added the Property.range_iri attribute that returns the list of range as IRI.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: How to access the datatype of a property

jonathanunderwood
Great, thank you for adding that feature!I thought I must have been missing something obvious, nice to know I wasn't.
Reply | Threaded
Open this post in threaded view
|

Re: How to access the datatype of a property

Michael
In reply to this post by Jiba
I see Property.range_iri is now available in the version from Pypi as well.

This is very useful information. I found this message because I discovered that Property.range returns inconsistent results  - some XMLSchema types appear to be converted but others are not. It might be safer not to convert any - or convert all of them?

<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#language"/>
Property.range is [None]

<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#anyURI"/>
Property.range is [<class 'owlready2.util.normstr'>]

<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#date"/>
Property.range is [<class 'datetime.date'>]
Reply | Threaded
Open this post in threaded view
|

Re: How to access the datatype of a property

Jiba
Administrator
Hi,

Indeed, only some XMLSchema were considered. In the development version, I've just added more aliases, including for "language" datatype.

Jiba