मोड्युल:PopulationFromWikidata
This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected. |
Reason for the module
सम्पादन गर्नुहोस्The aim is to make it easier to keep population values (and associated references) up-to-date in Australian place article Infoboxes. This module looks at population claims in a linked Wikidata item and filters for the latest and most appropriate population value. It extracts this value, along with all referencing information, and gives this to the article Infobox.
Who made the module
सम्पादन गर्नुहोस्Wikimedia Australia designed this project to coincide with the first release of the 2021 census data (in June 2022). This module was created as part of a funded project with work done by m:User:MaiaCWilliams in collaboration with (really...HUGE amounts of help from) User:Samwilson, User:99of9 and User:Canley. The project was coordinated by User:tenniscourtisland.
It is an ongoing project and we will continue to refine the module. Of course anyone is welcome to contribute!
Head to the Module_talk:PopulationFromWikidata page if you have anything to discuss.
We wrote a summary of the project for the Wikimedia Australia blog here.
What the module does
सम्पादन गर्नुहोस्Population sources
सम्पादन गर्नुहोस्The module is designed to be invoked from the Infobox Australian place template and gathers data from the Wikidata item linked to each article. The module may be modified and used in other places/cases in the future.
Currently, this module is invoked in such a way that it will only give the Infobox a population figure if one isn't manually given for the Infobox Australian place pop argument. This means that initially the module will not impact many articles. Over time, once we're certain it is working well, we can remove the manually added population figures in favour of the Wikidata figures brought in by the module.
See line 110 of the Infobox Australian place template for the module invoke.
How to see the module in action
सम्पादन गर्नुहोस्Currently the module will only give a population figure to the Infobox if one has not been manually added via the Infobox Australian place template pop field. This means if you want to see the module in action for a particular place article, you should follow these steps:
- Pick a Wikipedia place article and check that the linked Wikidata item has a valid population claim (most now do, but some values will be old because not all 2021 Census data has been released yet).
- If the Wikidata item looks good, then edit the Infobox Australian place template part of the article. Remove the pop value and replace with a comment like: “<!--Leave blank to draw the latest automatically from Wikidata-->”. Remove the pop_year and pop_footnotes fields. Check if the old pop_footnotes reference had been used elsewhere in the article.
- Check the output in the article Infobox. If the output is not as expected then edit the Wikidata item or if it’s really broken, get in touch here.
Here's an example of an article with Infobox using the module, and the diff of the edit made.
The list of articles using population values from Wikidata (via this module) is here.
Assumptions
सम्पादन गर्नुहोस्The module works with the following assumptions:
- That all Australian place Wikipedia articles are linked to relevant Wikidata items (true because Canley and 99of9 have done this work).
- Relying on the type field of the Infobox Australian place template being a required field and assuming it always has a value specified.
- We're only considering population values associated with the Australian Bureau of Statistics' defined Australian Statistical Geographic Standard areas.
- Assuming that the linked Wikidata item will likely have population statements for multiple Australian Bureau of Statistics geographic areas that encompass the item place.
- We’re ignoring any ranking of population statements.
Population selection
सम्पादन गर्नुहोस्The high level steps of the module work flow are outlined in the diagram below. There are three major steps in the process of selecting the best population figure from a Wikidata item.
Step 1. Check which population claims have enough information to be considered
सम्पादन गर्नुहोस्As a minimum they are required to have:
- A point in time qualifier date (this helps to choose the most recent population figures).
- An applies to part qualifier value (this states which ABS geography type the population is for and helps choose the most appropriate geographic area for the place article).
- A determination method qualifier item (this specifies if it is a census population figure or a non-census population estimate and helps define the reference components).
- Some reference information (it is a requirement to have something with which to build a reference but more than the minimum is recommended - see the Population data in Wikidata section).
After filtering for these requirements a subset of population claims is carried forward.
Step 2. Check which population claims match the Infobox Australian place type value
सम्पादन गर्नुहोस्The next part of the module separates the valid population claims into those which have applies to part values (defined ABS geography types) that match the Infobox type and those that don't. For the Infobox types that can map to multiple ABS geography types (eg. type = town), the most common mapping is considered a match initially and the other mappings are considered later in the module if the first preference isn't available. For example, type = town is matched to Urban Centres and Localities (UCL) as a first preference, but also returns population values for Suburbs and Localities (SAL) and Indigenous Locations (ILOC) instead, if they exist.
The mappings are based on outputs of summary SPARQL queries pulling out Infobox place type versus ABS geography types specified in linked Wikidata item (for all Australian place articles). The module uses the following mappings.
Infobox type | ABS geographic area |
---|---|
City | Urban Centres and Localities (UCL) |
Suburb | Suburbs and Localities (SAL) |
Town | Urban Centres and Localities (UCL) (or SAL or Indigenous Locations (ILOC)) |
LGA | Local Government Areas (LGA) |
Region | Local Government Areas (LGA) (for now) |
Step 3. Check which population claims have the most recent figures
सम्पादन गर्नुहोस्The next step is to check within the two sets of claims (applies to part geography matched or not) and find the most recent population figure per each applies to part value. For example, in the list of claims with applies to part geography not matching the Infobox, there are likely multiple applies to part values (UCL, SA1 etc) and multiple point in time values (2006, 2011, 2016 etc). This step finds the most recent population figures for each geography type (eg 2016 UCL; 2021 SA1).
There are then three different types of outputs depending on the outcomes of the Step 2 and Step 3 filtering.
Step 3A. Outputs for claims with geography match to Infobox type
सम्पादन गर्नुहोस्This is Output Scenario 1 and gives the Infobox one formatted population figure, with the relevant applies to part, point in time year and full Cite web reference(s). Eg. 5,089 (Suburb and Locality 2021)[1]
Step 3B Towns. Second preference output for Infobox type = town
सम्पादन गर्नुहोस्This is Output Scenario 2 and gives the Infobox up to two formatted population figures, each with the relevant applies to part, point in time year and full Cite web reference(s). This happens when there is no valid UCL population claim and is the second preference output for type = town places. E.g.
- 100 (Urban Centre and Locality 2021)[1]
OR
- 90 (Indigenous Location 2021)[1]
- 100 (Suburb and Locality 2021)[2]
Step 3B. Outputs for claims with no geography match to Infobox type
सम्पादन गर्नुहोस्This is Output Scenario 3 and gives the Infobox (possibly) multiple formatted population figures (one for each applies to part value), each with the relevant applies to part, point in time year and full Cite web reference(s). Eg. If Infobox type = city that's mapped to UCL (ands leads to Output Scenario 1), but if there're no UCL population values you might get this output:
- 100 (GCCSA 2021)[1]
- 100 (SUA 2016)[2]
- 120 (SA1 2016)[3]
References
सम्पादन गर्नुहोस्The references are formatted using the Cite web template.
The census population figure references take this form: Australian Bureau of Statistics (28 June 2022). "Cosmo Newberry (Indigenous Locations)". Australian Census 2021 QuickStats. Retrieved 28 June 2022.
The non-census derived population figure references take this form: Australian Bureau of Statistics (29 March 2022). "Population estimates by SA2 and above, 2001 to 2021 (Greater Capital City Statistical Areas)". Australian Regional Population. Retrieved 28 June 2022.
The references are named, using this method (for now): name = refwork.."_"..pointintime.."_"..appliespart.."_"..reftitle. This is long-winded because we are aiming for a unique reference name for each population value.
Module work flow diagram (draft)
सम्पादन गर्नुहोस्
Example outputs
सम्पादन गर्नुहोस्There are some example outputs in the Infobox Australian place Sandbox Test Cases page here.
What it doesn't do - next steps
सम्पादन गर्नुहोस्There are some issues that we are aware of, have considered but haven't dealt with yet. These will be tackled in time in collaboration with other place article contributors. (No doubt there are many more to add to the list - please do).
- Some tidying up the output within the infobox:
removing unnecessary bullet points when there's only one itemadd links to information about the relevant Censusadding tooltip descriptionchange geography to abbreviation- adding links to explanations of ABS geographic boundaries (add this info to the Census articles and link to sections there)
- Make a table of historic population values (from those available in Wikidata and that meet other module criteria) and test this as a new addition to place articles. As part of possible methods of preserving historic population figures in articles. Possibly a better solution than having multiple old values listed in Infoboxes (eg. Basket_Range,_South_Australia) or having to maintain individually in-text? Not the same idea, but there is a table of historic population values listed in this article).
- Figure out the case of two Infoboxes: Jimbour East, Queensland
- Suppress the population figures for protected areas. (eg, no output for type = protected). Yes?
- Population density figures need to be computed and added to the Infobox using the same population (and area from corresponding geography) as this module outputs now. With area data uploaded to Wikidata?
- Test that city rank can still be displayed in the Infobox if population coming from the module.
- How to integrate (merge correctly) named references from the module with those used in-text. And how to retain historic population values (and references) as the Infobox population automatically updates with the most current figures. The module produces named references that are unique to the population value, but there are currently reference merging bugs associated with references from templates (and modules).
- Should we change it so that pop2 still displays even if pop is replaced by the module population? So you can have both the automated population and a specific other population that's relevant to the article for some reason.
- Add some more documentation to Wikipedia:WikiProject Australian places/Population data.
- Figure out interactions with the Coord template that's used in the majority of Australian place articles. The Coord template takes a population argument and uses that to determine the display scale of the Coordinates interactive map. Should we make an equivalent module (similar to this one) to bring place coordinates (with appropriate map zoom scales) from Wikidata to the Infobox Australian place template? Then the coordinates (and map scale) can be kept up-to-date with Wikidata. This would require parallel work to determine most appropriate place coordinate definition (eg centroid? of which geographic area?) so coordinates can be bulk imported to Wikidata? Or just rely on people adding the coordinates values to Wikidata manually but cut out the need to use the Coord template to set map zoom scale? Or keep using the Coord template but give it the appropriate population value as selected by (a modified version) of this PopulationFromWikidata module.
- Connect Aboriginal and Torres Strait Islander community Wikidata items with ABS ILOC IDs so ILOC population counts can be uploaded in bulk. Will then need to revisit the ILOC vs SAL preferencing because for some towns ILOC will be more appropriate than SAL (due to geographic area covered).
- Need to revisit mapping of regions to ABS geographies. Maybe they should be mapped to SA3s? Eg: Kimberley region article Also, need to update this article and other equivalents.
- Discrepancy with places with zero population, such as Essendon Fields (Q5399482):
- In QuickStats it says: "No information can be provided because the area selected had no people or a very low population in the 2021 Census."
- But it does have data in Wikidata (population 13, for SAL20886, which is what is in the DataPack).
- This means that the reference URL ends up not backing up the displayed population figure.
- There may be a difference in how this is handled between 2016 and 2021. For example, (Q55771929) has zero population and doesn't show in either 2016 or 2021 QuickStats — but (Q7859816) had 3 people in 2016 (shown in QuickStats) and 4 people in 2021 (not shown in QuickStats). Both places have both figures in the DataPack.
What if the outputs are incorrect
सम्पादन गर्नुहोस्All the references produced by this module are followed by an Edit at Wikidata pencil icon with link the relevant Wikidata item (and specific population claim). This is where people should go to fix any errors in the population figure outputs or references. See next section for lists of what should ideally be included in a Wikidata population claim.
Population data in Wikidata
सम्पादन गर्नुहोस्Wikipedia - Wikidata links
सम्पादन गर्नुहोस्In parallel to development of this module User:99of9 and User:Canley have been working on ensuring all Australian place Wikipedia articles are linked to corresponding Wikidata items (describing that same place). This has largely been done. This enables the use of this module.
Census data
सम्पादन गर्नुहोस्Population data has historically been manually entered to individual Wikidata items. Recently (since ~2017) User:99of9, User:Canley and others have used QuickStatements to do bulk imports of population data from Australian Bureau of Statistics datasets. Part of developing this module was to refine the list of metadata (qualifiers and reference fields) that should be imported alongside the population values.
As at July 2022 the first release of the 2021 census population data has been uploaded for the geographic areas relevant to Australian place Infoboxes. This includes data for Suburbs and Localities (SAL), Indigenous Locations (ILOC) and Local Government Areas (LGA). The Urban Centres and Localities (UCL) data is due to be released in October 2022.
The module requires these qualifiers and reference components to have values in the Wikidata population claim.
- applies to part
- point in time
- determination method
- reference: reference URL
- reference: title
- reference: published in
- reference: retrieved
- reference: Australian Statistical Geography 2021 ID (optional)
An example of a Wikidata item with a correctly filled 2021 population claim (using Census data) is:d:Q2821571#P1082.
Non-census data
सम्पादन गर्नुहोस्Bulk uploads have been done for census data. They have not been done for between-census estimated residential population (ERP) or Data by Region figures, for example. These estimates are useful for capital cities, LGAs and regions.
The module requires that non-census population claims have these components:
- applies to part
- point in time
- determination method
- reference: reference URL
- reference: title
- reference: published in
- reference: retrieved
- reference: publication date
- reference: Australian Statistical Geography 2021 ID (optional)
An example of a Wikidata item with a correctly filled 2021 estimated resident population claim (not the other population claims) is:d:Q11568#P1082. An example of a Wikidata item with a correctly filled 2020 LGA Data by Region population claim (not the other population claims) is:d:Q704257#P1082.
Usage
सम्पादन गर्नुहोस्The module exposes one function.
ListForInfobox( type, wikidata )
सम्पादन गर्नुहोस्{{#invoke:PopulationFromWikidata |ListForInfobox |type=t |wikidata=w }}
Parameters:
|type=
thetype
parameter from {{Infobox Australian place}}. Required.|wikidata=
Wikidata ID to override that of the current article. Optional.
---------------- Defining variables--------------------
local Pop_P = "P1082" -- population property
local Applies_P = "P518" -- applies to part property
local Pointin_P = "P585" -- point in time property
local DetMeth_P = "P459" -- determination method property
local RefURL_P = "P854" -- reference URL
local RefTitle_P = "P1476" -- reference title
local RefPubIn_P = "P1433" --reference published in property
local DatePub_P = "P577" -- date of publication property
local Publisher_P = "P123" -- publisher property
local Retrieved_P = "P813" -- retrieved property
local CensusAU_I = "Q5058971" -- Australian census item
local Instof_P = "P31" -- instance of property
local ShortN_P = "P1813" -- short name property
local SAL_I = "Q33112019" -- state suburb item (includes SSC and SAL)
--local GCCSA_I = "Q112762887" -- Greater Capital City Statistical Area item
local LGA_I = "Q33127844" -- Local Government Area item
local UCL_I = "Q33127891" -- Urban Centre or Locality
--local SA2_I = "Q33128776" -- SA2
local ILOC_I = "Q112729549" -- Indigenous Location
local item = nil
--------------- Function GetRefsForClaim to check, collate and format all the reference components----------------------
function GetRefsForClaim(claim, defaulttitle)
local refs = ""
for b,x in pairs(claim.references) do -- Loop through all references in a claim and pull out the components
local refurl = "" -- initialise an empty URL, check if there is one then populate with the actual value (if not it stays as an empty string)
if claim.references[b].snaks[RefURL_P] ~= nil then
refurl = claim.references[b].snaks[RefURL_P][1].datavalue.value
end
local reftitle = defaulttitle -- Initialise the default title as the Wikidata item title. This is the fallback title if one isn't provided in the references
if claim.references[b].snaks[RefTitle_P] ~= nil then
reftitle = claim.references[b].snaks[RefTitle_P][1].datavalue.value.text
end
local detmet = mw.wikibase.getEntity(claim.qualifiers[DetMeth_P][1].datavalue.value.id) -- Get the dertermination method item
local pubinlabel = "" --Initalising an empty published in label. This is the last option for this value.
if claim.references[b].snaks[RefPubIn_P] ~= nil then --Checking if the published in part of reference exists (it should for all references)
local pubin = mw.wikibase.getEntity(claim.references[b].snaks[RefPubIn_P][1].datavalue.value.id) --If it does then grab the published item and the label of that item
pubinlabel = pubin.labels.en.value
end
local refwork = pubinlabel -- This value is used for non-census references, or as a fall-back value for census references with missing parts
local pubdate = "" -- This is the fallback option if published date is missing (no date)
if claim.references[b].snaks[DatePub_P] ~= nil then -- This is the second option for the published date (given with references - this is used for non-census references)
pubdate = mw.language.getContentLanguage():formatDate('j F Y', claim.references[b].snaks[DatePub_P][1].datavalue.value.time)
end
if detmet.claims[Instof_P] ~=nil and detmet.claims[Instof_P][1].mainsnak.datavalue.value.id == CensusAU_I then -- Checking for census references (which will have different refwork and published date sources)
refwork = detmet.labels.en.value.." "..pubinlabel -- Concatenating to get work - determination method + published in (this overwrites the refwork value for census references)
if detmet.claims[DatePub_P] ~=nil then
pubdate = mw.language.getContentLanguage():formatDate('j F Y', detmet.claims[DatePub_P][1].mainsnak.datavalue.value.time) -- Overwrite the published date value if the determination method item has a date published (for census references)
end
end
local refpublisher = "" -- The publisher is empty if missing
if detmet.claims[Publisher_P] ~= nil then
local publisheritem = mw.wikibase.getEntity(detmet.claims[Publisher_P][1].mainsnak.datavalue.value.id) -- Get the determination method item and the publisher item ID
refpublisher = publisheritem.labels.en.value -- Get the label of the publisher item
end
local refaccessdate = "" -- The retrieved date fallback is empty
if claim.references[b].snaks[Retrieved_P] ~= nil then
refaccessdate = mw.language.getContentLanguage():formatDate('j F Y', claim.references[b].snaks[Retrieved_P][1].datavalue.value.time) -- Populate the retrieved date if it's there
end
local appliespart = mw.wikibase.getEntity(claim.qualifiers[Applies_P][1].datavalue.value.id).labels.en.value -- The ABS geography type for the particular claim (to use in reference name)
local pointintime = mw.language.getContentLanguage():formatDate('Y', claim.qualifiers[Pointin_P][1].datavalue.value.time) -- Getting the point in time as a YYYY (to use in the reference name)
local citewebargs = { --Putting all the cite_web arguments into a list (for a single reference)
url = refurl,
title = reftitle.." ("..appliespart..")" ,
date = pubdate,
work = refwork,
author = "[["..refpublisher.."]]", -- Changed the publisher to author for now to match existing population references
accessdate = refaccessdate
}
local wdeditpencil = mw.getCurrentFrame():expandTemplate{title = 'EditAtWikidata', args = {qid = item.id, pid = claim.id, nbsp = 1}} --Call the Edit At Wikidata template (to add the edit pencil to end of references)
local reference = mw.getCurrentFrame():expandTemplate{ title = 'cite web', args = citewebargs } --expand template to feed arguments to cite_web
refs = refs..mw.getCurrentFrame():extensionTag{ name = 'ref', content = reference..wdeditpencil, { name = refwork.."_"..pointintime.."_"..appliespart.."_"..reftitle } } --Add the reference from this iteration to the list of references for this particular claim
end
return refs -- List of references to be given to reflist
end
---------------This is a function for getting the population geography abbreviation and the Wikipedia article link for the population year ---------------
function GetAbbrLabelYearLink(returnclaim)
local appliespartitem = mw.wikibase.getEntity(returnclaim.qualifiers[Applies_P][1].datavalue.value.id) -- This gets the item ID for the current claim Applied to Part value
local abbrelabel = appliespartitem.labels.en.value -- This is the fall back value for the geography label if no abbreviation (short name) value exists in Wikidata item
if appliespartitem.claims[ShortN_P] ~= nil then -- If a short name value exists then use thi value instead of the full item label.
abbrelabel = mw.getCurrentFrame():expandTemplate{title = 'Abbr', args = {appliespartitem.claims[ShortN_P][1].mainsnak.datavalue.value.text , appliespartitem.labels.en.value }} -- Output the abbreviated name with tooltip showing the full label
end
local year = string.sub(returnclaim.qualifiers[Pointin_P][1].datavalue.value.time, 2, 5) -- Get the population point in time as a year string
local yearreturn = year -- If no links to Wikipedia articles describing population determination method exist then just output year
local detmetitem = mw.wikibase.getEntity(returnclaim.qualifiers[DetMeth_P][1].datavalue.value.id) -- Get the current claim determination method item
if detmetitem.sitelinks ~=nil and detmetitem.sitelinks.enwiki ~=nil then -- Check if the determination method item has an enwiki URL
yearreturn = "[["..detmetitem.sitelinks.enwiki.title.."|".. year.."]]" -- If it does, use this URL as the link with the year value
elseif detmetitem.claims[Instof_P] ~=nil and detmetitem.claims[Instof_P][1].mainsnak.datavalue.value.id == CensusAU_I then -- If there isn't a populated enwiki URL for determination method item AND it's a census determination method then...
yearreturn = "[[Census_in_Australia#"..year.."|".. year.."]]" -- ... return the population year linked to the corresponding section of the Census in Australia article
end
return abbrelabel.." "..yearreturn -- Join the geography abbreviation to the year (with link) ready for the final output
end
---------------- This ListForInfobox function is being used to grab the correct population value ---------------
local p = {}
function p.ListForInfobox( frame )
local luaplacetype = "" --Initialise the local place type
if frame.args.type == nil then
return ""
end
local articleplacetype = string.lower(frame.args.type) -- Bring in the place type entered into Infobox Australian place template, change to a lower case string
if articleplacetype == "town" then -- Check which place type and match to the equivalent ABS geographic area "city", "suburb", "town", "lga", "region"
luaplacetype = UCL_I
elseif articleplacetype == "suburb" then
luaplacetype = SAL_I
elseif articleplacetype == "city" then
luaplacetype = UCL_I
elseif articleplacetype == "lga" then
luaplacetype = LGA_I
elseif articleplacetype == "region" then -- for now saying region == LGA_I... but unclear what is most apprpriate ABS geography type.... can revise
luaplacetype = LGA_I
end
if frame.args.wikidata ~= nil and frame.args.wikidata ~= "" then -- checking if there's a linked Wikidata item for the article
item = mw.wikibase.getEntity(frame.args.wikidata) -- this is the default item specified by the wikidata parameter in the template
else
item = mw.wikibase.getEntity() -- If there's a Wikidata item connected to the article it will find it here.
end
-- mw.logObject(item)
--------------- CHECK: If item.claims[Pop_P] is nil. If it is return an empty string ----------------------
if item == nil or item.claims[Pop_P] == nil then
return ""
end
------------ PART 1: Find claims with (1) point in time is not nil, (2) applies to part is not nil, (3) determination method is not nil and (4) References table is not empty-------------
local validpopclaims = {} --initialise the blank claim table for storing all population claims that satisfy the four conditions
z=0 -- initialise the table row count
for j, s in pairs(item.claims[Pop_P]) do
if s.qualifiers ~= nil and
s.qualifiers[Pointin_P]~= nil and
s.qualifiers[Applies_P] ~= nil and
s.qualifiers[DetMeth_P] ~= nil and
s.references ~= nil then
z=z+1
validpopclaims[z]=s -- give the claim a new key in the table
end
end
--------------- CHECK: If count of validpopclaims is less than one (eg 0) then return a html message. This checks we have something from which to get a population value and basic reference.--------------
if #validpopclaims <1 then
return ""
end
--------------- PART 2: Compare claim 'applies to part' values against template place type-------------------------
local templategeog = {} --initialise the blank claim table for if the template type matches to Wikidata claim applies to part
local othergeog = {} --initialise the blank claim table for when the template type doesn't match Wikidata claims applies to part
local c=0
local d=0
for i, q in pairs(validpopclaims) do
if q.qualifiers[Applies_P][1].datavalue.value.id == luaplacetype then --filter for claims where applies to part = Infobox template type
c=c+1 -- give the claim a new key in the table
templategeog[c]=q -- claims with Infobox template type geography
else
d=d+1
othergeog[d]=q -- claims with geography other than specified in the Infobox template type.
end
end
----------PART 3: Get claims with the maximum 'Point in time' values ------------------
----------PART 3A: Find the max date of claims with template geography-----------------
local maxclaimspertemplategeog = nil --initialise the blank claim corresponding to the max date
for k, v in pairs(templategeog) do --loop through all the claims with geography type = Infobox template type
local tclaimdate = v.qualifiers[Pointin_P][1].datavalue.value.time
if maxclaimspertemplategeog == nil
or (maxclaimspertemplategeog ~= nil
and tclaimdate >= maxclaimspertemplategeog.qualifiers[Pointin_P][1].datavalue.value.time)
then
maxclaimspertemplategeog=v
end
end
----------PART 3B: Find the max date of claims with non-Infobox template geography-----------------
local maxclaimsperothergeog = {}
for l, m in pairs(othergeog) do --loop through all the claims with geography type = non Infobox place type
local oclaimdate = m.qualifiers[Pointin_P][1].datavalue.value.time
local claimgeog = m.qualifiers[Applies_P][1].datavalue.value.id
if maxclaimsperothergeog[claimgeog] == nil -- using the applies to part value as the table key
or (maxclaimsperothergeog[claimgeog] ~= nil
and oclaimdate >= maxclaimsperothergeog[claimgeog].qualifiers[Pointin_P][1].datavalue.value.time) -- checking the max date for a particular geography value
then
maxclaimsperothergeog[claimgeog]=m -- overwrites with a geography-max date claim pair whenever the point in time is bigger than the last iteration.
end
end
------------------------------Compiling the module output--------------------------------
local returnlist = {} -- Initiate an empty table to store the output claims
if maxclaimspertemplategeog ~=nil then -- Situation 1: Getting population for max date claim where applies to part matches the Infobox place type
local templategeogrefs = GetRefsForClaim(maxclaimspertemplategeog, item.labels.en.value) -- Getting the references for max date claim where Wikidata applies to part matches the Infobox place type
table.insert (returnlist, mw.language.getContentLanguage():formatNum(tonumber(maxclaimspertemplategeog.mainsnak.datavalue.value.amount)).." ("..GetAbbrLabelYearLink(maxclaimspertemplategeog)..")"..templategeogrefs) --Insert the return string to returnlist. With population value, applies to part, point in time, reference
elseif articleplacetype == "town" then -- Situation 2: Getting population for max date claims where Infobox place type = town. If no UCL populations (earlier default) then get ILOC and SAL populations.
if maxclaimsperothergeog[ILOC_I]~=nil then
local ILOCrefs = GetRefsForClaim(maxclaimsperothergeog[ILOC_I], item.labels.en.value) -- Getting the references for max date claim where applies to part = ILOC
table.insert (returnlist, mw.language.getContentLanguage():formatNum(tonumber(maxclaimsperothergeog[ILOC_I].mainsnak.datavalue.value.amount)).." ("..GetAbbrLabelYearLink(maxclaimsperothergeog[ILOC_I])..")"..ILOCrefs) --Insert the return string to returnlist. With population value, applies to part, point in time, reference
end
if maxclaimsperothergeog[SAL_I]~=nil then
local SALrefs = GetRefsForClaim(maxclaimsperothergeog[SAL_I], item.labels.en.value) -- Getting the references for max date claim where applies to part = SAL
table.insert (returnlist, mw.language.getContentLanguage():formatNum(tonumber(maxclaimsperothergeog[SAL_I].mainsnak.datavalue.value.amount)).." ("..GetAbbrLabelYearLink(maxclaimsperothergeog[SAL_I])..")"..SALrefs) --Insert the return string to returnlist. With population value, applies to part, point in time, reference
end
else
for a, w in pairs(maxclaimsperothergeog) do -- Situation 3: Getting population for max date claims where applies to part doesn't = Infobox place type, and Infobox place type doesn't = town.
local othergeogrefs = GetRefsForClaim(w, item.labels.en.value) -- Loop through the claims in maxclaimsperothergeog and output all of them
table.insert (returnlist, mw.language.getContentLanguage():formatNum(tonumber(maxclaimsperothergeog[a].mainsnak.datavalue.value.amount)).." ("..GetAbbrLabelYearLink(maxclaimsperothergeog[a])..")"..othergeogrefs) --Insert the return string to returnlist. With population value, applies to part, point in time, reference
end
end
local wikitext = "" -- Initialise an empty string output (this is the value that goes back to the Infobox Australian place)
if #returnlist == 1 then -- If there is only one formatted "population (geography year)" string (one row) in returnlist then return it without a bullet point
wikitext = returnlist[1]
else
wikitext = "\n*"..table.concat(returnlist,"\n*") -- If there are multiple formatted "population (geography year)" strings (multiple rows) in returnlist then return all the rows with new line and bullet points between them
end
return wikitext..'[[Category:Australian place articles using Wikidata population values]]' -- Append the category to the output so we can keep track of which articles are using this module to output a population value
end
return p