Page MenuHomePhabricator

Templatized WDQS scope does not really work. Propose fix : use a prefix instead of a bind.
Open, Needs TriagePublicBUG REPORT

Description

I filled this as a bug but this might be considered a feature request, depending on the point of view. (The point is that I considered this as a bummer when trying to use the feature)

The "template" feature of WDQS is useful, but there is a stopper that make it hard to use for some query. It requires a variable to "bind" a value, and that works only in some scope of a query.

If you write a complex query, the variable is likely to not be accessible in all the scopes.

See for example this query

#TEMPLATE={ "template": { "en": "Textual description of template, referencing ?var" }, "variables": { "?var": {  } } }

select * {
  
  bind ( wd:Q5 as ?var)
  
  ?person wdt:P31 ?var .
  
  {
    select ?person2 (?var as ?plop){
      ?person2 wdt:P31 ?var  .
      bind ( wd:Q5 as ?var)
    } limit 10
  }
} limit 100

that can be checked here

There is a "bind" in a subquery with the same variable, but when you interactively change the "human" value of the "?var" value then the value does not change in the subquery. This query is dummy of course, it’s just provided here for illustration.

There could be a solution using named subquery, doing the bind in a dummy named subquery and include in later in any relevant context, but it’s tedious to do, and named subquery tends to sometimes make a query timeout for non obvious reasons, which require work to solve.

I see too solutions for this problem :

  • either drop the use of a "bind" and instead use the "prefix" feature as used in scholia, see https://github.com/WDscholia/scholia/blob/master/scholia/app/templates/author_list-of-publications.sparql . This solves the scope problem. It can coexist with the current solution by adding an option to the template json, or by checking if the "?var" part is replaced by a prefix syntax "var:" as it is done in the "prefix" case.
  • Non exclusive, instead of replacing the bind value in only one bind replace it in all places, requires putting multiple "binds" in the query, less convenient to use.