Saved datetimes of instances have xsd:string instead of xsd:datetime data type

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

Saved datetimes of instances have xsd:string instead of xsd:datetime data type

phiofx
This post was updated on .
Hi all,
first, since I am new here, many thanks for this wonderful package and the active community around it. Looking forward to going through the book and getting familiar with all the ins and outs of owlready.

In the meantime I have jumped directly into a project and got stuck with the following: I am creating instances with an ontology that is also generated within owlready using python classes. After the abstact ontology is setup (and verified as consistent in protege) further code basically iterates over entities, data properties and values as per:

  setattr(entity, prop.name, [value])

where entity is the instance of a class, prop is a data property (obtained from onto.data_properties()) and value is any of the various (limited) types allowed by owl.

After all instances are created I write the whole thing to a file using:

  onto.save(file="instances.owl", format="rdfxml")


It all works quite well (eg for decimal, boolean) except for data properties of datetime type. These are saved as having type xsd:string instead of of xsd:dateTime. More precisely, for a property (has_current_date) I get in the file elements like:

    <has_current_date rdf:datatype="http://www.w3.org/2001/XMLSchema#string">2019-11-23T10:35:28</has_current_date>

So the element has an element rdf:datatype that is set to string whereas it should be datetime. The problem is that this then makes the ontology inconsistent (e.g in protege) because the range of that property is set as dateTime within the ontology.

Not sure where exactly it goes wrong, any hint appreciated


-------------------------------------------------------
Some further info that might be useful:

the datetime value is created in python using (eventually) t.strftime('%Y-%m-%dT%H:%M:%S') but passing the datetime variable directly does not work

Reply | Threaded
Open this post in threaded view
|

Re: Saved datetimes of instances have xsd:string instead of xsd:datetime data type

phiofx
This post was updated on .
ok, solved

The problem was that the python data type of the value assigned to the property was pandas.timestamp rather than datetime.

Converting the pandas.timestamp to a string of the right datetime appearance means that is was serialized nicely but unfortunately with the wrong type :-)