Module:PrevalenceData: Difference between revisions

Content deleted Content added
m Protected "Module:PrevalenceData": Highly visible template ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))
catch pages that have no connected WIkidata entity
 
(3 intermediate revisions by 2 users not shown)
Line 1:
-- This module is specifically the Wikidata property "prevalence" (P1193), due
-- to its particular need for ranges and area-based qualifiers, and the lack of
-- support for these in the main Wikidata module.
 
-- Completely untested.
local p = {}
 
--local wikidata = require( 'Module:Wikidata' )
 
p.main = function ( frame )
--local entityqid = mwframe.wikibaseargs.getEntity(qId 'Q133087'or )""
localif entityqid == "" then qid = mw.wikibase.getEntitygetEntityIdForCurrentPage( frame.args.qId or nil ) end
if entitynot qid then return nil end
local prevalenceClaims = entitymw.claimswikibase.getBestStatements(qid, and entity.claims."P1193")
local pRange = ''
-- TODO: Get best claim, not always just the first one.
-- Run through all prevalence claims - the table prevalenceClaims always exists but may be empty
-- Probably use getBestStatements.
if for i, prevalenceClaim in ipairs( prevalenceClaims then) do
local prevalenceValue = prevalenceClaim.mainsnak.datavalue and prevalenceClaim.mainsnak.datavalue.value
local pRange = ''
if prevalenceValue then
-- Run through all prevalence claims
if string.len( pRange ) > 0 then
for i, prevalenceClaim in pairs( prevalenceClaims ) do
-- Split multiple claims
local prevalenceValue = prevalenceClaim.mainsnak.datavalue.value
-- Maybe line break instead?
if prevalenceValue then
ifpRange string.len(= pRange ) >.. 0', then'
end
-- Split multiple claims
if prevalenceValue.lowerBound ~=and prevalenceValue.upperBound then
-- Maybe line break instead?
local lowerBound = prevalenceValue.lowerBound * 100
pRange = pRange .. ', '
local upperBound = prevalenceValue.upperBound * 100
end
local lowerBoundpRange = prevalenceValuepRange .. lowerBound * 100
localif upperBoundlowerBound ~= prevalenceValue.upperBound * 100then
pRange = pRange .. lowerBound'—' .. upperBound
end
if lowerBound ~= upperBound then
else
pRange = pRange .. ' to ' .. upperBound
local amount = prevalenceValue.amount * 100
end
pRange = pRange .. amount
end
pRange = pRange .. '%'
if prevalenceClaim.qualifiers then
-- Qualifiers for prevalence are currently unstandardized.
-- Keep guessing until the right one is found.
local quals = prevalenceClaim.qualifiers.P276 or -- ___location
prevalenceClaim.qualifiers.P1001 or -- applies to jurisdiction
prevalenceClaim.qualifiers.P17 -- country
if quals then
pRange = pRange .. ' ('
for k, qual in pairs(quals) do
if k > 1 then
pRange = pRange .. ', '
end
local qualId = qual.datavalue.value[ 'numeric-id' ]
local link = mw.wikibase.sitelink( 'Q' .. qualId )
local label = ({
-- Certain geographic locales might need a
-- manual-ish override for labels.
[ 132453 ] = 'developed world'
})[ qualId ] or mw.wikibase.label( 'Q' .. qualId )
if link then
label = '[[' .. link .. '|' .. label .. ']]'
end
pRange = pRange .. label
end
pRange = pRange .. ')'
end
local qualId = qual.datavalue.value[ 'numeric-id' ]
local link = mw.wikibase.sitelink( 'Q' .. qualId )
local label = ({
-- Certain geographic locales might need a
-- manual-ish override for labels.
[ 132453 ] = 'developed world'
})[ qualId ] or mw.wikibase.label( 'Q' .. qualId )
if link then
label = '[[' .. link .. '|' .. label .. ']]'
end
pRange = pRange .. ' to ' .. upperBoundlabel
end
pRange = pRange .. ', )'
end
--[[
-- Todo: References
if prevalenceClaim.references then
end
]]--
end
return pRange
end
--[[ Todo: References
if prevalenceClaim.references then
end
--[[]]
end
return ''pRange
end