Modul:Wikidata utilities: Unterschied zwischen den Versionen

rückgängig; mw.wikibase.getReferencedEntityId ist unbrauchbar
(new typeSearch)
(rückgängig; mw.wikibase.getReferencedEntityId ist unbrauchbar)
Zeile 279: Zeile 279:
end
end


function fw.typeSearch( p31, list, catArray )
function fw.typeSearch( p31, list, limit, catArray )
-- p31: array of Wikidata values
-- list: indexed array of q id - types relations
-- limit: maximum levels to analyse
if not list or not p31 or #p31 == 0 then
if not list or not p31 or #p31 == 0 then
return 'error', catArray
return 'error', catArray
end
end
local ids = {}, id, k, v
local aType, i, id, j
for k,v in pairs( list ) do
 
if mw.wikibase.isValidEntityId( k ) then
for i = 1, #p31, 1 do -- check p31 ids first
table.insert( ids, k )
aType = list[ p31[ i ].id ]
if aType then
return aType, catArray
end
end
end
end
if #ids == 0 then
for i = 1, #p31, 1 do -- analyse P279 chain
return 'error', catArray
j = 0
end
repeat
 
id, catArray = fw.getId( p31[ i ].id, 'P279', catArray )
for k = 1, #p31, 1 do
if id ~= '' then
id = p31[ k ].id
aType = list[ id ]
v = list[ id ]
if aType then
 
return aType, catArray
if v then
return v, catArray
else
v = mw.wikibase.getReferencedEntityId( id, 'P279', ids )
if v then
if catArray then
catArray[ 'P279' ] = ''
end
end
return list[ v ], catArray
end
end
end
j = j + 1
until j >= limit or id == ''
end
end
return 'error', catArray
return 'error', catArray
Anonymer Benutzer