Modul:Wikidata utilities: Unterschied zwischen den Versionen

+labelFct
K (Korrektur)
(+labelFct)
Zeile 6: Zeile 6:
serial = '2020-10-01',
serial = '2020-10-01',
item  = 65439025
item  = 65439025
}
-- i18n
local wd = {
version = 'P348'
}
}


Zeile 220: Zeile 225:
end
end


local function analyzeDatavalue( datavalue )
local function analyzeDatavalue( datavalue, labelFct, ... )
local v = datavalue.value
local v = datavalue.value
local t = datavalue.type
local t = datavalue.type
Zeile 227: Zeile 232:
if t == 'wikibase-entityid' then
if t == 'wikibase-entityid' then
v = v.id
v = v.id
if type( labelFct ) == 'function' then
v = labelFct( v, ... )
end
elseif t == 'quantity' then
elseif t == 'quantity' then
if v.unit == '1' then
if v.unit == '1' then
Zeile 244: Zeile 252:
function wu.getValuesWithQualifiers( entity, p, qualifiers, count, labelFct, ... )
function wu.getValuesWithQualifiers( entity, p, qualifiers, count, labelFct, ... )
local array
local array
local function toQualifierTable( key, qualTab )
local function toQualifierTable( key, qualTab, labelFct, ... )
local v
local v
if not array[ key ] then
if not array[ key ] then
Zeile 252: Zeile 260:
if qual.snaktype == 'value' then
if qual.snaktype == 'value' then
v, array[ key .. '-type' ] =
v, array[ key .. '-type' ] =
analyzeDatavalue( qual.datavalue )
analyzeDatavalue( qual.datavalue, labelFct, ... )
table.insert( array[ key ], v )
table.insert( array[ key ], v )
end
end
Zeile 260: Zeile 268:
array[ key .. '-type' ] = nil
array[ key .. '-type' ] = nil
else
else
wu.addProperty( key )
catTable[ key ] = ''
end
end
end
end
Zeile 269: Zeile 277:
return results
return results
end
end
catTable[ p ] = ''


if type( qualifiers ) == 'string' then
if type( qualifiers ) == 'string' then
Zeile 275: Zeile 284:


for _, statement in ipairs( statements ) do
for _, statement in ipairs( statements ) do
array = { value = analyzeDatavalue( statement.mainsnak.datavalue ),
array = { value = analyzeDatavalue( statement.mainsnak.datavalue, labelFct, ... ),
[ 'value-type' ] = statement.mainsnak.datavalue.type }
[ 'value-type' ] = statement.mainsnak.datavalue.type }
if statement.qualifiers then
if statement.qualifiers then
if not qualifiers then -- all qualifier properties
if not qualifiers then -- all qualifier properties
for key, qualTab in pairs( statement.qualifiers ) do
for key, qualTab in pairs( statement.qualifiers ) do
toQualifierTable( key, qualTab )
toQualifierTable( key, qualTab, labelFct, ... )
end
end
else -- table of selected qualifier properties
else -- table of selected qualifier properties
for _, key in ipairs( qualifiers ) do
for _, key in ipairs( qualifiers ) do
if statement.qualifiers[ key ] then
if statement.qualifiers[ key ] then
toQualifierTable( key, statement.qualifiers[ key ] )
toQualifierTable( key, statement.qualifiers[ key ], labelFct, ... )
end
end
end
end
Zeile 388: Zeile 397:
i = moduleInterface.item
i = moduleInterface.item
if type( i ) == 'number' and i > 0 then
if type( i ) == 'number' and i > 0 then
v = wu.getValue( 'Q' .. i, 'P348' )
v = wu.getValue( 'Q' .. i, wd.version )
if v ~= '' then
if v ~= '' then
return v
return v
Anonymer Benutzer