Module talk:Wikidata

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

QID lookup from enwp article title[edit]

sub parameters[edit]

So I can request population (P1082) of a town and it appears to give me the latest values if there are multiple (which I want). Is there a way to get the associated values of that entry such as point in time (P585) and determination method (P459). Take for example d:Q316500 how would I get the values 1 August 2015 and census of the latest population figures?--Traveler100 (talk) 11:07, 23 June 2018 (UTC)

  • {{wdib|P1082|qid=Q316500|fwd=ALL|rank=best|qual=ALL}} → 227,645 (1 August 2015, CensusEdit this on Wikidata
  • {{wdib|P1082|qid=Q316500|fwd=ALL|rank=best|qual=P459}} → 227,645 (CensusEdit this on Wikidata
  • {{wdib|P1082|qid=Q316500|fwd=ALL|rank=best|qual=P585}} → 227,645 (1 August 2015) Edit this on Wikidata
  • {{wd|qualifier|Q316500|P1082|P459}} → census
  • {{wd|qualifier|Q316500|P1082|P585}} → 1 August 2015
I don't know how you want to use those values, but one or another of the above may be useful. --RexxS (talk) 19:40, 23 June 2018 (UTC)
@RexxS: Great, thanks. --Traveler100 (talk) 20:07, 23 June 2018 (UTC)

Problem with special characters in template[edit]

When retrieving coordinates from Wikidata they are handled differently in string module functions like sub and find than when the equivalent text is input (working on template to convert to decimal then work out distances between places).

  • Correctly {{#invoke:Wikidata|getValueFromID|Q85|P625|FETCH_WIKIDATA}} → 30°3'22"N, 31°14'22"E
  • Correctly {{#invoke:String|len|30°3'22"N, 31°14'22"E}} → 21
  • Incorrectly {{#invoke:String|len|s={{#invoke:Wikidata|getValueFromID|Q85|P625|FETCH_WIKIDATA}} }} → 37
  • Correctly {{#invoke:String|find|source=30°3'22"N, 31°14'22"E |target=,}} → 10
  • Incorrectly {{#invoke:String|find|source={{#invoke:Wikidata|getValueFromID|Q85|P625|FETCH_WIKIDATA}} |target=,}} → 18

Can someone explain why this is happening and more importantly how I can fix it? --Traveler100 (talk) 05:06, 27 July 2018 (UTC)

The why is that the Wikidata module is actually returning:
30°3'22"N, 31°14'22"E
I'm not sure how best to fix it. Johnuniq (talk) 06:08, 27 July 2018 (UTC)
Module:Coordinates already has conversion functions, so you could use those. Jc86035 (talk) 07:04, 27 July 2018 (UTC)
Sound like a better solution, what is the syntax though? --Traveler100 (talk) 07:20, 27 July 2018 (UTC)
  • {{#invoke:Coordinates | dms2dec |30°3'22"N, 31°14'22"E|lat}}Lua error in Module:Coordinates at line 235: attempt to perform arithmetic on local 'degrees' (a nil value).
  • {{#invoke:Coordinates | dms2dec |{{#invoke:Wikidata|getValueFromID|Q85|P625|FETCH_WIKIDATA}}|lat}}Lua error in Module:Coordinates at line 235: attempt to perform arithmetic on local 'degrees' (a nil value).
  • {{#invoke:Coordinates | dms2dec |30°3'22"N|lat}}Lua error in Module:Coordinates at line 235: attempt to perform arithmetic on local 'degrees' (a nil value).
@Traveler100: Where is this needed? What is the purpose? Can you give an example of an article that you would want to change (or at least, where you want to change the wikitext)? Johnuniq (talk) 07:26, 27 July 2018 (UTC)
@Traveler100: You can also use Module:WikidataCoord and the coord2text function of Module:Coordinates. You shouldn't really need to do most of this, though. Jc86035 (talk) 09:55, 27 July 2018 (UTC)
I will take a look at that. Actually working on Wikivoyage articles. We are finding that often there is an error with the coordinates of towns on Wikidata (often when extracted from Russian Wikipedia) and the Geo values in Wikivoyage articles are better. Was setting up a check to see where there is a difference and highlight them for fixing. See voy:Template:Geo/sandbox. --Traveler100 (talk) 10:36, 27 July 2018 (UTC)
The getValueFromID function in Module:Wikidata returns the raw values stored in Wikidata for coordinates, which means that html entities are returned. The newer getValue function from Module:WikidataIB substitutes the actual characters °, ', ".
  • {{#invoke:WikidataIB |getValue |qid=Q85 |P625 |fwd=ALL |osd=no |noicon=true}} → 30°3′22″N 31°14′22″E
  • {{#invoke:String|len|s={{#invoke:WikidataIB |getValue |qid=Q85 |P625 |fwd=ALL |osd=no |noicon=true}} }} → 20
However, it uses just the space to separate latitude and longitude, not a comma and a space. --RexxS (talk) 13:24, 27 July 2018 (UTC)

Preferred rank[edit]

The documentation says the module only fetches preferred-rank values if some are marked as preferred, but it doesn't seem to work like that. e.g.:


gives Bach's entire list of occupations rather than the preferred-rank ones only:

composer, organist, harpsichordist, violinist[*], violist[*], conductor, choir director[*], concertmaster, musicologist[*], music pedagogue[*], virtuoso, musician

Is there are recent change which removed this functionality? Deryck C. 15:03, 20 August 2018 (UTC)

@Deryck: I don't know the answer to that question, but while somebody is sorting that out, you could use Module:WikidataIB:
{{#invoke:WikidataIB |getValue |qid=Q1339 |P106 |fwd=ALL |osd=no}}Composer, Organist, Harpsichordist, violinist, violist, Conductor, choir director, Concertmaster, musicologist, music pedagogue, Virtuoso, Musician Edit this on Wikidata
{{#invoke:WikidataIB |getValue |qid=Q1339 |P106 |fwd=ALL |osd=no |rank=best}}Composer Edit this on Wikidata
That also has all of its links pointing to Wikipedia, not Wikidata. Cheers. --RexxS (talk) 15:21, 20 August 2018 (UTC)
@RexxS: What does WikidataIB do if the item label is a redlink on the site? Deryck C. 15:34, 20 August 2018 (UTC)
  1. If the Wikidata item has a sitelink, it strips disambiguators and uses that as the displayed text, linked to the full sitelink.
  2. If there is no sitelink, but there is a label, it checks the local Wikipedia to see if there is a redirect with the same text as the label. If so, it links to the redirect.
  3. If the label is not a redirect, it returns the unlinked label.
  4. If there is no sitelink or label, it returns the entity-ID (e.g. Q12345) and puts the article in the Category:Articles with missing Wikidata information.
Does that make sense? --RexxS (talk) 15:47, 20 August 2018 (UTC)
@RexxS: Yep. And does it try to fetch a label from another language if the local language doesn't have a label? Deryck C. 10:44, 21 August 2018 (UTC)
@Deryck: Not explicitly. The normal language fallback is implemented (e.g. zh-mo → zh-hk → zh-hant → zh-hans → en), but I haven't written code to offer anything beyond that for a couple of reasons. There's no collection of sitelinks or labels available via the api exposed to Lua. That means we would have to load the entire entity and scan what is there - very inefficient and screws up watchlists. Additionally, there's no good algorithm that I've been able to come up with which would determine which label to return if more than one existed. Cheers --RexxS (talk) 16:40, 21 August 2018 (UTC)
That's totally fine - it's good to know there is some language fallback so if I use this of the Cantonese Wikipedia it'll try to scan some other languages (most importantly zh and en) before giving up and displaying the Q-number! Deryck C. 16:50, 21 August 2018 (UTC)