SPARQL/模板
外觀
< SPARQL
在 Wikidata查詢服務查詢助手內,註釋#TEMPLATE可以構建一個簡單的模板,使用者可以在其中選擇一個或多個變數來更改查詢,而無需瞭解SPARQL查詢語言。
下面是一個從任何國家選擇總統及其配偶的例子
#TEMPLATE={"template":"Presidents of ?country and their spouses","variables":{"?country":{"query":" SELECT ?id WHERE { ?id wdt:P31 wd:Q6256 . }"} } }
SELECT ?p ?pLabel ?ppicture ?w ?wLabel ?wpicture WHERE {
BIND(wd:Q30 AS ?country) # United States of America
?country (p:P6/ps:P6) ?p. # Head of government
?p wdt:P26 ?w. # Spouse
OPTIONAL {
?p wdt:P18 ?ppicture.
?w wdt:P18 ?wpicture.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
該“模板”包含文字和一個或多個變數。
該“變數”列出了變數,並可選地提供一個“查詢”來選擇可能的值,在本例中,?id是國家例項。
- 如果不需要查詢,語法為“?var1”:{} 在這種情況下,可能是
#TEMPLATE={"template":"Presidents of ?country and their spouses","variables":{"?country":{} } }
注意:BIND(wd:Q30 AS ?country) 用作變數 ?country 的預設值。