query-1a24388daa0673c55ce245f1b73b96b5

rq turtle/ttl

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

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]". }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?age"):::projected v4("?ageInDays") v5("?ageInYears") v2("?born") v3("?died") v1("?person"):::projected c6(["wd:Q8454"]):::iri c8(["bd:serviceParam"]):::iri c10(["#91;AUTO_LANGUAGE#93;"]):::literal c2(["wd:Q5"]):::iri v1 --"wdt:P31"--> c2 v1 --"wdt:P569"--> v2 v1 --"wdt:P570"--> v3 v1 --"wdt:P1196"--> c6 bind0[/"?died - ?born"/] v3 --o bind0 v2 --o bind0 bind0 --as--o v4 bind1[/"?ageInDays / '365.2425^^xsd:decimal'"/] v4 --o bind1 bind1 --as--o v5 bind2[/"numeric-floor(?ageInYears)"/] v5 --o bind2 bind2 --as--o v6 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c8 --"wikibase:language"--> c10 end