Modul:Wikidata utilities: Unterschied zwischen den Versionen

new typeSearch
(+mw.wikibase.entityExists)
(new typeSearch)
Zeile 279: Zeile 279:
end
end


function fw.typeSearch( p31, list, limit, catArray )
function fw.typeSearch( p31, list, catArray )
-- p31: array of Wikidata values
if not list or not p31 or #p31 == 0 then
-- list: array of q id - types relations
return 'error', catArray
-- limit: maximum levels to analyse
end
if (not p31) or (#p31 == 0) then return 'error', catArray end
local ids = {}, id, k, v
local aType, i, id, j
for k,v in pairs( list ) do
if mw.wikibase.isValidEntityId( k ) then
table.insert( ids, k )
end
end
if #ids == 0 then
return 'error', catArray
end


for i = 1, #p31, 1 do
for k = 1, #p31, 1 do
id = p31[i].id
id = p31[ k ].id
aType = list[id]
v = list[ id ]


if aType then
if v then
return aType, catArray
return v, catArray
else
else
j = 0
v = mw.wikibase.getReferencedEntityId( id, 'P279', ids )
repeat
if v then
id, catArray = fw.getId( id, 'P279', catArray )
if catArray then
if id ~= '' then
catArray[ 'P279' ] = ''
aType = list[id]
if aType then return aType, catArray end
end
end
j = j + 1
return list[ v ], catArray
until (j >= limit) or (id == '')
end
end
end
end
end
Anonymer Benutzer