Module:PrevalenceData: Difference between revisions

Content deleted Content added
Remove commented-out code, comments at top (moved to doc page), and "untested" warning (it's used in a high-risk template. Does that not count as "tested" enought?)
catch pages that have no connected WIkidata entity
 
(2 intermediate revisions by the same user not shown)
Line 2:
 
p.main = function ( frame )
local entityqid = mw.wikibase.getEntity( frame.args.qId or nil )""
if qid == "" then qid = mw.wikibase.getEntityIdForCurrentPage() end
if entity then
if not qid then return nil end
local prevalenceClaims = entity.claims and entity.claims.P1193
local prevalenceClaims = mw.wikibase.getBestStatements(qid, "P1193")
-- TODO: Get best claim, not always just the first one.
local pRange = ''
-- Probably use getBestStatements.
-- Run through all prevalence claims - the table prevalenceClaims always exists but may be empty
if prevalenceClaims then
for i, prevalenceClaim in pairsipairs( prevalenceClaims ) do
local pRange = ''
local prevalenceValue = prevalenceClaim.mainsnak.datavalue and prevalenceClaim.mainsnak.datavalue.value
-- Run through all prevalence claims
if prevalenceValue then
for i, prevalenceClaim in pairs( prevalenceClaims ) do
if string.len( pRange ) > 0 then
local prevalenceValue = prevalenceClaim.mainsnak.datavalue.value
-- Split multiple claims
if prevalenceValue then
-- Maybe line break instead?
if string.len( pRange ) > 0 then
--pRange Split= multiplepRange claims.. ', '
end
-- Maybe line break instead?
if prevalenceValue.lowerBound ~=and prevalenceValue.upperBound then
pRange = pRange .. ', '
local upperBoundlowerBound = prevalenceValue.upperBoundlowerBound * 100
end
local lowerBoundupperBound = prevalenceValue.lowerBoundupperBound * 100
pRange = pRange .. lowerBound
local upperBound = prevalenceValue.upperBound * 100
if lowerBound ~= upperBound then
pRange = pRange .. lowerBound
pRange = pRange .. ' to ' .. upperBound
if lowerBound ~= upperBound then
end
pRange = pRange .. ' to ' .. upperBound
endelse
local amount = prevalenceValue.amount * 100
pRange = pRange .. '%'amount
end
if prevalenceClaim.qualifiers then
pRange = pRange .. '%'
-- Qualifiers for prevalence are currently unstandardized.
if prevalenceClaim.qualifiers then
-- Keep guessing until the right one is found.
-- Qualifiers for prevalence are currently unstandardized.
local quals = prevalenceClaim.qualifiers.P276 or -- ___location
-- Keep guessing until the right one is found.
prevalenceClaim.qualifiers.P1001 or -- applies to jurisdiction
local quals = prevalenceClaim.qualifiers.P17 P276 or -- country___location
prevalenceClaim.qualifiers.P1001 or -- applies to jurisdiction
if quals then
local quals = prevalenceClaim.qualifiers.P276P17 or -- ___locationcountry
pRange = pRange .. ' ('
forif k, qual in pairs(quals) dothen
ifpRange k= >pRange 1.. then' ('
pRangefor =k, pRangequal ..in ',pairs(quals) 'do
endif k > 1 then
local qualIdpRange = qualpRange .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 qualslink then
label = '[[' .. link .. '|' .. label .. ']]'
end
pRange = pRange .. ' ('label
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