Module talk:Wikidata

Latest comment: 2 years ago by Matěj Suchánek in topic check for qualifier value

Lua error in Module:Wikidata at line 135: attempt to concatenate field 'month' (a nil value).

edit

Acoelorraphe wrightii (Q140088), apparently after this edit. Another example Salix (Q36050). --Succu (talk) 19:49, 5 May 2015 (UTC)Reply

Pxxx of the item Qxxx from Pxxx of current item

edit

Is there a option to get Pxxx of the item Qxxx from Pxxx of current item? In other words, for infoboxes in Wikipedia is possible to easily get birth_place with {{#property:P19}}, but how to get country of birth — P17 of that settlement? --XXN, 11:58, 10 January 2016 (UTC)Reply

Consider using qualifier inside the property. See for example place of birth (P19) at Frédéric Chopin (Q1268), the country where and when he was born does not exists. Otherwise you had to create dedicated Lua script for that purpose, and fill all necessary historical data for country (P17) with qualifiers start time (P580) and end time (P582) for places. Paweł Ziemian (talk) 13:07, 10 January 2016 (UTC)Reply

Issue: getFormattedQualifiers() returns all languages for a given monolingual text qualifier

edit

I added comment (DEPRECATED) (P2315) in three languages here; on the talk page, field "Allowed values" shows all three languages (en, ru and de) where I would have expected it to display only en if my current language is en. This field is the result of this call in Module:Property documentation:

d.formatStatements{
  conjtype = '<br />',
  displayformat = 'wikidatastyle',
  entity = entity,
  lang = lang,
  property = 'P1793',   -- format as a regular expression
  showqualifiers = 'P2315'     -- comment
}

Could someone add support for some kind of "qualLang" param that could be used to select one of the languages for monolingual text qualifiers? Or is there already a scheme for that that I missed?

Thanks -- LaddΩ chat ;) 22:43, 1 February 2016 (UTC)Reply

When I looked at the doc by VIAF, I realized we could even use similar logic to {{TranslateThis}} (ie. language fallback). I will try to implement a sane way for this but I don't promise it will happen immediately (so if another one wants to do this, just go ahead). Matěj Suchánek (talk) 13:44, 2 February 2016 (UTC)Reply
  Done This behaviour is always forced now (if it's not okay, I can rewrite it). I have also made a fix for coordinates which weren't shown at all. Looks like we still need a fix for quantities with units... Matěj Suchánek (talk) 17:19, 3 February 2016 (UTC)Reply
Formidable! Thanks a lot, it works great! -- LaddΩ chat ;) 16:06, 4 February 2016 (UTC)Reply

new datatype mathematical expression

edit

see here. --Molarus 12:34, 7 February 2016 (UTC)Reply

edit

It can happens that a Wikidata model generates a link on the same page. It then is shown in bold, which might not be the wanted behavior. author  TomT0m / talk page 10:03, 15 July 2016 (UTC)Reply

Example? Matěj Suchánek (talk) 12:31, 15 July 2016 (UTC)Reply
Module talk:Wikidata?! -- Innocent bystander (talk) 07:03, 16 July 2016 (UTC)Reply
And example where the module produces this problem? Because AFAIK this module outputs either external links, or links to entities whereas it cannot be linked from any entity. Matěj Suchánek (talk) 07:30, 16 July 2016 (UTC)Reply
Hmm OK, this might be a frwiki Wikidata module peculiarity. I'll relocate this : on frwiki, this generate an internal link. author  TomT0m / talk page 07:33, 16 July 2016 (UTC)Reply

Labels and descriptions in a language without fallback

edit

If I now try Toida, I get the English label (via fallback) instead of the Dutch label as there is no Dutch label. This can be useful, but I also like to have the option if a label or description in a certain language is empty. Can this option be added to the module? Thanks! Romaine (talk) 15:57, 30 December 2016 (UTC)Reply

Done with "|fallback= - " parameter: {{#invoke:Wikidata|getLabel|entity=Q11418831|lang=nl|fallback=-}},
@Zolo: Thank you for the addition! Romaine (talk) 02:04, 4 January 2017 (UTC)Reply
Zolo: I tested it and it seems not to work completely... My interface language is set in Dutch, the item Q11418831 only has a label in English.
  1. When I do lang=nl + fallback=- (no label) I get: Lady Toida
  2. When I do only lang=nl (Toida) I get: Lady Toida
  3. When I do lang=fr + fallback=- (no label) I get: Q11418831
  4. When I do only lang=fr (Toida) I get: Lady Toida
So the outcome of case one is not right.
So my conclusion is or Dutch (nl) is just a problem, or that the fallback I get is depending on the language set in the preferences, and for the language set in the preferences it does not work well.
Also I would suggest that the given output when no label/description is available in a language when no fallback is used, the output is the same as when no label or no description is available. It normally shows: no label / no description, or in Dutch: geen label / geen omschrijving.
I hope these issues can be fixed, thanks!! Romaine (talk) 02:22, 4 January 2017 (UTC)Reply
@Romaine: Yesterday I made an update to fetching labels. Could you please check again how it works now? Matěj Suchánek (talk) 13:55, 11 February 2017 (UTC)Reply
@Matěj Suchánek: - Sorry for the delay, illness and travel was in my way. It now works great! If there is no label, with fallback=- no label is given.
When I try the same for getDescription, this does not work: With no description I do get the fallback from English. I hope this can be fixed for this too? Thanks! Romaine (talk) 13:52, 14 March 2017 (UTC)Reply
  Done Matěj Suchánek (talk) 08:54, 15 March 2017 (UTC)Reply
@Matěj Suchánek: I fixed a wrong variable name in your code change. --Bamyers99 (talk) 17:15, 15 March 2017 (UTC)Reply
Yes, thank you very much. Copy&paste is evil... Matěj Suchánek (talk) 17:39, 15 March 2017 (UTC)Reply

make use of mw.wikibase.label?

edit

This may reduce the number of expensive function calls.--GZWDer (talk) 09:19, 10 February 2017 (UTC)Reply

  Done Matěj Suchánek (talk) 21:43, 10 February 2017 (UTC)Reply

Not able to get label of property

edit

  Resolved

  • incorrect code was: {{#invoke:Wikidata|getLabel|item=P106}}
  • correct code: {{#invoke:Wikidata|getLabel|entity=P106}}

Something is wrong in documentation or code. d1g (talk) 11:34, 21 February 2017 (UTC)Reply

The documentation of getLabel only mentions entity = entity ID with its Q or P and actually, this behaviour is logical because occupation (P106) is not an item. Matěj Suchánek (talk) 15:03, 21 February 2017 (UTC)Reply
edit

  Resolved

d1g (talk) 11:47, 21 February 2017 (UTC)Reply

For getLabel, link=- should work. Matěj Suchánek (talk) 15:07, 21 February 2017 (UTC)Reply

BCE dates

edit

In Property talk:P570, the dates in BCE are displayed incorrectly (5000 instead of 5000 BCE)--GZWDer (talk) 16:38, 13 July 2017 (UTC)Reply

Lua error in Module:Wikidata at line 355: attempt to call method 'getSitelink' (a nil value).

edit

In Module:Wikidata/doc. πr2 (t • c) 15:54, 9 August 2018 (UTC)Reply

  Fixed Thanks for your report. Matěj Suchánek (talk) 17:12, 9 August 2018 (UTC)Reply

Script error: The function "formatStatements" does not exist.

edit

On wp, {{#invoke:Wikidata|formatStatements|item=Q12418|property=p186|qualifier=p518}} say "Script error: The function "formatStatements" does not exist." cdt, --Speltdecca (talk) 07:35, 17 May 2019 (UTC)Reply

Which wiki? There are plenty of Wikidata modules around, each wiki may have a different one. Matěj Suchánek (talk) 07:27, 18 May 2019 (UTC)Reply

p.getClaims returns claims

edit

Hi,

@Zolo, Pasleim, Matěj Suchánek:

The documentation says « p.getClaims returns claims » but how exactly? under which format? I did some tests and it seems to be some kind of table (or a table of table?) I'm a bit lost and some explicit explanations would be welcome.

Cheers, VIGNERON (talk) 16:17, 14 November 2019 (UTC)Reply

@VIGNERON: it returns a table of claims. Each claim is itself a table like (containing tables containing tables...), and looks like:

{ ["id"] = "Q16354758$d09b1475-46d7-bbd3-ce7a-4698212a4a99",

       ["mainsnak"] = {
         ["datatype"] = "url",
         ["datavalue"] = { ["type"] = "string", ["value"] = "https://gerrit.wikimedia.org/r/mediawiki/extensions/Wikibase.git", },
         ["property"] = "P1324",
         ["snaktype"] = "value",
       },
       ["qualifiers"] = {
         ["P2700"] = {
           {
             ["datatype"] = "wikibase-item",
               ["datavalue"] = { ["type"] = "wikibase-entityid", ["value"] = { ["entity-type"] = "item", ["id"] = "Q186055", ["numeric-id"] = 186055, }, },
               ["hash"] = "c9653c60db2ac354cb25a08c14c306afd1238d7c",
               ["property"] = "P2700",
               ["snaktype"] = "value",
           },
         },
       },
       ["qualifiers-order"] = { "P2700", },
       ["rank"] = "normal",
       ["references"] = {
         {
           ["hash"] = "ebb5373bbff11d9abd156aadbcf65ad5f97035dd",
           ["snaks"] = {
             ["P854"] = {
               { ["datatype"] = "url", ["datavalue"] = { ["type"] = "string", ["value"] = "https://www.mediawiki.org/wiki/Extension:Wikibase_Repository#Download", }, ["property"] = "P854", ["snaktype"] = "value", },
             },
           },
           ["snaks-order"] = { "P854", "P813", },
         },
       },
       ["type"] = "statement",
     },
   },

See mw:Extension:Wikibase Client/Lua#Structure-Zolo (talk) 17:23, 14 November 2019 (UTC)Reply

Thank you Zolo Cdlt, VIGNERON (talk) 19:55, 14 November 2019 (UTC)Reply

Adaptation for Schemas

edit

I just started {{EntitySchema}} based on {{P}} and noticed that the former does not display the label, leading to things like E25 as opposed to mother (P25). Poking around in the template dependencies, I ended up at Module:Wikidata, suspecting that things like the getLabel, getDescription and getLink functions might need some review and perhaps revision with schemas in mind. --Daniel Mietchen (talk) 01:06, 8 April 2020 (UTC)Reply

{{Label}} uses Module:Wikidata label. --Matěj Suchánek (talk) 08:43, 8 April 2020 (UTC)Reply
Thanks — I left a note there. --Daniel Mietchen (talk) 23:25, 8 April 2020 (UTC)Reply

Edits of late to this module

edit

@Matěj Suchánek: In light of at least two people having complained of Lua errors appearing due to a user's edits to this module over the past two days, and in light of the full protection I have applied to this module due to its frequent use across the site, would you happen to know what it is that user is trying to do, and whether there's a way of doing it that doesn't completely break templates sitewide? Mahir256 (talk) 13:47, 1 November 2020 (UTC)Reply

This is unfortunate but not unexpected. This module does simply too much, it's full of various functions and some cleanup (if this is what they attempt to do) is certainly desirable. (The worst thing is it is written for a multilingual wiki but there are maybe wikis that import it.) Which naturally comes with regressions and annoyed users. On the other hand, if the user is not willing to solve the problems here or further up the stack, full protection is an option. I don't currently have the capacity to investigate and attempt to resolve it, it's probably up to them to explain (or possibly ask for help). --Matěj Suchánek (talk) 14:31, 1 November 2020 (UTC)Reply
Thanks @Mahir256: for the intervention!
For the explanations, before your intervention I started a discussion on his talk page: User_talk:Verdy_p#Casse_du_Module:Wikidata (in French). In this discussion, I pointed a good pratice: we should have a sandbox duplicate of this module where people could work safely. If a change is not breaking anything, then it could be copied in the "real" module. Now with the protection, this solution makes even more sense to me.
Cheers," VIGNERON (talk) 15:03, 1 November 2020 (UTC)Reply
"If the user is not willing to solve the problem" is a FALSE statement of Matěj Suchánek.
There's still a bug that the revert canceled. I also had made sandbox tests. Something has changed in Lua that still causes unexpeced nil values and various pages not working correctly (with incomplate dcata), becaseu the code uses false assumptions, notably when modifying tables while there are open iteratators on them: setting a value to nil has the effect of changing the set of keys, and this breaks existing open iterators which may stop prematurely before the end of loops enumerating keys with pairs() or ipairs(), or that could unexpectedly retrieve keys with nil values: such operations are not (and have NEVER) been supported in Lua.
I tried to fix that, but the existing code is very tricky and very disorganized, with lot of false assumptions everywhere (and no real tests of its supported interface: too many functions are publicly exposed instead of being local only: this makes things very complicate to know the dependencies).
Before your last revert I had fixed everything I think, except in some existing moduiles that bypass the normal (documented) API of the Wikidata module (the problem is that there are tricks in determining the frame from where it takes its parameters, and its documentation is very defective).
And the module still has side effects as it modifies the arguments table in inconsistant ways (so it also breaks some dependant modules which recurse on these arguments: this Wikidata module does not ensure stability an immutability of its query parameters).
It's quite tricky. And there was still an very visible bug that occured (the first one being corrected without any impact anywhere, but that you reverted, then the next ones that your reverted all along).
Finding all the dependies was a work in progress (also based on sandboxed versions of modules/templates to track the uses and insert additional logging or checks). I had made many additional checks of assumptions, you have reverted all of them.
As well "p.formatSnak()" may also return nil values (unchecked) that also cause errors notably in concatenation of strings (the module incorrectly assumes that no nil values are returned, only strings). Such cases occur with properties with special values (unknown), e.g. for dates, or cause some requests to not sort their result properly (when using the sorted option: dates are not comparable if one of them is nil and have then no computed timestamp).
Really, this Wikidata module is a nightmare, it has not been properly tested as it should, and it's now back to its former state, with many bugs. Verdy p (talk) 04:52, 2 November 2020 (UTC)Reply
"If the user is not willing to solve the problem" is a FALSE statement of Matěj Suchánek. It is not. What you quoted isn't a statement, it's a part of a conditional sentence. My statement was if the user is not willing to solve the problems [...], full protection is an option. Otherwise, you've got a point there.
Do we have some list of pages which yielded errors (to be used for "Preview page with this template" feature)? Is it possible to identify which version was the last not to yield errors? --Matěj Suchánek (talk) 08:46, 2 November 2020 (UTC)Reply

Display the number of sitelinks, number of labels, number of statements, number of descriptions

edit

Is there any Lua function which could display the number of sitelinks, number of statements, number of labels, number of descriptions?

If no, would it be possible to design such a function or not? PAC2 (talk) 06:28, 16 May 2021 (UTC)Reply

check for qualifier value

edit
			local onQ5 = d.showQualifier {displayformat = 'raw',entity = entity,property = 'P2302',targetvalue = 'Q21503250', qualifier = 'P2308'}
			if onQ5 == "Q5" then 

At Module:Property documentation, I used the above to check if property constraint (P2302)=subject type constraint (Q21503250) has the qualifier class (P2308)=human (Q5).

That works except when there are several P2308. I tried adding "qualifiervalue = 'Q5'"

but somehow that fails. --- Jura 21:53, 1 February 2022 (UTC)Reply

  Fixed There was a mistake in calling a function. qualifiervalue = 'Q5' shouldn't break now. --Matěj Suchánek (talk) 08:59, 3 February 2022 (UTC)Reply
@Matěj Suchánek thanks. It no longer throws an error, but still returns all values: e.g. "Q5 and Q8436" instead of "Q5", I'd expect on Property talk:P3217 after [1]. --- Jura 12:55, 3 February 2022 (UTC)Reply
Apparently, the argument is only used for filtering the statements, but not the qualifiers. However, you are only testing for existence, you don't mean to show the stuff, so perhaps just #(d.getClaims{ ... } or {}) > 0 is sufficient. --Matěj Suchánek (talk) 15:13, 3 February 2022 (UTC)Reply
Return to "Wikidata" page.