Modul:Wikidata utilities: Unterschied zwischen den Versionen
getValuesWithQualifiers extended by values parameter
(vereinfacht) |
(getValuesWithQualifiers extended by values parameter) |
||
Zeile 4: | Zeile 4: | ||
local WikidataUtilities = { | local WikidataUtilities = { | ||
suite = 'WikidataUtilities', | suite = 'WikidataUtilities', | ||
serial = ' | serial = '2021-01-28', | ||
item = 65439025 | item = 65439025 | ||
} | } | ||
Zeile 306: | Zeile 306: | ||
-- {} : using no qualifiers/references | -- {} : using no qualifiers/references | ||
-- nil : using all qualifiers/references | -- nil : using all qualifiers/references | ||
function wu.getValuesWithQualifiers( entity, p, qualifiers, references, count, | function wu.getValuesWithQualifiers( entity, p, values, qualifiers, references, | ||
count, labelFct, ... ) | |||
local array | local array | ||
local function toQualifierTable( tab, key, qualTab, labelFct, ... ) | local function toQualifierTable( tab, key, qualTab, labelFct, ... ) | ||
Zeile 327: | Zeile 327: | ||
catTable[ key ] = '' | catTable[ key ] = '' | ||
end | end | ||
end | |||
local function hasValue( tab, val ) | |||
for _, value in ipairs( tab ) do | |||
if value == val then | |||
return true | |||
end | |||
end | |||
return false | |||
end | end | ||
Zeile 333: | Zeile 341: | ||
if #statements == 0 then | if #statements == 0 then | ||
return results | return results | ||
end | |||
local i, v | |||
if type( values ) == 'table' and #values > 0 then | |||
for i = #statements, 1, -1 do | |||
v = statements[ i ].mainsnak.datavalue.value | |||
if type( v ) ~= 'string' then | |||
v = v.id | |||
end | |||
if not isSet( v ) or not hasValue( values, v ) then | |||
table.remove( statements, i ) | |||
end | |||
end | |||
if #statements == 0 then | |||
return results | |||
end | |||
end | end | ||
catTable[ p ] = '' | catTable[ p ] = '' |