Zum Inhalt springen

Modul:Wikidata utilities: Unterschied zwischen den Versionen

+references
(Vorbereitung Erweiterung getValuesWithQualifiers)
(+references)
Zeile 4: Zeile 4:
local WikidataUtilities = {
local WikidataUtilities = {
suite  = 'WikidataUtilities',
suite  = 'WikidataUtilities',
serial = '2020-10-09',
serial = '2020-10-10',
item  = 65439025
item  = 65439025
}
}
Zeile 265: Zeile 265:
labelFct, ... )
labelFct, ... )
local array
local array
local function toQualifierTable( key, qualTab, labelFct, ... )
local function toQualifierTable( tab, key, qualTab, labelFct, ... )
local v
local v
if not array[ key ] then
if not tab[ key ] then
array[ key ] = {}
tab[ key ] = {}
end
end
for _, qual in ipairs( qualTab ) do
for _, qual in ipairs( qualTab ) do
if qual.snaktype == 'value' then
if qual.snaktype == 'value' then
v, array[ key .. '-type' ] =
v, tab[ key .. '-type' ] =
analyzeDatavalue( qual.datavalue, labelFct, ... )
analyzeDatavalue( qual.datavalue, labelFct, ... )
table.insert( array[ key ], v )
table.insert( tab[ key ], v )
end
end
end
end
if #array[ key ] == 0 then
if #tab[ key ] == 0 then
array[ key ] = nil
tab[ key ] = nil
array[ key .. '-type' ] = nil
tab[ key .. '-type' ] = nil
else
else
catTable[ key ] = ''
catTable[ key ] = ''
Zeile 296: Zeile 296:
end
end
if type( references ) == 'string' then
if type( references ) == 'string' then
qualifiers = { references }
references = { references }
end
end


Zeile 306: Zeile 306:
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, labelFct, ... )
toQualifierTable( array, 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 ], labelFct, ... )
toQualifierTable( array, key, statement.qualifiers[ key ], labelFct, ... )
end
end
end
end
end
end
end
end
table.insert( results, array )


array.references = {}
if statement.references then
if statement.references then
if not references then -- all references
for i, reference in ipairs( statement.references ) do
-- ...
if reference and reference.snaks then
else -- table of selected references
table.insert( array.references, {} )
-- ...
if not references then -- all references
for key, refTab in pairs( reference.snaks ) do
toQualifierTable( array.references[ #array.references ],
key, refTab )
end
else -- table of selected references
for _, key in ipairs( references ) do
if reference.snaks[ key ] then
toQualifierTable( array.references[ #array.references ],
key, reference.snaks[ key ] )
end
end
end
end
end
end
end
end
-- ...
 
table.insert( results, array )
end
end


Anonymer Benutzer