SPARQL queries (default, non inference):
1 - Retrieve all WORKs having a particular property 'date_document/work_date_document' (i.e. 'work_date_document' is a sub_property of 'date_document' in the CDM ontology)
---------------------------------------------------------------------------------------
PREFIX cdm: <http://publications.europa.eu/ontology/cdm#>
SELECT * WHERE { ?s cdm:work_date_document ?o. }
limit 100
---------------------------------------------------------------------------------------
SPARQL queries (with inference):
1 - Retrieve all WORKs having a particular property 'date_document'
---------------------------------------------------------------------------------------
DEFINE input:inference "cdm_rule_set"
PREFIX cdm: <http://publications.europa.eu/ontology/cdm#>
SELECT * WHERE { ?s cdm:date_document ?o. }
limit 100
---------------------------------------------------------------------------------------
==> The instruction {DEFINE input:inference "cdm_rule_set"} aims at activating the inference at querying time in CELLAR.
2- Count the number of (unique) WORKs that are monthly created during a particular year
---------------------------------------------------------------------------------------
DEFINE input:inference "cdm_rule_set"
PREFIX cdm: <http://publications.europa.eu/ontology/cdm#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX at: <http://publications.europa.eu/ontology/authority/>
SELECT ?month as ?MONTH COUNT(distinct ?work) as ?TOTAL
WHERE {
?work cdm:date_document ?date_doc .
filter ( year(?date_doc) = 2010 )
}
GROUP BY (month(?date_doc) AS ?month)
ORDER BY ?month
---------------------------------------------------------------------------------------
==> If a work is described by the property 'work_date_document', the inference engine takes into account this sub-property as a 'date_document'.
3-List the procedure related to a particular work.
DEFINE input:inference "cdm_rule_set"
prefix cdm: <http://publications.europa.eu/ontology/cdm#>
select distinct ?w ?event ?basis_legal where {
?w a cdm:work.
?w cdm:work_part_of_dossier ?dossier.
#?dossier cdm:dossier_contains_work ?w.
#?dossier cdm:procedure_code_interinstitutional_reference_procedure ?proc_code; cdm:procedure_code_interinstitutional_number_procedure ?proc_num; cdm:procedure_code_interinstitutional_year_procedure ?proc_year; cdm:number_reference ?num_ref.
?event cdm:event_part_of_dossier ?dossier.
?event ?p ?o.
?event cdm:basis_legal ?basis_legal.
FILTER(regex(?basis_legal, "12012E114"^^xsd:string))
} limit 1000
-----
DEFINE input:inference "cdm_rule_set"
prefix cdm: <http://publications.europa.eu/ontology/cdm#>
select distinct ?w ?dossier ?proc_num ?proc_year ?event ?basis_legal where {
?w a cdm:work.
?w cdm:work_part_of_dossier ?dossier.
?dossier cdm:procedure_code_interinstitutional_number_procedure ?proc_num; cdm:procedure_code_interinstitutional_year_procedure ?proc_year; cdm:number_reference ?num_ref.
FILTER((?proc_year="2013"^^xsd:gYear) and regex(?proc_num,"0410"))
?event cdm:event_part_of_dossier ?dossier.
#?event ?p ?o.
?event cdm:basis_legal ?basis_legal.
}
limit 1000
Query CELLAR using Python Rodeo
import requests
import rdflib
url="http://cellar-test.publications.europa.eu/resource/procedure/2113_410"
headerSettings={'Accept': 'application/rdf+xml'}
r = requests.get(url, headers=headerSettings)
#print(r.text)
graph = rdflib.Graph()
graph.parse(data=r.text)
output = []
for s, p, o in graph:
if type(o) == rdflib.term.Literal:
output.append(o.toPython())
print (output)