Difference between revisions of "Template:SPARQL"

From DiSSCo Modelling Framework
Jump to navigation Jump to search
wd>Jarekt
(update SDC URL)
 
m (2 revisions imported: Import of useful Templates and Modules from Wikidata)
 
(One intermediate revision by one other user not shown)
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|wd}}}|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>
+
<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}}

Latest revision as of 20:47, 6 January 2022

Try it!

50px Template:Documentation/getText[[[Template:SPARQL/doc|Template:Documentation/getText]] · [[Special:EditPage/Template:SPARQL/doc|Template:Documentation/getText]] · [[Special:PageHistory/Template:SPARQL/doc|Template:Documentation/getText]] · [[Special:Purge/Template:SPARQL#|Template:Documentation/getText]] ]

Usage

This template displays SPARQL query with syntax highlighting, prefixes and link to WDQS beta site to run the query.

Template parameters

ParameterDescriptionTypeStatus
queryquery

SPARQL query

Example
SELECT * WHERE { ?x wdt:P31 wd:Q5 } LIMIT 1
Stringrequired
pp

Produce p: prefix if set

Booleanoptional
qq

Produce q: prefix if set

Booleanoptional
vv

Produce v: prefix if set

Booleanoptional
Extraprefixextraprefix

Extra prefixes to be added

Example
PREFIX wikibase: <http://wikiba.se/ontology#>
Stringoptional
Statestate

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.

Stringoptional
Labellabel

Text to be used as the label of the link to the Wikidata Query Service

Default
Try it!
Contentoptional
ShortURLshortURL

slug of the query's short URL, as generated by the WMF URL shortener - for example, for https://w.wiki/37j enter just 37j

Stringoptional
projectproject

project name: '''wd''' for Wikidata and '''sdc''' for Structured Data on Commons

Stringoptional

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
Try it! (https://w.wiki/37j)

See also

Page Module:Message box/styles.css must have content model "Sanitized CSS" for TemplateStyles (current model is "CSS").