Page MenuHomePhabricator

[Story] Maintain Query Examples
Open, MediumPublic

Description

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

Current list: https://www.mediawiki.org/wiki/Wikibase/Indexing/SPARQL_Query_Examples

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: https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples#Find_drugs_for_cancers_that_target_genes_related_to_cell_proliferation ).
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 https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples#Human_settlements_without_an_article_in_any_language_version_of_Wikipedia), 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"

image.png (1×1 px, 217 KB)

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 query.wikidata.org, 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.)

I've a question: the URL of the Wikidata query example page is currently https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples

For a Wikibase.cloud instance I use (https://kbtestwikibase.wikibase.cloud) I figured out (by trail and error) that the URL needed to be https://kbtestwikibase.wikibase.cloud/wiki/Project:SPARQL/examples for the examples to show in the dropdown in the query service https://kbtestwikibase.wikibase.cloud/query

For another Wikibase I'd like to be able to show a query example dropdown in the QS GUI as well, but if I try https://<wikibase>/wiki/Wikidata:SPARQL_query_service/queries/examples or https://<wikibase>/wiki/Project:SPARQL/examples , those do not work.

Hence: I was wondering if there is some variable in the MediaWiki-configuration that defines this URL. So how/where is this URL specified?

It should be controlled by apia.examples.pageTitle in the config, see default-config.json.

It should be controlled by apia.examples.pageTitle in the config, see default-config.json.

Many thanks Lucas, I'll try it out with our sysadmin a.s.a.p. and let you know what the outcome was (can't adapt the config myself)

Where can we find the documentation about parameters that can be set in the config.json file?
For example, I would like as in https://kbtestwikibase.wikibase.cloud to remove the query builder button.
I find that the URL can be set with api.query-builder.server but don't know how to hide the button.

The same question about documentation on how to build the page with sample queries.
How is the page parsed by the query service?
Is there some specific template to use?

I would like also to precise that my setup is Wikibase release pipeline with current latest stable version 1.40.1 deployed on Docker version 24.0.7 hosted on Ubuntu 20.04.6 LTS

One more question also, about randompage.
On Wikidata or https://kbtestwikibase.wikibase.cloud the randompage open random item.
But on my setup the randompage only open random page and not item.
IHow is ti possible to change the behaviour?

The same question about documentation on how to build the page with sample queries.
....
Is there some specific template to use?

By looking at https://www.wikidata.org/w/index.php?title=Wikidata:SPARQL_query_service/queries/examples&action=edit I figured out that the headings in https://kbtestwikibase.wikibase.cloud/w/index.php?title=Project:SPARQL/examples&action=edit needed to be H2 (==) and H3 (===) in order for that page to be shown correctly in the query examples https://kbtestwikibase.wikibase.cloud/query/

Thanks for your reply.

Indeed headers are use as title and the SPARQL query need to be between tags as <syntaxhighlight lang="sparql">SELECT ... <syntaxhighligh>