-
Notifications
You must be signed in to change notification settings - Fork 581
Closed
Labels
Milestone
Description
The script below gives output
[(rdflib.term.URIRef('file:///home/wrobell/projects/uddo/#c1'), None),
(rdflib.term.URIRef('file:///home/wrobell/projects/uddo/#c2'), None)]
It would be nice to get time difference as xsd:duration instead of nulls.
The script
from pprint import pprint
import rdflib
import io
data = """
@prefix : <#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
:C a rdfs:Class.
:start a rdf:Property;
rdfs:domain :C;
rdfs:range xsd:dateTime.
:end a rdf:Property;
rdfs:domain :C;
rdfs:range xsd:dateTime.
:c1 a :C;
:start "2016-01-01 20:00:00"^^xsd:dateTime;
:end "2016-01-02 20:01:00"^^xsd:dateTime.
:c2 a :C;
:start "2016-01-01 20:05:00"^^xsd:dateTime;
:end "2016-01-01 20:30:00"^^xsd:dateTime.
"""
graph = rdflib.Graph()
f = io.StringIO(data)
graph.parse(f, format='n3')
result = graph.query("""
SELECT ?c ?duration
WHERE {
BIND(?end - ?start AS ?duration)
?c :start ?start;
:end ?end.
}
""")
pprint(list(result))