Page MenuHomePhabricator

Create the easy function mw.wikibase.property('P21', 'Q8023', 'en')
Closed, ResolvedPublic

Description

The purpose of the proposed task is to simplify for Lua coders the use of wikibase. Otherwise, they could search and test for days or weeks.

This property function gets the sought property from any available element and language and returns its value if available.
Otherwise, as usual in scribunto, it returns zero and the module displays an error or changes the requested language...
The simplest use is to request only the property keyword like "image" or "lastname"...
This function gets also pseudo properties: "description", "label", "title", "QITEM" like "Q34743", and "sitelink" like "Author:Rudyard Kipling".

The QITEM argument can be the id like "Q535" or the title or the label of another sought item. "Q" asks the property for the current page.

The value of the default property is returned in the content of the calling page. The module can request it in any language.
For a value in the content or page or language of the user, use "content" or "page" or "user".
For simplicity of use, the module can request languages in descending priority in 2 formats: "user; content; en, de, es" or {'user', 'content', 'en', 'de', ' es',}

Examples:

local prop1 = mw.wikibase.property('P21') -- Simplest use
local prop2 = mw.wikibase.property('lastname') -- Named pseudo property
local prop3 = mw.wikibase.property('label', 'Q', { 'user', 'page', 'content', 'en', 'de', 'es', } ) -- Default values
local prop4 = mw.wikibase.property('description', 'Nelson Mandela', { 'user', 'fr', } ) -- other case

Event Timeline

Aklapper changed the task status from Open to Stalled.Jan 23 2018, 2:01 PM

Where should this function be created? MediaWiki API? Somewhere in Wikidata/Wikibase? How is this function called?
This task misses any steps to reproduce.
Please see and follow https://mediawiki.org/wiki/How_to_report_a_bug to structure your tasks, no matter if bug reports or feature requests.

Aklapper changed the task status from Stalled to Open.Jan 26 2018, 9:40 PM
Aklapper added a project: Wikidata.

I agree. This request is poorly specified. For one, labels, descriptions, and sitelinks are not properties. Also how should these property values be handled? There are many property data types where the data is not necessarily a single scalar value. Also property claims can have unknown or no value in addition to a value. This ignores what to do when there are multiple property claims for the same property (or any comment about ranks) and is unclear how qualifiers or references should or should not be handled by this interface (although the second line in the description of this task quotes a qualifier access).

I also disagree with the perception that traversals of statements, claims, qualifiers, references, or snaks are somehow heavy and/or hazardous. This is semi-structured data and as such it is nontrivial to traverse without a semi-structured query language (e.g., SPARQL, XPath, etc.). We already have large Lua convenience libraries for processing these data. Short of adding some sort of query language to the Wikibase client Scribunto interface, I do not see this as something that is missing (unless I am somehow misunderstanding the request).

@Uzume, first, thank your for your attention. You are right this new function is not accurately defined.
The keypoint is to give at Lua coders a simple and standardised way to acces all datas.
Probably many points are to discuss.
Labels, descriptions, sitelinks ... help Lua coders like true properties.
If a property as no value the function returns nil and the coder adapt the module.
For multiple value a table-sequence could replace a simple value, then coders can easy adapt their modules.
Also ranks could be add as arguments to select the admissible confidence need by the module, from RANK_PREFERRED to RANK_DEPRECATED?
Perhaps we could add a composite option argument to define ranks, snaks.
In snaks, ['Claims'] is necessary in the internal struture of the base but not for Lua coders.
In snaks, if the property P123 is repeated why ask the second at the Lua coders.
Do you known a better place to discuss all these and others questions?

I have no issue with discussion and I believe this an adequate forum for such a discussion. My point was your requests are significantly lacking (and need discussion and focus) before they can be considered for possible implementation.

We already have many of the facilities you mention, for example, getBestStatements(eid, pid) to obtain the best statements (by rank). Also if you need something more than that we have many Scribunto Lua libraries to simplify such things.

FYI: I would not want to return nil when where is a stated "no value" as that is inherently different than the lack of a claim.

thiemowmde triaged this task as Lowest priority.Feb 12 2018, 3:00 PM
thiemowmde subscribed.

I would love to include this into what we consider for T182147: more convenience functions for Lua. But I'm afraid the current description is more confusing than helpful.

  • It starts with an example that accesses a qualifier, but never picks this up again.
  • The suggested function is called "property". I believe this does not refer to the entity type we also call "property", but to some property (a.k.a. feature) of some element in the Wikibase data model.
  • What should be returned when you call mw.wikibase.property( 'P21' ) with a property name? It would need to be an array of statements, as there can be multiple with the same property ID.
  • What exactly are { 'user', 'page', 'content', 'en', 'de', 'es', } and { 'user', 'fr' } in the examples? It looks like these lists mix language codes with something else. I believe the strings that are not language codes refer to the users language, the page language, as well as the wikis language. The later two are typically (but not always) identical.
  • Again, what is returned when calling the function like this? A single label as a string? An array of labels?

