Modul:Wikidata utilities: Unterschied zwischen den Versionen

+wu.getUnit( unit )
(+labelFct)
(+wu.getUnit( unit ))
Zeile 4: Zeile 4:
local WikidataUtilities = {
local WikidataUtilities = {
suite  = 'WikidataUtilities',
suite  = 'WikidataUtilities',
serial = '2020-10-01',
serial = '2020-10-02',
item  = 65439025
item  = 65439025
}
}
Zeile 85: Zeile 85:
return isSet( globalSiteId ) and entity:getSitelink( globalSiteId )
return isSet( globalSiteId ) and entity:getSitelink( globalSiteId )
or entity:getSitelink( globalSiteId )
or entity:getSitelink( globalSiteId )
end
end
-- convert from url to Q id
function wu.getUnit( unit )
if isSet( unit ) and type( unit ) == 'string' then
return unit:gsub( 'https?://www.wikidata.org/entity/', '' )
else
return ''
end
end
end
end
Zeile 112: Zeile 121:
i = i + 1
i = i + 1
if statements[ i ].mainsnak.snaktype == 'value' then
if statements[ i ].mainsnak.snaktype == 'value' then
if statements[ i ].mainsnak.datatype == 'quantity' then
statements[ i ].mainsnak.datavalue.value.amount =
statements[ i ].mainsnak.datavalue.value.amount:gsub( '^+', '' )
statements[ i ].mainsnak.datavalue.value.unit = wu.getUnit(
statements[ i ].mainsnak.datavalue.value.unit )
end
table.insert( ar, statements[ i ] )
table.insert( ar, statements[ i ] )
end
end
Zeile 238: Zeile 253:
if v.unit == '1' then
if v.unit == '1' then
v = tonumber( v.amount ) or 1
v = tonumber( v.amount ) or 1
else
v.amount = v.amount:gsub( '^+', '' )
v.unit = v.unit:gsub( 'http://www.wikidata.org/entity/', '' )
end
end
elseif t == 'time' then
elseif t == 'time' then
Anonymer Benutzer