Template talk:SPARQL

From Wikidata
Jump to navigation Jump to search


The template has a problem with the logical-or-operator (||). The query is cut. E.g.

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/> 
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?item ?taxonName WHERE {
  ?item wdt:P225 ?taxonName .
  ?item wdt:P105 wd:Q35409 . # family
  FILTER(!(STRENDS(?taxonName, "idae") || STRENDS(?taxonName, "aceae")))


SELECT ?item ?taxonName WHERE {
  ?item wdt:P225 ?taxonName .
  ?item wdt:P105 wd:Q35409 . # family
  FILTER(!(STRENDS(?taxonName, "idae")|| STRENDS(?taxonName, "aceae")))

Try it!

@Succu: It's a wiki template, so you have to escape vertical bars. Try
SELECT ?item ?taxonName WHERE {
  ?item wdt:P225 ?taxonName .
  ?item wdt:P105 wd:Q35409 . # family
  FILTER(!(STRENDS(?taxonName, "idae") || STRENDS(?taxonName, "aceae")))

Try it!

Jheald (talk) 16:38, 25 November 2015 (UTC)

Thanks, Jheald. I'm not very familiar with templates. --Succu (talk) 16:43, 25 November 2015 (UTC)
I stumbled upon the same. For those to whom Jheald's code looks just the same as above, he typed


Documentation: https://www.mediawiki.org/wiki/Help:Magic_words#Other --Vladimir Alexiev (talk) 17:11, 23 February 2017 (UTC)

Bug with Flow[edit]

@TomT0m, Jheald: it seems this template has a bug on Flow talk pages. See my page for example : User talk:VIGNERON. nowiki are weirdly automatically added and there is no link to query.wikidata.org...

Cdlt, VIGNERON (talk) 10:42, 17 May 2016 (UTC)

@Trizek (WMF): I confirm this bug. It seems Flow or parsoid automatically thinks the "{" must be escaped, but a single one has no meaning in Wikitext. Is it known ? Can you upstream this with Flow or parsoid devs ? author  TomT0m / talk page 16:25, 17 May 2016 (UTC)
@TomT0m, Jheald, VIGNERON:
I can't edit the post to check it because I'm not autopatrolled on WikiData.
Can you describe the expected behavior?
Thanks, Trizek (WMF) (talk) 15:19, 18 May 2016 (UTC)
Hi Trizek (WMF),
This is how this template usualy appears :
SELECT ?item ?itemLabel ?coord WHERE {
?item wdt:P131+ wd:Q3357 ; wdt:P625 ?coord .
SERVICE wikibase:label { bd:serviceParam wikibase:language "fr" }

Try it!

With syntax coloration (a detail but an useful one), no nowiki (obviously) and the most important a link at the end pointing to the actual query on query.wikidata.org.
Cdlt, VIGNERON (talk) 15:33, 18 May 2016 (UTC)
I've tried it with the visual editor and, if the result looks fine, the wikicode has <nowiki> tags too. There is still a missing curly bracket at the end of that query. That's probably a Parsoid issue.
What is the best way to describe that problem? Have you tried to change parameters on the TemplateData, like selecting "type": "unbalanced-wikitext" instead of "string"?
I've created a specific bug report concerning #tag:syntaxhighlight.
Trizek (WMF) (talk) 14:00, 19 May 2016 (UTC)


Regarding that tag, that feedback may interest you: "You used #tag:syntaxhighlight rather than <syntaxhighlight>? I think it's the same either way. It is interpreted, but needs to be styled." Trizek (WMF) (talk) 16:20, 20 May 2016 (UTC)

@Trizek (WMF): I think I switched one with the over for a reason when writing this template to solve a bug (could be this template, I'd have to check my history) but I can't remember why. author  TomT0m / talk page 16:31, 20 May 2016 (UTC)

Vertical space between query and Try it! link[edit]

@Jheald, TomT0m: I think there’s too much vertical space between the query and the Try it! link. I suggest the <br/> just before [http://query.wikidata.org/#... should be removed. WDYT? --WikidataFacts (talk) 18:06, 28 May 2016 (UTC)

@Jheald, TomT0m: if no one objects, I’ll make this change soon… let’s hope nothing breaks --TweetsFactsAndQueries (talk) 14:14, 30 June 2016 (UTC)
✓ Done, and everything seems to still be working :) --TweetsFactsAndQueries (talk) 13:28, 3 July 2016 (UTC)

Add a query title[edit]

Any objections putting the query into a table with title like this?

Cats Try it!
SELECT ?item ?itemLabel
	?item wdt:P31 wd:Q146 . 
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }

To compare, the current layout is:

# Cats
SELECT ?item ?itemLabel
	?item wdt:P31 wd:Q146 . 
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }

Try it!

An alternative would be to show the query title as header of some given depth so it is also shown in the table of contents. -- JakobVoss (talk) 08:10, 12 July 2016 (UTC)

We shouldn't use "try it" on the right because WDQS uses "execute" button on the left d1g (talk) 23:45, 28 August 2017 (UTC)

Exclude URL during print?[edit]

Not sure where to report it. Try to print preview at examples-heavy page e.g. User:TweetsFactsAndQueries/A_Guide_To_WDQS

It will result in

  • meaningless "try it" labels on paper
  • duplicate queries, urlencoded (omit them)

d1g (talk) 04:12, 1 February 2017 (UTC)

Two links[edit]

I'd like to replace the current, single, "try it" link with two links.

The first would say "Run it!", and link to the embed.html version of the query.

The second, using the current link target, would say something like "View/ edit".

Any thoughts? Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 21:15, 18 June 2017 (UTC)

name embed.html as "embed"?
I also need third link to "debug" [this query] as parameter for complex queries d1g (talk) 22:58, 19 July 2017 (UTC)
I don't understand the difference between "debug" and "view/edit" but at least two links make sense -- JakobVoss (talk) 16:02, 29 August 2017 (UTC)

Hide query[edit]

I'd like an option to not show the SPARQL code but only links ("try it"/run it!"/"show query"...). The SPARQL code could be collapsed (see Template:Collapse). -- JakobVoss (talk) 16:02, 29 August 2017 (UTC)

@JakobVoss: I had created User:Marsupium/Template:SPARQL for that. I've introduced the functionality here now with the parameter |state=. I've used the terms of en:Template:Navbox#Setup parameters. Because it isn't obvious anymore what can be tried with "Try it!" I've also introduced the parameter |label= that can be used to customize the link label. The "Collapse"/"Expand" toggle button is displayed at the right of the page with the exception of list obviously which is handy. Example:
  • SELECT ?item WHERE {
      ?item wdt:P31 wd:Q146.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    query finding house cats
I hope the changes are acceptable. Please remark any ideas for improvements! Thanks in advance, --Marsupium (talk) 14:33, 25 May 2018 (UTC)
@Marsupium: great, thanks! How do we get these parameters added to the template? -- JakobVoss (talk) 06:50, 27 May 2018 (UTC)
@JakobVoss: ?? They are already added. You can look at the documentation on the other side. :) --Marsupium (talk) 08:58, 27 May 2018 (UTC)
Sorry for confusion and many thanks! -- JakobVoss (talk) 20:39, 27 May 2018 (UTC)