Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Comparison and arithmetic on xsd:duration #2680

Open
cmdoret opened this issue Jan 5, 2024 · 1 comment
Open

Bug: Comparison and arithmetic on xsd:duration #2680

cmdoret opened this issue Jan 5, 2024 · 1 comment

Comments

@cmdoret
Copy link

cmdoret commented Jan 5, 2024

It seems that comparisons (<,<=, ==, >=, >) and arithmetic operations (+,-) on xsd:duration in SPARQL queries always evaluate to null. Is this a bug?

Example:

data="""
@prefix ex: <http://example.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <https://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .


ex:d1 ex:lasted "P6D"^^xsd:duration .
ex:d2 ex:lasted "P4D"^^xsd:duration .
"""
g = Graph().parse(data=data)
print(g.query("""
  SELECT ((?d1 - ?d2) AS ?delta)
  WHERE {
    ex:d1 ex:lasted ?d1 .
    ex:d2 ex:lasted ?d2 .
  }
""").serialize(format='csv').decode())

Observed output:

delta
""

Expected output:

delta
"P2D"^^xsd:duration

Do I understand correctly that conversion between xsd:duration and python types has not yet been added (e.g. here)?

If so, maybe I coud give it a shot, but I am not familiar with the codebase and don't fully appreciate the complexity of adding such support.

Environment:

  • python 3.10.6
  • rdflib 7.0.0
@WhiteGobo
Copy link
Contributor

This seems like a bug. But i think that the problem is located in the sparql-plugin not with term.py

As far as i know, xsd:duration and other time related stuff is converted in python types of datetime and of isodate depending on the value. But those conversions are not always realiable because types isodate arent always compatible with types of datetime. Also isodate, which is used for the conversion, doesnt seem to be maintained anymore.

You can check if a conversion was used with the attribute value(checked with rdflib 7.0.0):

Literal("P6D", datatype=XSD.duration).value
>>> datetime.timedelta(days=6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants