Module talk:Wd
This is the talk page for discussing improvements to the Wd module. |
|
Archives: 1Auto-archiving period: 90 days ![]() |
![]() | Wikidata | |||
|
![]() | Use Wikipedia talk:Wikidata for general Wikidata support discussions. |
Related pages |
---|
Not most recent value if point-in-time is missing for one of the values
{{wd|properties|Q180445|P1240|P585}}
-> 2, 3
gave 2,3, i.e. two values. I want the most recent value, 3, which is from point-in-time 2019, and is the last in the list. I have tried the current, normal, normal+, best and single options but none of them helps. Probably because the older and first value in the list does not have a point-in-time (P585). My only solution is to apply {{last word}}, which gives 3. But that is an ugly solution - the most recently entered value is to my understanding typically but not always the last in the list, and should be the default if there is no timing info. However, your module gives the correct date if I enter
{{#invoke:wd|qualifier|normal+|single|Q180445|P1240|P585}}}
-> September 2019.
(I would prefer a y or yyyy option to only get the year. Now I have to apply {{last word}} to get the year.) I need value and date separated from each other, since the value is visualized graphically, and need to be sure that correct date is shown for correct value. [edited afterwards]
Tomastvivlaren (talk) 02:07, 23 November 2019 (UTC)
- We're always dependent on the quality of the data in Wikidata for accuracy. We can make assumptions, but those are often also inaccurate. Assuming that the claim that was added last is the most up-to-date, for example, does not always hold if historic information was added later. Instead, Wikidata offers tools that allow us to select the most relevant information. In this case the rank tool can be used to mark 3 as the preferred claim. This module sorts claims based on this rank, from preferred to deprecated, so you will see that
{{wd|property|Q180445|P1240}}
[-> 2 ] returns the preferred value. - The qualifier command gives the date value that you want since that is the only matching qualifier it could find. If claim 2 also had a qualifier of the same type, then that would also be returned. You could even use the (raw) qualifier value to select the claim that you want, but that is not a reliable solution since claim 2 could be assigned the qualifier in the future. Instead, the best way to go is to set the preferred rank in Wikidata which I just did.
- Regarding the date, you could also do this:
{{#time:Y|{{wd|qualifier|raw|Q180445|P1240|P585}}}}
[ -> 2019 ]. If you want to get the value together with the year (and{{wd|property|qualifier|Q180445|P1240|P585}}
[ -> 2 ], which also returns the month, is not good enough), then you could make two separate calls to construct value+qualifier. However, it's then depending on the rank and the presence of the qualifier if it is selected from the same claim as the value, so it would be best to keep it in a single call (like the{{wd|property|qualifier|...
I just gave). And then an option to get only the year would indeed come in handy. I'll put it on my to-do list. Thayts ••• 12:36, 23 November 2019 (UTC) [I added the current code response in your answer, within brackets]
- Thankyou user:Thayts for prompt reply. However, then a bot should change the ranking to preferred value on thousands of Wikidata Items, or add point-in-time to the old values. If I restore the ranking for this item, the problem seems to return. You have not considered an option that allows the user to omit values without point-in-time - or to default prioritize those values that have a point-in-time? At Swedish Wikipedia, I just found out that the Swedish sv:module:Wikidata2 offers such an option, and solves my problem for now. At other wikipedias, where Wikidata2 is not installed, I really would like to use your module. (It is a petty that different Wikipedias cannot agree on a standardized set of modules, and that every Wikipedia has its own local culture regarding what module that people expect us to use.) Tomastvivlaren (talk) 23:42, 23 November 2019 (UTC)
- @Tomastvivlaren and Thayts: Hello! I have been trying to solkve exactly the same issue. For Covid-19 related articles it would be very useful to get the current, most recent property using the Wd module. Properties like P1120 (death counts) are updated every day for hundreds of items via the quickstatements tool, which does not support prefferred rank. It would be great for standardizing sources in the covid-19 situation if we could retrieve the latest (or highest) modification. TiagoLubiana (talk) 11:35, 27 April 2020 (UTC)
Maxvals & inverted
Hi, I have two question :
First question :
{{#invoke:wd|properties|normal+|Q55|P1082}} display :"17,942,942, 10,026,773, 16,779,575, 16,829,289, 17,000,000, 17,081,507, 17,181,084, 17,282,163, 17,407,585, 17,590,672",
how can I display just three first number for to have just : "17,181,084, 16,829,289, 16,779,575" ?
I have unsuccessfully tested "maxvals" and "numval" :
{{#invoke:wd|properties|normal+|Q55|P1082|maxvals=3}} (display ever :"17,942,942, 10,026,773, 16,779,575, 16,829,289, 17,000,000, 17,081,507, 17,181,084, 17,282,163, 17,407,585, 17,590,672")
and
{{#invoke:wd|properties|normal+|Q55|P1082|numval=3}} (display ever :"17,942,942, 10,026,773, 16,779,575, 16,829,289, 17,000,000, 17,081,507, 17,181,084, 17,282,163, 17,407,585, 17,590,672")
Second question :
{{#invoke:wd|properties|normal+|Q55|P1082}} display :"17,942,942, 10,026,773, 16,779,575, 16,829,289, 17,000,000, 17,081,507, 17,181,084, 17,282,163, 17,407,585, 17,590,672",
how can I to reverse the chronological order for to display : "17,132,854 17,000,000, 10,026,773, 16,779,575, 16,829,289, 17,181,084" ?
I have unsuccessfully tested "sorttype = inverted" :
{{#invoke:wd|properties|normal+|Q55|P1082|sorttype = inverted}} (display ever :"17,942,942, 10,026,773, 16,779,575, 16,829,289, 17,000,000, 17,081,507, 17,181,084, 17,282,163, 17,407,585, 17,590,672")
My project is to do this table on page https://fr.wikipedia.org/wiki/Épidémie_de_maladie_à_coronavirus_de_2020_en_France#Localisation_des_cas to https://en.wikipedia.org/wiki/2020_coronavirus_outbreak_in_France.
Thanks, --Viruscorona2020 (talk) 05:09, 10 March 2020 (UTC)--Viruscorona2020 (talk) 05:05, 10 March 2020 (UTC)
- Both are currently not possible, although you can create a template that achieves the first like this:
{{#titleparts:{{#invoke:wd|properties|normal+|Q55|P1082|sep%s=/|sep=}}|1|1}}, {{#titleparts:{{#invoke:wd|properties|normal+|Q55|P1082|sep%s=/|sep=}}|1|2}}, {{#titleparts:{{#invoke:wd|properties|normal+|Q55|P1082|sep%s=/|sep=}}|1|3}}
- ↓
- 17,942,942, 10,026,773, 16,779,575
- I'm actually working on a sort function, but not sure when that'll be done as it's quite complicated. Thayts ••• 18:39, 14 March 2020 (UTC)
- @Thayts: Hi! I just wanted to say thank your for this powerful and awesome module, and I really hope you get that sorting function sorted out soon. Having it would make it possible to efficiently use the latest data for the pandemic (thus allowing international collaboration and saving so much volunteer effort) and being able to autogenerate graphs (with Module:Graph) about the pandemic (and so many other graphs, of course). I understand that doing the functionality properly may be complicated, but isn't there a chance to do a not-so-proper solution for the time being (one that only sorts per point-in-time, for example, rather than any arbitrary qualifier)? Thanks, really. Sophivorus (talk) 19:22, 18 April 2020 (UTC)
- Actually I was able to produce a reasonable graph, so sorry for my rash comment. Still sorting would be great, cheers! Sophivorus (talk) 22:10, 18 April 2020 (UTC)
- Great! Yes, it would indeed be great, but it's far from trivial to implement because of the many different datatypes that I suddenly need to take into account and the data model that is currently string-based. But I'll see if I will continue work on that soon again. Thayts ••• 22:49, 18 April 2020 (UTC)
- Actually I was able to produce a reasonable graph, so sorry for my rash comment. Still sorting would be great, cheers! Sophivorus (talk) 22:10, 18 April 2020 (UTC)
- @Thayts: Hi! I just wanted to say thank your for this powerful and awesome module, and I really hope you get that sorting function sorted out soon. Having it would make it possible to efficiently use the latest data for the pandemic (thus allowing international collaboration and saving so much volunteer effort) and being able to autogenerate graphs (with Module:Graph) about the pandemic (and so many other graphs, of course). I understand that doing the functionality properly may be complicated, but isn't there a chance to do a not-so-proper solution for the time being (one that only sorts per point-in-time, for example, rather than any arbitrary qualifier)? Thanks, really. Sophivorus (talk) 19:22, 18 April 2020 (UTC)
Merge i18n and aliasesP
Hi! First of all let me say this module is awesome, super thanks to the developers! I just ported it to the Spanish Wikipedia and it's going great. The thing that surprised me the most, though, was the separation between Module:Wd/i18n and Module:Wd/aliasesP. It seems unnecessary to me and even counterproductive for easy and effective localization. So I'm thinking about merging them as my first contribution to this module (I'm an experienced developer and have some experience with modules too). However, before I do anything, I'd like to ask more experienced contributors if there's some reason for keeping them separated that maybe I'm not seeing. Thanks! Sophivorus (talk) 11:25, 15 April 2020 (UTC)
- @Sophivorus: Thanks! The separation exists because they serve different purposes. Module:Wd/aliasesP used to be integrated in Module:Wd, but then I wanted to make use of the aliases list in Module:Wd/i18n too so I took it out of the main module. Module:Wd/aliasesP is not dependent on locale, so it doesn't really fit in an internationalization submodule. That's why I made it a separate submodule. Thayts ••• 22:47, 18 April 2020 (UTC)
- Actually, I figured we don't need to have the aliasesP in a separate submodule. So I've made an update to include it in the main module again and requested to delete Module:Wd/aliasesP. Thayts ••• 10:49, 19 April 2020 (UTC)
Seeking newest value, rather than current value
It looks like the configuration flags currently prioritize future, then current, then past values for values that have a start time/end time qualifier. But I'm trying to fetch the most recent result for a value that instead has a point in time qualifier. Is there any way to do that, and if not, could that functionality be added? {{u|Sdkb}} talk 06:59, 31 July 2020 (UTC)
- I'm working on a more generic function to sort on any qualifier (or the property value itself), with which this can also be achieved. I'll let you know once it's available. Thayts ••• 18:37, 8 August 2020 (UTC)
- Thayts, thanks, that sounds great; please do give me a ping when it's ready! {{u|Sdkb}} talk 18:45, 8 August 2020 (UTC)
Unable to fetch reference properly
For Q7227384, I'm trying to fetch the reference for the most recent (preferred rank) value of "employees" with the qualifier "applies to part, aspect, or form" equal to "faculty member" (i.e., I'm trying to fetch the reference for the current number of faculty members, as opposed to administrative staff). I was able to get the number of faculty via {{wikidata|property|normal+|current|P1128|P518=Q5428874|page=Pomona College}}
, but trying to use {{wikidata|reference|normal+|current|P1128|P518=Q5428874|page=Pomona College}}
returns all the references for the faculty count (although not the ones for administrative staff), not just the most recent, preferred rank one. I think this may be a bug, since the documentation here says that using "reference" rather than "references" should only return a single value. Help, anyone? {{u|Sdkb}} talk 04:37, 14 August 2020 (UTC)
- Sdkb,
reference
only returns a single value per claim. To access only one claim, use thesingle
flag like so: {{wikidata|reference|normal+|current|single|P1128|P518=Q5428874|page=Pomona College}}
- This was indeed not properly documented, so I've improved that. Thayts ••• 08:32, 14 August 2020 (UTC)
- Thayts, that works; thanks! {{u|Sdkb}} talk 08:41, 14 August 2020 (UTC)
When importing into local wiki, error getGlobalSiteID nil value
Can anyone head me in the right direction to fix the error on this module when I import it into my own wiki?
Lua error in Module:Wd at line 196: attempt to call field 'getSiteGlobalId' (a nil value).
The line in question has this code:
cfg.siteID = mw.wikibase.getGlobalSiteId()
I have wikibase installed and seemingly working. In my LocalSettings.php I have the following definition for all of my local language wikis:
$wgWBClientSettings['siteGlobalID'] = $wikiId;
Where $wikiId resolves to the language identifier "en", "es", "it", "fr", "de", "pt", etc. My Wikibase is working and I can set interwiki language links just fine.
Why could the LUA script for this module be choking at this point?
I don't have any experience with LUA, I know PHP and Javascript, jQuery, some Java and C++, .NET... But I'm seeing there is a LUA console for debugging purposes when editing the module page. So I tried logging some values on my local wiki:
mw.log(mw.wikibase)
tells me that mw.wikibase is a table
mw.logObject(mw.wikibase)
tells me that in fact the function getGlobalSiteID doesn't exist:
["getEntityUrl"] = function#12,
["getLabel"] = function#13,
Whereas if I log the same on the wikipedia module page, I see:
["getEntityUrl"] = function#12,
["getGlobalSiteId"] = function#13,
["getLabel"] = function#14,
Doing a little more research, I see that the getGlobalSiteId function should be defined by the Wikibase client Lua module, see [1]https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua#mw.wikibase.getGlobalSiteId.
I wonder then why my Wikibase doesn't have this definition?