Skip to content

Instantly share code, notes, and snippets.

@niclashoyer
Created June 28, 2012 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save niclashoyer/3010916 to your computer and use it in GitHub Desktop.
Save niclashoyer/3010916 to your computer and use it in GitHub Desktop.
Example SPARQL Queries for Events
PREFIX time:<http://www.w3.org/2006/time#>
PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>
PREFIX event:<http://purl.org/NET/c4dm/event.owl#>
INSERT DATA {
_:ev a event:Event ;
event:time _:time .
_:time a time:Interval ;
time:hasBeginning _:begin ;
time:hasEnd _:end .
_:begin a time:Instant ;
time:inXSDDateTime "2012-06-28T11:04:14Z"^^xsd:dateTime .
_:end a time:Instant ;
time:inXSDDateTime "2012-07-28T11:04:14Z"^^xsd:dateTime .
}
PREFIX time:<http://www.w3.org/2006/time#>
PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>
PREFIX event:<http://purl.org/NET/c4dm/event.owl#>
SELECT ?x ?begin ?end
WHERE {
?x a event:Event .
?x event:time _:t .
_:t a time:Interval ;
time:hasBeginning _:begin ;
time:hasEnd _:end .
_:begin time:inXSDDateTime ?begin .
_:end time:inXSDDateTime ?end .
FILTER (?begin > "2012-06-25T11:04:14Z"^^xsd:dateTime)
}
PREFIX time:<http://www.w3.org/2006/time#>
PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>
PREFIX event:<http://purl.org/NET/c4dm/event.owl#>
PREFIX todo:<http://example.com/todoontology#>
PREFIX ex:<http://example.com/>
INSERT DATA {
ex:todo01 a todo:Todo ;
todo:due [
a event:Event ;
event:time [
a time:Interval ;
time:hasBeginning [
a time:Instant ;
time:inXSDDateTime "2012-06-28T11:04:14Z"^^xsd:dateTime
] ;
time:hasEnd [
a time:Instant ;
time:inXSDDateTime "2012-07-28T11:04:14Z"^^xsd:dateTime
]
]
] ;
todo:done [
a event:Event ;
event:time [
a time:Instant ;
time:inXSDDateTime "2012-07-15T11:04:14Z"^^xsd:dateTime
]
]
}
# Select all Todos that have a due and that are done
PREFIX time:<http://www.w3.org/2006/time#>
PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>
PREFIX event:<http://purl.org/NET/c4dm/event.owl#>
PREFIX todo:<http://example.com/todoontology#>
PREFIX ex:<http://example.com/>
SELECT ?todo
WHERE {
?todo a todo:Todo ;
todo:done [
a event:Event ;
event:time ?done
] ;
todo:due [
a event:Event ;
event:time ?due
] .
{
?due a time:Instant ;
time:inXSDDateTime ?duexsd
} UNION {
?due a time:Interval ;
time:hasEnd [
a time:Instant ;
time:inXSDDateTime ?duexsd
]
}
{
?done a time:Instant ;
time:inXSDDateTime ?donexsd
} UNION {
?done a time:Interval ;
time:hasEnd [
a time:Interval ;
time:inXSDDateTime ?donexsd
]
}
FILTER ( ?duexsd >= NOW() && ?donexsd <= ?duexsd )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment