-
Notifications
You must be signed in to change notification settings - Fork 31
Parameter Mapping
When creating a query it can be made more general by using special variables inside the query. Adding these variables allows for the API to insert given parameters that are used by the query, making it dynamic. Creating such a variable is done by adding a '_' between the '?' and the variable name, resulting in:
?_name
With this variable name the parameter will replace the variable as a simple literal, by adding another term after the variable name the parameter will be interpreted differently.
When using:
-
?_name_en
it will be interpreted as a literal written in English, this can be done with any language tag. -
?_name_integer
it will be interpreted as an integer. -
?_name_iri
it will be interpreted as an IRI. -
?_name_prefix_datatype
it will be interpreted as a datatype of type^^prefix:datatype
.
When there will not always be a parameter to replace the variable two underscores can be used to create an optional parameter, resulting in:
?__name
This way of mapping the parameters is based on the conventions used by BASIL.
The code of the query would look like this (for more on the first seven lines you can read query decorators):
#+ summary: Returns the bands
#+ endpoint: http://dbpedia.org/sparql
#+ tags:
#+ - bands
#+ defaults:
#+ - type: http://dbpedia.org/ontology/Band
#+ - genre: http://dbpedia.org/resource/Grunge
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?band WHERE {
?band a ?_type_iri .
?band dbo:genre ?__genre_iri .
?band dbo:activeYearsStartYear ?_year_xsd_date .
}
LIMIT 30
Giving you control over the parameters in the API that looks like this: