Template:SPARQL

From Wikidata
Jump to: navigation, search
Documentation icon Template documentation[view] [edit] [history] [purge]

Usage[edit]

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

Template parameters

Parameter Description Type Status
query query

SPARQL query

Default
empty
Example
SELECT * WHERE { ?x wdt:P31 wd:Q5 } LIMIT 1
Auto value
empty
String required
p p

Produce p: prefix if set

Default
empty
Example
empty
Auto value
empty
Boolean optional
q q

Produce q: prefix if set

Default
empty
Example
empty
Auto value
empty
Boolean optional
v v

Produce v: prefix if set

Default
empty
Example
empty
Auto value
empty
Boolean optional
Extraprefix extraprefix

Extra prefixes to be added

Default
empty
Example
PREFIX wikibase: <http://wikiba.se/ontology#>
Auto value
empty
String optional

Examples[edit]

  • {{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 }}
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!

See also[edit]


Try it!