SIOC/SampleQueries

From W3C Wiki

This page contains sample SPARQL queries that can be performed over SIOC data.

Get the Usergroups Uldis is involved in: {{{ PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT DISTINCT ?name ?group ?description WHERE {

?x rdf:type sioc:User .
?x sioc:name ?name .
?u sioc:has_member ?x .
{ ?u sioc:name ?group  } UNION
{ ?u sioc:description ?group } . 
FILTER REGEX(str(?name), "^Uldis Bojars$") 

} }}}

Comments on last month's topics: {{{ PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT ?post ?reply ?date WHERE

 { 
 ?post sioc:has_reply ?reply .
 ?post sioc:created_at ?date .
 FILTER (xsd:dateTime(?date) >= "2006-05-01T00:00:00Z"^^xsd:dateTime) 

} }}}

"Original" posts, i.e. not replies {{{ PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX sioc: <http://rdfs.org/sioc/ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT DISTINCT ?post ?title ?date ?author WHERE {

 ?post sioc:title ?title .
 ?post sioc:created_at ?date .
 ?post sioc:has_creator ?_y .
 ?_y rdfs:label ?author .
 OPTIONAL { ?_z sioc:has_reply ?post }
 FILTER (!bound(?_z))

} ORDER BY ?start }}}}