Page MenuHomePhabricator

Simplify access to properties that currently require traversing numerous items
Open, MediumPublic


Many properties related to an item are stored in other items and are presently very hard to access by templates using wikidata. For example:

  1. taxon items have property parent taxon (P171). If I have an infobox that shows genus, family or order of a given organism I need a way to move up a chain of P171s until some rank is met.
  2. people items have property place of death (P20) that stores most exact item related to place of death, which could be a house, street, hospital, neighborhood, etc. If I have an infobox that shows place of death of a person I usually need city or town where someone died. A query to look up a city of death of Pyotr Tchaikovsky is SELECT DISTINCT ?city { ?city ^(wdt:P20/wdt:P131*) wd:Q7315; wdt:P31/wdt:P279* wd:Q515 . }. It is very hard to access that information using Lua calls. Similar issue would be for "Country of birth" or "Country of death"

I do not have a specific proposal of how to allow access to such properties. However here are 2 ideas:

  1. Create infrastructure to allow read-only properties which are not directly editable but precomputed based on some SPARQL query and other properties and items. Users would see and access them in a way similar to current properties. (Inverse properties like P910/P301 can be implemented using this mechanism in the future, where one of the properties would be "read-only")
  2. Allow Lua to do SPARQL queries. This could be expensive
  3. Other ideas?

Alternative which is happening as we speak, is to write big ugly Lua codes that are hardwired queries in disguise. They need to load multiple items to show a simple info.

Event Timeline

The lack of powerful means to traverse the Wikidata knowledge tree within Lua modules is in fact a problem for Wikidata as well, not only for module coders on Wikipedia side. {{#property:}}/{{#statement:}} parser functions and Module:Wikidata allow simple data retrieval from the connected item, but any lookup of items (as indicated by Jarekt) is very difficult. Users deal with this problem by adding all information they want to access from a client (e.g. in an infobox) directly to the connected item—even if it is utterly misplaced there (for instance country qualifiers to place of birth data in an item about a person).

The most effective method to search in the Wikidata knowledge tree is likely a SPARQL query. It would thus be very useful if a SPARQL interface for item lookup was available in Lua.

Yeah totally. We "just" need to figure out how to make this work without killing the site.

At least in eswiki we would also need a way to check if an entity or a value are from a given type (or list of types). For us it would be very useful having a way to do queries like this through Lua:

  BIND(wd:Q6012487 AS ?item)
  VALUES ?class { wd:Q386724 }
  ?item wdt:P31/wdt:P279* ?class. hint:Prior hint:gearing "forward".

Which would be called with some lua function call like mw.wikibase.checkEntityType( id, { typeId1, typeId2,... }) which would return true or false depending on the response of the query. @Lydia_Pintscher, as this is already done for the constraint check API would it be possible implementing something like this for Lua too without killing the site? Having this would simplify our transition to a single infobox template.

This use case was marked as duplicate of this task and merged into it, but I think the use case we need in eswiki is simpler to implement and that it's not the same as the one in this task.