I'm afraid a multi-purpose function like this that can be called in so many different ways, and will return many different things depending on how it is called, is outside of our scope. The community is free to create something like this (and already did similar things), but the Wikidata team is most probably not able to do this for the community.

Can you please help us by collecting the individual use cases that drive this request here, so we can consider them for T182147?

For some weeks in Module:Central, this function use:

function datas.property(pp) -- Get datas from mw.wikibase for one property of the page.
    datas.QITEM      = mw.wikibase.getEntityIdForCurrentPage() -- like "Q42"
    datas.item       = mw.wikibase.getEntity(QITEM)
    pp.label         = datas.item:getLabel.QITEM)
    pp.sitelink      = datas.item:getSitelink()
    pp.labelwithlang = datas.item:getLabelWithLang()
    pp.description   = mw.wikibase.description.QITEM) 
    pp.labelbylang   = mw.wikibase.getLabelByLang(QITEM)
    pp.labelcontent  = mw.wikibase.getLabelByLang(, langs.content_lan, QITEM)
    pp.labelpage     = mw.wikibase.getLabelByLang(, langs.page_lan, QITEM)
    pp.labeluser     = mw.wikibase.getLabelByLang(, langs.user_lan, QITEM)
    pp.val           = datas.item:formatPropertyValues( pp.prop ) -- like "P123"
     ...
    return pp
end

This code example is quite unfortunate. It works around all performance optimizations the Wikidata team implemented in the past weeks and months. Is this from a Lua module actually used somewhere, and if so, can you please provide a link?

Thanks for updating this tasks description. Unfortunately I still don't understand the idea behind the majority of what you are suggesting. For example, what is mw.wikibase.property( 'P21' ) supposed to return? What should be returned when all the method gets is a Q-ID? Whats the difference to the existing mw.wikibase.getEntityObject( 'Q34743' )? How would you distinguish between the pseudo-property "label" and a property that's actually called "label"? What is "Q", and how do you distinguish this from https://www.wikidata.org/wiki/Q9950?

{F13706389}

What are the use cases you have in mind? I really think we need to go back multiple steps, away from specific suggestions, and collect your use cases first. Can you please provide links to specific templates and explain the features they need?

Each call of datas.property(pp) defines one property in the pp table.
The calling process contains a table to define all eventual properties.

p.args_known = { -- Table of the definitions of all known arguments at module level. 
    -- All arguments have a keyword identical to the registration name, except synonyms.
    ["country"]		= { ["typ"] = "dat", ["need"] = 0, ["keyword"] = "country", ["prop"] = "P27", },
    ["countryRANK"]	= { ["typ"] = "dat", ["need"] = 0, ["keyword"] = "country", ["prop"] = "P27", ["RANK"] = "RANK_NORMAL", },
    ["birthyear"]	= { ["typ"] = "dat", ["need"] = 2, ["keyword"] = "birthyear", ["prop"] = "P569", ["format"] = "year", },
    ["deathyear"]	= { ["typ"] = "dat", ["need"] = 2, ["keyword"] = "deathyear", ["prop"] = "P570", ["format"] = "year", },
    ["lastname"]	= { ["typ"] = "dat", ["need"] = 0, ["keyword"] = "lastname", ["prop"] = "P734", },
    ["lastname2"]	= { ["typ"] = "dat", ["need"] = 0, ["keyword"] = "lastname", ["prop"] = "P734", ["syn"] = 2, },
    ["firstname"]	= { ["typ"] = "dat", ["need"] = 0, ["keyword"] = "firstname", ["prop"] = "P735", },
    ["firstname2"]	= { ["typ"] = "dat", ["need"] = 0, ["keyword"] = "firstname", ["prop"] = "P735", ["syn"] = 2, },
    ["title"]		= { ["typ"] = "dat", ["need"] = 2, ["keyword"] = "label", ["prop"] = "P735", ["syn"] = 2, },
    ["personlang"]	= { ["typ"] = "dat", ["need"] = 2, ["keyword"] = "personlang", ["prop"] = "P1412", },
    ["QITEM"]		= { ["typ"] = "dat", ["need"] = 2, ["keyword"] = "QITEM", ["prop"] = "Q16222597", },
    ["label"]		= { ["typ"] = "dat", ["need"] = 0, ["keyword"] = "label", ["prop"] = "label", },
    ["sitelink"]	= { ["typ"] = "dat", ["need"] = 0, ["keyword"] = "sitelink", ["prop"] = "sitelink", },
    ["description"]	= { ["typ"] = "dat", ["need"] = 2, ["keyword"] = "description", ["prop"] = "description", },
    }

I have used this structure for years and have change it when I need or when new mw.wikibase functions have appeared.
This code is in the very heavy
https://fr.wikisource.org/wiki/Module:Central-s-fr
If you need I could code a dedicated small test module.

Where is this used, and how?

I would love to suggest looking into https://en.wikipedia.org/wiki/SOLID_(object-oriented_design), and related.

Rical claimed this task.

The status of this function is enough advance in Central modules to close it.