Module:Convert/wikidata: Difference between revisions

Content deleted Content added
 
(4 intermediate revisions by 2 users not shown)
Line 215:
-- very likely that any decision a module makes about how to handle data
-- will be wrong for some cases at some time. This meets current requirements.
-- For each qualifier (or if no qualitiferqualifier), if there are any preferred
-- statements, use them and ignore any normal statements.
-- For each qualifier, for the preferred statements if any, or for
Line 277:
end
 
local function input_from_text(tdata, parms, text, insert2)
-- Given string should be of form "<value><space><unit>". or
-- "<value1><space>ft<space><value2><space>in" for a special case (feet and inches).
-- Return value,true ucodeif (twovalues/units strings)were extracted and inserted, or return nothing.
text = text:gsub('&nbsp;', ' '):gsub(' %s+', ' ')
local pos = text:find(' ', 1, true)
if pos then
Line 286 ⟶ 287:
local value = text:sub(1, pos - 1)
local uid = text:sub(pos + 1)
if uid:sub(1, 3) == 'ft ' and uid:sub(-3) == ' in' then
local ucode = make_unit(tdata.wikidata_units, parms, uid)
-- Special case for enwiki to allow {{convert|input=5 ft 10+1/2 in}}
return value, ucode or uid
insert2(uid:sub(4, -4), 'in')
insert2(value, 'ft')
else
local ucode = insert2(value, make_unit(tdata.wikidata_units, parms, uid) or uid)
end
return true
end
end
Line 300 ⟶ 307:
local text = parms.input -- should be a trimmed, non-empty string
local pid = text:match('^P%d+$')
local sep = ','
local sep = parms.test == '#' and '#' or ',' -- LATER remove test when decide what is wanted
local special = specials[parms[index]]
if special then
Line 310 ⟶ 317:
return false, pid and { 'cvt_no_output' } or { 'cvt_bad_input', text }
end
local function insertinsert2(first, second)
table.insert(parms, index, second)
table.insert(parms, index, first)
Line 330 ⟶ 337:
end
local item = ucode
if item == parms[index] then
-- Remove specified output unit if it is the same as the Wikidata unit.
-- For example, {{convert|input=P2044|km}} with property "12 km".
table.remove(parms, index)
end
for i = result.n, 1, -1 do
insertinsert2(result[i][1], item)
item = sep
end
return true
else
local amount, ucode =if input_from_text(tdata, parms, text, insert2) then
if amount and ucode then
insert(amount, ucode)
return true
end
Line 473 ⟶ 483:
end
if k == 'label' then
local wdl = mw.wikibase.labelgetLabel(key)
if wdl ~= value then
note:add('label changed to ' .. tostring(wdl))