Support for xsd.duration in time ontology?

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

Support for xsd.duration in time ontology?

chrum
This post was updated on .
Good afternoon!

First off, thanks for this great package.
Really appreciate having a simplified way to operate on owl files away from GUIs or Java.

I was wondering whether owlready2 already supports the xsd.duration format and if not what I would need to do to get it to work? Would this need implementing in the parser section?

Here a link to how the format looks like.
xsd.duration format description

The format is really useful to be able to do "on-the-fly" SPARQL duration and date calculations but
has a funky notation, e.g. "P12M" for 12 months, hence I wonder whether this is causing a problem or its something I haven't defined correctly.

Currently when I try to import an instance of a class that is using the data property "has XSD duration" (time ontology) with range "xsd.duration", the result is a parser error
"ValueError: Cannot read literal of datatype 749!".


edit: To expand on this:
Running:

list(default_world.sparql("""
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT (now() - "P1Y"^^xsd:duration AS ?year_ago)
WHERE {}
    """))

does not result in a correctly rendered or output answer. This query results in [[2022]], however unlike the previously presented case, it does run.

Any ideas?

Thank you for your time!

With best wishes,
Chrum
Reply | Threaded
Open this post in threaded view
|

Re: Support for xsd.duration in time ontology?

Jiba
Administrator
Hi,

I've just added xsd:duration support in Owlready development version. Durations are translated into Python timedelta objets (and suffer all associated limitations, e.g. 1 month is considered as 30 days).

In addition, I've added DATETIME_ADD,  DATETIME_SUB,  DATE_ADD, DATE_SUB SPARQL function for computing on dates, e.g. :

list(default_world.sparql("""
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT (DATETIME_SUB(now(), "P1Y"^^xsd:duration) AS ?year_ago)
WHERE {}
    """))

Supporting such operation with + and - operator would be very complex, requiring to track the type of each operand, so I opted for function.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Support for xsd.duration in time ontology?

chrum
Dear Jiba,

Thank you very much for the incredibly fast turn-around!
I was going to suggest the Isodate Package for some of the datetime and duration parsing to help ease the burden.

I have two questions:

1. With the functional implementation currently employed, will the functions have to be called in the select statement or can they be called anywhere within the SPARQL query? e.g. within a BIND statement.

2. Apologies for the beginner question, how would I install the development build?

Thank you very much for the great work!

With best wishes,
Chrum
Reply | Threaded
Open this post in threaded view
|

Re: Support for xsd.duration in time ontology?

Jiba
Administrator
1) The functions can be used anywhere a function can be used, including BIND statement.

2) You need to download it with GIT, and to install it manually -- I'll make a new release soon.

Bonus : I've also added DATETIME_DIFF function for computing the duration between two dates.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Support for xsd.duration in time ontology?

Jiba
Administrator
You can now install Owlready 0.36 with the xsd:duration support,

Jiba