All,

With limited programming experience, I've been using the python module rdflib to familiarize myself with SPARQL and have what is probably a naive question, I hope you'll bear with me.

I have an RDF graph that looks, in part, like this:

<E5.Event rdf:about="http://jjcrump.itinerary.king.john/Event#75599bf70a3a036ef0b6c8b1ef331c2704fe648e "> <P117F.occurs_during rdf:datatype="http://www.w3.org/2001/XMLSchema#date ">1215-03-21</P117F.occurs_during> <P11F.had_participant rdf:resource="http://jjcrump.itinerary.king.john/person/king_john "/> <P7F.took_place_at rdf:resource="http://jjcrump.itinerary.king.john/place#geddington_northamptonshire "/>
</E5.Event>

<E5.Event rdf:about="http://jjcrump.itinerary.king.john/Event#7577d039daff5397bc5c4d8c671432fa0cdedaa1 "> <P115F.finishes rdf:datatype="http://www.w3.org/2001/ XMLSchema#date">1208-01-06</P115F.finishes> <P116F.starts rdf:datatype="http://www.w3.org/2001/ XMLSchema#date">1208-01-05</P116F.starts> <P11F.had_participant rdf:resource="http://jjcrump.itinerary.king.john/person/king_john "/> <P7F.took_place_at rdf:resource="http://jjcrump.itinerary.king.john/place#burbage_wiltshire "/>
</E5.Event>

ie. Instants have a single property for date, durations have start/end properties. I'm trying to construct a query that returns all events that fall within, or intersect with a date range.

This, for example, works:

PREFIX loc: <http://simile.mit.edu/2005/05/ontologies/location#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX place: <http://jjcrump.itinerary.king.john/place#>
PREFIX crm: <http://cidoc.ics.forth.gr/rdfs/cidoc_v4.2.rdfs#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?event ?place
WHERE {{?event crm:P117F.occurs_during ?date .}
UNION {?event crm:P116F.starts ?date .}
UNION {?event crm:P115F.finishes ?date .}
OPTIONAL { ?event crm:P7F.took_place_at ?place .}
FILTER (xsd:dateTime(?date) >= xsd:dateTime("1215-10-15")
&& xsd:dateTime(?date) <= xsd:dateTime("1215-10-31") )}

EXCEPT in the case of a duration that starts 1215-10-14 and ends 1215-11-01.

Is there any kind of arithmetic that can be done in the filter clause that will catch this case as well?

Many thanks for your patience,
Jon

Reply via email to