「モジュール:Core」の版間の差分

split core.parseStatements into 2 functions
(1版 をインポートしました)
bsd>Jarekt
(split core.parseStatements into 2 functions)
290行目: 290行目:
for _, statement in ipairs(statements) do
for _, statement in ipairs(statements) do
if (statement.mainsnak.snaktype == "value") and (statement.rank ~= 'deprecated')  then
if (statement.mainsnak.snaktype == "value") and (statement.rank ~= 'deprecated')  then
local val = statement.mainsnak.datavalue.value
table.insert(output, core.parseSnak(statement.mainsnak, lang))
if val.id then
val = val.id
if lang ~= nil then
val = core.getLabel(val, lang)
end
elseif val.text then
val = val.text
elseif val.amount then
val = tonumber(val.amount)
end
table.insert(output, val)
end
end
end
end
if #output==0 then return nil end
if #output==0 then return nil end
return output
return output
end
-------------------------------------------------------------------------------
--[[
parse part of the statement called "snak"
Inputs:
1: snak -
2: lang - language code (like "en"), if provided than item IDs will be
    changed to a label
Output:
* string
]]
function core.parseSnak(snak, lang)
local val = snak.datavalue.value
if val.id then
val = val.id
if lang ~= nil then
val = core.getLabel(val, lang)
end
elseif val.text then
val = val.text
elseif val.amount then
val = tonumber(val.amount)
elseif val.time then -- handle most dates (use [[Module:Wikidata date]] for the rest
local gregorian = 'http://www.wikidata.org/entity/Q1985727'
if (val.calendarmodel==gregorian) and (mw.ustring.sub(val.time,1,1)=='+') and val.precision >= 9 then
local trim = 3*math.min(val.precision,11) - 22 -- day (11)->11, month (10)->8, year (9)->5
val = mw.ustring.sub(val.time, 2, trim)    -- return YYYY-MM-DD, YYYY-MM or YYYY depending on precission
end
end
return val
end
end


return core
return core
匿名利用者