Difference between revisions of "Template:SPARQL"
wd>Jarekt (update SDC URL) |
wd>DFichtmueller m (included MediaWiki:QueryServiceURL as default) |
||
Line 1: | Line 1: | ||
− | <onlyinclude><div {{#switch: {{{state|}}} | collapsed = class="mw-collapsible mw-collapsed" | expanded = class="mw-collapsible" }} >{{#tag:syntaxhighlight|{{SPARQLText|p={{{p|}}}|q={{{q|}}}|v={{{v|}}}|query={{#invoke:ConcatArgs|ConcatArgs|init=query|min=1}}|extraprefix={{{extraprefix|}}} }}|lang="sparql"}}</div>[{{#switch:{{{project| | + | <onlyinclude><div {{#switch: {{{state|}}} | collapsed = class="mw-collapsible mw-collapsed" | expanded = class="mw-collapsible" }} >{{#tag:syntaxhighlight|{{SPARQLText|p={{{p|}}}|q={{{q|}}}|v={{{v|}}}|query={{#invoke:ConcatArgs|ConcatArgs|init=query|min=1}}|extraprefix={{{extraprefix|}}} }}|lang="sparql"}}</div>[{{#switch:{{{project|wb}}}|wb={{MediaWiki:QueryServiceURL}}|wd=//query.wikidata.org/|sdc=//wcqs-beta.wmflabs.org}}#{{urlencode: {{SPARQLText|p={{{p|}}}|q={{{q|}}}|v={{{v|}}}|query={{#invoke:ConcatArgs|ConcatArgs|init=query|min=1}}|extraprefix={{{extraprefix|}}} }} | PATH }} {{{label|{{int try it}}}}}] {{#if: {{{shortURL|}}} | (<nowiki />https://w.wiki/{{{shortURL}}}<nowiki />) }}</onlyinclude> |
{{documentation}} | {{documentation}} |
Revision as of 08:14, 14 August 2020
Usage
This template displays SPARQL query with syntax highlighting, prefixes and link to WDQS beta site to run the query.
Parameter | Description | Type | Status | |
---|---|---|---|---|
query | query | SPARQL query
| String | required |
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 |
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 |
Examples
- {{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
See also
- Wikidata:SPARQL query service
{{SPARQL2}}
{{SPARQL Inline}}
{{Wdquery}}
- WDQ
Page Module:Message box/styles.css must have content model "Sanitized CSS" for TemplateStyles (current model is "CSS").
Template:Documentation/getText Template:Documentation/getText Template:Documentation/getText Template:Documentation/getText |