Page MenuHomePhabricator

[Story] Maintain Query Examples
Open, MediumPublic


We would like to have a nice collection of useful query examples for the Wikidata query service on
So we can show the beauty of Wikidata and allow people to retrieve information to satisfy their needs.

Current list:

We would like to have:

  • Queries to be always 'tagged' with Q-templates ( for example {{Q|Q30|United States of America}})
  • Queries should satisfy various use cases and user groups
  • Queries should be expressive and reusable
    • Showing useful information (label, description, URL (official homepage, identifier, etc.) , image, location )
    • Use various displaying formats ( table, Image Grid, Map, Bubble Chart, Tree Map ) (Use magic comments like #defaultView:Map)
    • Work nice with 'Query explanation'
    • Include a query template if usefully
  • Queries should always use a LIMIT
  • Queries should use OPTIONAL
  • Queries should never time out
  • Multiple languages

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

We have Query: namespace in wikidata, but I don't think it's being used. Maybe we should start using it?

Also may help having better editor/display for SPARQL like there is for Javascript. I imagine it would require creating a content handler but may be worth it.

The query namespace is going to be used later. We shouldn't use it for this at this point.

Then maybe some other namespace, like SPARQL: ?

What query namespace is reserved for?

It is for the stored queries we will use to generate lists on Wikipedia for example.

This ticket is about having:

  • Showcase queries to show the power and beauty of Wikidata.
  • Queries to explain and express the WDQS UI functionality.

I really like the idea of having sophisticated Wikibase SPARQL support, but I think we should use URL shortener [T44085] as an intermediate step for storing queries.

It is for the stored queries we will use to generate lists on Wikipedia for example.

If it's for SPARQL queries, then I don't see why can't we use them for examples too.

I don't think we need a shortener to store queries on Wikidata - after all, shortener is just another indexed storage, so what's the difference if we store it on shortener DB or on wikidata DB?

I think we should have a namespace where we store queries on wikidata (Query: or not, whatever we choose), with accompanying talk page for discussion, with content handler for pretty display (like Javascript) and maybe some metadata, like Template: namespace has.

Maybe we can sit around to at least start cleaning somewhere tomorrow? Should also be in scope of the documentation sprint.

I got the feedback that people are afraid of touching the existing queries, because it may upset authors.
Maybe we could somehow indicate that the page needs cleanup and restructuring, to motivate changes and reduce the fear of upsetting somebody.

Good point. So we need to find a way to find out what queries are useful. Are we tracking the amount of clicks on them?

AFAIK there is no easy way to find out what queries are clicked....
Is there a template we could use to indicate 'needs cleanup' ?

We could add it as an option to SPARQL/SPARQL2 template that queries use (or at least supposed to).

This task doesn't read as a story, but more like recurring house keeping. Maybe rewrite it into something more actionable or create new more focused stories?

Hi all,

Recently, I've checked out some examples under the topic Science, related to Biology and Medicine (for example: ).
There are lots of queries, with the header: #added before 2016-10 . Could I ask what the reason for this is?
And would it be an idea to change this to: Last modified at year-month-date? So we know if the queries are working, and which ones have been updated?

At that point we went through all examples and this was basically a marker. It could be removed/reused now.

I think the query examples should explicitly include even built-in WD prefixes such as wdt: and wikibase:. Missing prefixes render queries invalid and prevent people from simply copy-pasting them into their own environments.

The SPARQL example page seems currently broken, with the latest queries not properly displayed (currently starting at, and not properly accessible in the WDQS interface.
Hypothesis : is it because of the large number of the Template:SPARQL used in the same page ?

@Tfrancart Can you add a screenshot about how it looks like for you? I just checked and everything is fine for me, the list is correctly displayed, starting with cats.

@Lea_Lacroix_WMDE : look at the bottom of the page, the latest queries, starting with "Human settlements without an article in any language version of Wikipedia"

Hi there, noticed too the template SPARQL bug. Isn't it simply because the page is too large ?
Shouldn't we break it into subpages ?

  • Simple Queries
  • Showcase Queries
  • etc

Hi there, noticed too the template SPARQL bug. Isn't it simply because the page is too large ?
Shouldn't we break it into subpages ?

  • Simple Queries
  • Showcase Queries
  • etc

I like this idea. We could add a Lexeme Queries to that list.
Note: This will affect the script that generates the examples-UI in WDQS.

I went ahead and split the page. It now has 3 subpages that should be scraped as well.

We recently changed how example loading works (there’ll be an announcement with more information soon), and one consequence of that is that examples which don’t show up in the parsed wikitext – in this case, because the parser’s “post-expand include size limit” was exceeded – no longer load as examples in the query service UI.

But while I think splitting out some subpages makes sense, I don’t think we should scrape those. To me this issue means that the list of examples is simply too long, and instead of working around it by loading the examples from an ever-increasing list of pages, we should decide which queries we actually want to show on, and only include those on the main example page. (That doesn’t mean there can’t be other wiki pages with more examples, of course.)