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 (default), 'sdc' for Structured Data on Commons, or the URL of another compatible query service (e.g. 'https://database.factgrid.de/query/' – note that this must be a page with the query UI frontend, not the SPARQL endpoint itself) | 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 |
QLever | qlever | Add link to QLever (only supported for project=wd or project=sdc)
| Boolean | optional |
Orb Open Graph | orb | Add link to Orb Open Graph
| Boolean | 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
}
}
}
| |
{{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 } } } |qlever=true }} |
#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
}
}
}
| |
{{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 } } } |qlever=true }} |
#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 {{!}}
|