Zum Inhalt springen

Modul:Wikidata utilities: Unterschied zwischen den Versionen

code check
(maintain categories table)
(code check)
Zeile 3: Zeile 3:
suite  = 'FastWikidata',
suite  = 'FastWikidata',
serial = '2020-05-13',
serial = '2020-05-13',
-- item  = 58187612
item  = 65439025
}
}


Zeile 100: Zeile 100:


for i = 1, #statements, 1 do
for i = 1, #statements, 1 do
if statements[i].mainsnak.snaktype == 'value' then
if statements[ i ].mainsnak.snaktype == 'value' then
return statements[i].mainsnak.datavalue.value
return statements[ i ].mainsnak.datavalue.value
end
end
end
end
Zeile 113: Zeile 113:
count = #statements
count = #statements
end
end
if ( #statements == 0 ) or ( count <= 0 ) then
if #statements == 0 or count <= 0 then
return ar
return ar
end
end
Zeile 120: Zeile 120:
repeat
repeat
i = i + 1
i = i + 1
if statements[i].mainsnak.snaktype == 'value' then
if statements[ i ].mainsnak.snaktype == 'value' then
table.insert( ar, statements[i].mainsnak.datavalue.value )
table.insert( ar, statements[ i ].mainsnak.datavalue.value )
end
end
until ( i >= #statements ) or ( #ar >= count )
until i >= #statements or #ar >= count


return ar
return ar
Zeile 138: Zeile 138:
function fw.getStatements( entity, p, count )
function fw.getStatements( entity, p, count )
local ar = {}
local ar = {}
if ( not entity ) or ( entity == '' ) then
if not entity or entity == '' then
return ar
return ar
end
end
Zeile 148: Zeile 148:
count = #statements
count = #statements
end
end
if ( #statements == 0 ) or ( count <= 0 ) then
if #statements == 0 or count <= 0 then
return ar
return ar
end
end
Zeile 155: Zeile 155:
repeat
repeat
i = i + 1
i = i + 1
if statements[i].mainsnak.snaktype == 'value' then
if statements[ i ].mainsnak.snaktype == 'value' then
table.insert( ar, statements[i] )
table.insert( ar, statements[ i ] )
end
end
until ( i >= #statements ) or ( #ar >= count )
until i >= #statements or #ar >= count


return ar
return ar
Zeile 169: Zeile 169:
if value then
if value then
catTable[ p ] = ''
catTable[ p ] = ''
else
value = ''
end
end
value = value or ''
end
end
return value
return value
Zeile 218: Zeile 219:
end
end
end
end
until ( i >= #statements ) or ( #ar >= count )
until i >= #statements or #ar >= count
end
end
if #ar > 0 then
if #ar > 0 then
Zeile 260: Zeile 261:
-- get values array for monolingual text
-- get values array for monolingual text
function fw.getValuesWithLanguages( entity, p )
function fw.getValuesWithLanguages( entity, p )
local result = {}, statements, hyphen, i, lng, value
local result = {}
if entity and entity ~= '' and p and p ~= '' then
if entity and entity ~= '' and p and p ~= '' then
statements = fw.getStatements( entity, p, nil )
local statements = fw.getStatements( entity, p, nil )
local hyphen, lng, value
if #statements > 0 and statements[ 1 ].mainsnak.datatype == 'monolingualtext' then
if #statements > 0 and statements[ 1 ].mainsnak.datatype == 'monolingualtext' then
catTable[ p ] = ''
catTable[ p ] = ''
for i = 1, #statements, 1 do
for i = 1, #statements, 1 do
value = statements[i].mainsnak.datavalue.value
value = statements[ i ].mainsnak.datavalue.value
lng = value.language
lng = value.language
hyphen = lng:find( '-' )
hyphen = lng:find( '-' )
Zeile 303: Zeile 305:
end
end


if qualifiers and ( type( qualifiers ) == 'string' ) then
if qualifiers and type( qualifiers ) == 'string' then
qualifiers = { qualifiers }
qualifiers = { qualifiers }
end
end
Zeile 309: Zeile 311:
local array
local array
for i = 1, #statements, 1 do
for i = 1, #statements, 1 do
array = { value = statements[i].mainsnak.datavalue.value,
array = { value = statements[ i ].mainsnak.datavalue.value,
['value-type'] = statements[i].mainsnak.datavalue.type }
[ 'value-type' ] = statements[ i ].mainsnak.datavalue.type }
if statements[ i ].qualifiers then
if statements[ i ].qualifiers then
if not qualifiers then -- all qualifier properties
if not qualifiers then -- all qualifier properties
for key, value in pairs( statements[i].qualifiers ) do
for key, value in pairs( statements[ i ].qualifiers ) do
if #value > 0 then
if #value > 0 then
for j = 1, #value, 1 do
for j = 1, #value, 1 do
Zeile 326: Zeile 328:
else -- table of selected qualifier properties
else -- table of selected qualifier properties
for key, value in pairs( qualifiers ) do
for key, value in pairs( qualifiers ) do
if statements[i].qualifiers[ value ] and
if statements[ i ].qualifiers[ value ] and
( #statements[ i ].qualifiers[ value ] > 0 ) then
#statements[ i ].qualifiers[ value ] > 0 then
for j = 1, #statements[i].qualifiers[ value ], 1 do
for j = 1, #statements[ i ].qualifiers[ value ], 1 do
if statements[i].qualifiers[ value ][ j ].snaktype == 'value' then
if statements[ i ].qualifiers[ value ][ j ].snaktype == 'value' then
array[ value ], array[ value .. '-type' ] =
array[ value ], array[ value .. '-type' ] =
getValueFromgetValueFromDatavalue( statements[i].qualifiers[ value ][ j ].datavalue )
getValueFromgetValueFromDatavalue( statements[ i ].qualifiers[ value ][ j ].datavalue )
break
break
end
end
Zeile 389: Zeile 391:
end
end


function fw.getCategories( catArray, formatStr )
function fw.getCategories( formatStr )
local result = ''
local result = ''
if type( catArray ) == 'string' then
 
formatStr = catArray
end
if not formatStr or formatStr == '' then
if not formatStr or formatStr == '' then
formatStr = '[[Category:%s]]'
formatStr = '[[Category:%s]]'
Anonymer Benutzer