Modul:Wikidata utilities: Unterschied zwischen den Versionen
erweitert, Kommentare
K (etwas umgestellt) |
(erweitert, Kommentare) |
||
Zeile 286: | Zeile 286: | ||
return 'error', catArray | return 'error', catArray | ||
end | end | ||
for i = 1, # | local function compareIds( ar ) | ||
local i, t | |||
for i = 1, #ar, 1 do | |||
t = list[ ar[ i ].id ] | |||
if t then | |||
return t | |||
end | |||
end | end | ||
return nil | |||
end | |||
local aType, i, id, ids, j | |||
aType = compareIds( p31 ) -- check p31 ids first, maybe step 2 is not nessary | |||
if aType then | |||
return aType, catArray | |||
end | end | ||
-- now functions becomes expensive because of multiple fw.getValues calls | |||
for i = 1, #p31, 1 do -- step 2: analyse P279 chains of first ids | for i = 1, #p31, 1 do -- step 2: analyse P279 chains of first ids | ||
id = p31[ i ].id -- start id | id = p31[ i ].id -- start id | ||
j = 0 | j = 0 | ||
repeat | repeat | ||
ids, catArray = fw.getValues( id, 'P279', nil, catArray ) | |||
if id | if #ids > 0 then | ||
aType = | id = ids[ 1 ].id | ||
aType = compareIds( ids ) | |||
if aType then | if aType then | ||
return aType, catArray | return aType, catArray | ||
Zeile 307: | Zeile 318: | ||
end | end | ||
j = j + 1 | j = j + 1 | ||
until j >= limit or | until j >= limit or #ids == 0 | ||
end | end | ||