Module:PrevalenceData: Difference between revisions
Appearance
Content deleted Content added
←Created page with '-- This module is specifically the Wikidata property "prevalence" (P1193), due -- to its particular need for ranges and area-based qualifiers, and the lack of --...' |
No edit summary |
||
Line 5: | Line 5: | ||
-- Completely untested. |
-- Completely untested. |
||
local p = {} |
local p = {} |
||
--local wikidata = require( 'Module:Wikidata' ) |
|||
p.main = function ( frame ) |
p.main = function ( frame ) |
||
--local entity = mw.wikibase.getEntity( 'Q133087' ) |
|||
local entity = mw.wikibase.getEntity( frame.args.qId or nil ) |
local entity = mw.wikibase.getEntity( frame.args.qId or nil ) |
||
if entity then |
if entity then |
||
local prevalenceClaims = entity.claims.P1193 |
local prevalenceClaims = entity.claims.P1193 |
||
-- TODO: Get best claim, not always just the first one. |
-- TODO: Get best claim, not always just the first one. |
||
-- Probably use getBestStatements. |
|||
local prevalenceClaim = prevalenceClaims and prevalenceClaims[ 1 ] |
local prevalenceClaim = prevalenceClaims and prevalenceClaims[ 1 ] |
||
mw.logObject( prevalenceClaims[ 1 ] ) |
|||
if prevalenceClaim then |
if prevalenceClaim then |
||
local prevalenceValue = prevalenceClaim.mainsnak.datavalue.value |
local prevalenceValue = prevalenceClaim.mainsnak.datavalue.value |
||
mw.logObject( prevalenceValue ) |
|||
if prevalenceValue then |
if prevalenceValue then |
||
mw.log( prevalenceValue.upperBound * 100 ) |
|||
local lowerBound = prevalenceValue.lowerBound * 100 |
local lowerBound = prevalenceValue.lowerBound * 100 |
||
local upperBound = prevalenceValue.upperBound * 100 |
local upperBound = prevalenceValue.upperBound * 100 |
||
Line 35: | Line 36: | ||
pRange = pRange .. ' (' |
pRange = pRange .. ' (' |
||
for k, qual in pairs(quals) do |
for k, qual in pairs(quals) do |
||
mw.log( k, 123 ) |
|||
⚫ | |||
if k > 1 then |
if k > 1 then |
||
pRange = pRange .. ', ' |
pRange = pRange .. ', ' |
||
Line 54: | Line 53: | ||
end |
end |
||
pRange = pRange .. ')' |
pRange = pRange .. ')' |
||
⚫ | |||
end |
end |
||
end |
end |
||
--[[ |
|||
-- Todo: References |
|||
if prevalenceClaim.references then |
|||
⚫ | |||
end |
|||
]]-- |
|||
⚫ | |||
end |
end |
||
end |
end |
||
end |
end |
||
return '' |
|||
end |
end |
||
Revision as of 22:31, 18 February 2016
This module is specifically for 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. It is used by Template:infobox medical condition.
-- 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 entity = mw.wikibase.getEntity( 'Q133087' )
local entity = mw.wikibase.getEntity( frame.args.qId or nil )
if entity then
local prevalenceClaims = entity.claims.P1193
-- TODO: Get best claim, not always just the first one.
-- Probably use getBestStatements.
local prevalenceClaim = prevalenceClaims and prevalenceClaims[ 1 ]
if prevalenceClaim then
local prevalenceValue = prevalenceClaim.mainsnak.datavalue.value
if prevalenceValue then
local lowerBound = prevalenceValue.lowerBound * 100
local upperBound = prevalenceValue.upperBound * 100
local pRange = lowerBound
if lowerBound ~= upperBound then
pRange = pRange .. ' to ' .. upperBound
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
end
--[[
-- Todo: References
if prevalenceClaim.references then
end
]]--
return pRange
end
end
end
return ''
end
return p