Anonimo

Modulo:DTGenerico: differenze tra le versioni

Da Wikitrek.
New loop to identify root class
(Routine to get the root instance of a given item)
(New loop to identify root class)
 
(5 versioni intermedie di uno stesso utente non sono mostrate)
Riga 221: Riga 221:
InstanceQ = Item.claims[Property][1].mainsnak.datavalue.value.id
InstanceQ = Item.claims[Property][1].mainsnak.datavalue.value.id
RootInstanceArray = PropertiesOnTree("P14", 3, true, false, true)
--Initial setting to calculate the root class of the item
RootInstanceQ = InstanceQ
if #RootInstanceArray > 1 then
--Loop only if the element is not a Class itself
--Second to last resul, because last one should always be a Class, the topmost Instance possible
if RootInstanceQ ~= "Q47" then
RootInstance = RootInstanceArray[#RootInstanceArray - 1]
--Set a reasonable number of iteration to avoid infinite loop
else
for i = 1, 15, 1 do
--Should be a Class
local TempQ
RootInstance = RootInstanceArray[1]
TempQ = mw.wikibase.getEntity(RootInstanceQ).claims["P14"][1].mainsnak.datavalue.value.id
--If
if TempQ == "Q47" then
break
else
RootInstanceQ = TempQ
end
end
end
end
RootInstance = mw.wikibase.getLabelByLang(RootInstanceQ, 'it')
mw.smw.set("Istanza radice=" .. RootInstance)
mw.smw.set("Istanza radice=" .. RootInstance)
--If the item's root class is spaceship, then sets the name
if RootInstance == "Astronave" or RootInstance == "Spaceship" then
if RootInstance == "Astronave" or RootInstance == "Spaceship" then
--if InstanceQ == "Q876" or InstanceQ == "Q78" or InstanceQ == "Q890" then
--if InstanceQ == "Q876" or InstanceQ == "Q78" or InstanceQ == "Q890" then