Template:SPARQL
Usage
[edit]This template displays SPARQL query with syntax highlighting, prefixes and link to WDQS site to run the query.
Parameter | Description | Type | Status | |
---|---|---|---|---|
p | p | Produce p: prefix if set | Boolean | optional |
q | q | Produce q: prefix if set | Boolean | optional |
v | v | Produce v: prefix if set | Boolean | optional |
query | query | SPARQL query | String | required |
extraprefix | extraprefix | Extra prefixes to be added | String | optional |
state | state | Either "collapsed" or "expanded", both make the query code collapsible, "collapsed" makes it start collapsed. In a list ("*" or "#" at beginning of line) the "Collapse"/"Expand" toggle button is displayed next to the link to the Wikidata Query Service. | String | optional |
label | label | Text to be used as the label of the link to the Wikidata Query Service
| Content | optional |
shortURL | shortURL | slug of the query's short URL, as generated by the WMF URL shortener - for example, for https://w.wiki/37j enter just 37j | String | optional |
project | project | project name: '''wd''' for Wikidata and '''sdc''' for Structured Data on Commons | String | optional |
Embedded | embedded | Shall the link direct user to the results (yes) or to the code (no, empty) | String | suggested |
Highlight | highlight | Line(s) in the source code to be highlighted. See [[mediawiki:Extension:SyntaxHighlight#highlight]] for the supported syntax
| Line | optional |
Examples
[edit]Wikicode | Rendered result |
---|---|
{{SPARQL|query=SELECT DISTINCT ?person ?name ?language ?death (URI(CONCAT("https://www.gutenberg.org/ebooks/author/", ?gutenberg)) AS ?gberglink) WHERE { ?person wdt:P1938 ?gutenberg. ?person wdt:P570 ?death. # Dead people only MINUS { ?enws schema:about ?person. ?enws schema:isPartOf <https://en.wikisource.org/> } OPTIONAL {?person wdt:P1412 ?lang}. FILTER (!BOUND(?lang) {{!}}{{!}} ?lang = wd:Q1860) # Language: English or absent BIND(IF(BOUND(?lang),"English","Not specified") AS ?language ) ?person rdfs:label ?name. FILTER((LANG(?name)) = "en") } ORDER BY ?death |shortURL=37j}} |
SELECT DISTINCT ?person ?name ?language ?death (URI(CONCAT("https://www.gutenberg.org/ebooks/author/", ?gutenberg)) AS ?gberglink) WHERE {
?person wdt:P1938 ?gutenberg.
?person wdt:P570 ?death. # Dead people only
MINUS {
?enws schema:about ?person.
?enws schema:isPartOf <https://en.wikisource.org/>
}
OPTIONAL {?person wdt:P1412 ?lang}.
FILTER (!BOUND(?lang) || ?lang = wd:Q1860) # Language: English or absent
BIND(IF(BOUND(?lang),"English","Not specified") AS ?language
) ?person rdfs:label ?name.
FILTER((LANG(?name)) = "en")
}
ORDER BY ?death
|
{{SPARQL|embedded=yes|query= #defaultView:Map SELECT DISTINCT ?airport ?coor WHERE { ?airport (wdt:P31/wdt:P279) wd:Q62447; wdt:P17 wd:Q142. ?airport wdt:P625 ?coor. MINUS { ?airport (wdt:P576|wdt:P582|wdt:P3999) ?dispar. } MINUS { ?airport wdt:P5817 ?interdit. VALUES ?interdit { wd:Q811683 wd:Q63065035 wd:Q12377751 wd:Q30108381 wd:Q11639308 } } } |highlight=1, 8-14 }} |
#defaultView:Map
SELECT DISTINCT ?airport ?coor WHERE {
?airport (wdt:P31/wdt:P279) wd:Q62447; wdt:P17 wd:Q142.
?airport wdt:P625 ?coor.
MINUS { ?airport (wdt:P576|wdt:P582|wdt:P3999) ?dispar. }
MINUS {
?airport wdt:P5817 ?interdit.
VALUES ?interdit {
wd:Q811683
wd:Q63065035
wd:Q12377751
wd:Q30108381
wd:Q11639308
}
}
}
|
See also
[edit]Warning: If you use the pipe character ("|") in your query, you need to replace it with {{!}}
{{SPARQLText}}
syntax highlighted query text{{SPARQL}}
shows query text, links to the non-executed query (this template){{SPARQL2}}
with item/property listing{{SPARQL5}}
with item/property listing{{SPARQL6}}
with item/property listing, indentable{{SPARQL8}}
inline (no query text), links to the non-executed query{{SPARQL9}}
same as SPARQL?{{SPARQL Inline}}
inline (no query text), links to the non-executed query and or the results page{{SPARQL Box}}
inline (no query text) styled as a centered paragraph box, links to the non-executed query{{Wdquery}}
inline (no query text), links to the non-executed query, rather than to the results page{{Quickquery}}
simple graph patterns, allows to set limit and defaultView{{Query page}}
query stored on a dedicated wiki page, to be transcluded into other pages
The above documentation is transcluded from Template:SPARQL/doc (edit | history). Editors can experiment in this template's sandbox (edit | diff) and testcases (create) page. Please add categories to the /doc subpage. Subpages of this template. |