query-1a24388daa0673c55ce245f1b73b96b5
BIND, BOUND, IF These three features are often used in conjunction, so I’ll first explain all three of them and then show you some examples. clause can be used to assign the result of an expression to a variable (usually a new variable, but you can also overwrite existing ones). BIND(expression AS ?variable).A clause. OPTIONAL). It’s mostly useful on variables that are introduced in an false or true tests if a variable has been bound to a value (returns BOUND(?variable) . "terrible" evaluates to IF(false, "great", "terrible"), and "yes" evaluates to IF(true, "yes", "no"). That is, false evaluates to condition if elseExpression, and to true evaluates to condition if thenExpression evaluates to IF(condition,thenExpression,elseExpression) can be used to bind the results of some calculation to a new variable. This can be an intermediate result of a larger calculation or just directly a result of the query. For example, to get the age of victims of capital punishment: BIND
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?person ?personLabel ?age
WHERE
{
?person wdt:P31 wd:Q5;
wdt:P569 ?born;
wdt:P570 ?died;
wdt:P1196 wd:Q8454.
BIND(?died - ?born AS ?ageInDays).
BIND(?ageInDays/365.2425 AS ?ageInYears).
BIND(FLOOR(?ageInYears) AS ?age).
# eller, som et udtryk:
#BIND(FLOOR((?died - ?born)/365.2425) AS ?age).
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}