Modulo:CategoryAutoDescription
Aspekto
Dokumentado por ĉi tiu modulo povas esti kreata ĉe Modulo:CategoryAutoDescription/dokumentado
--[[
------------------------------------------
-- CategoryAutoDescription
-- Модуль для автозаполнения категорий.
------------------------------------------
--]]
local CategoryAutoDescription = {}
local AutoDescriptionAsteroid = require("Module:AutoDescriptionAsteroid")
local AutoDescriptionFilms = require("Module:AutoDescriptionFilms")
local AutoDescriptionGalaxy = require("Module:AutoDescriptionGalaxy")
local AutoDescriptionGames = require("Module:AutoDescriptionGames")
local AutoDescriptionHoliday = require("Module:AutoDescriptionHoliday")
local AutoDescriptionHuman = require("Module:AutoDescriptionHuman")
local AutoDescriptionLocality = require("Module:AutoDescriptionLocality")
local AutoDescriptionStars = require("Module:AutoDescriptionStars")
local AutoDescriptionState = require("Module:AutoDescriptionState")
local essence = {
Q515 = "locality" --[[ city --]], Q532 = "locality" --[[ village --]], Q5084 = "locality" --[[ hamlet --]],
Q5084 = "locality" --[[ hamlet --]], Q486972 = "locality" --[[ human settlement --]], Q2514025 = "locality" --[[ small settlement --]], Q3744870 = "locality" --[[ township --]],
Q5123999 = "locality" --[[ city of regional significance of Ukraine --]], Q12131624 = "locality" --[[ city in Ukraine --]],
Q747074 = "locality" --[[ comune of Italy --]], Q1637706 = "locality" --[[ city with a population of more than 1,000,000 --]],
Q3957 = "locality" --[[ settlement that is bigger than a village but smaller than a city --]], Q482821 = "locality" --[[ metropolitan city of South Korea --]],
Q13539802 = "locality" --[[ place with town rights and privileges --]], Q262882 = "locality" --[[ statutory city of Austria --]], Q667509 = "locality" --[[ municipality of Austria --]],
Q1906268 = "locality" --[[ municipality of Bulgaria --]], Q50330360 = "locality" --[[ second largest city --]], Q1549591 = "locality" --[[ big city --]], Q12813115 = "locality" --[[ urban area of Sweden --]],
Q70208 = "locality" --[[ municipality of Switzerland --]], Q14770218 = "locality" --[[ cantonal capital of Switzerland --]],
Q537250 = "locality" --[[ federal city --]], Q1187811 = "locality" --[[ college town --]], Q5119 = "locality" --[[ capital --]], Q317548 = "locality" --[[ resort town --]],
Q13218391 = "locality" --[[ charter city --]], Q484170 = "locality" --[[ commune of France --]], Q2989398 = "locality" --[[ municipality of Algeria --]], Q25412763 = "locality" --[[ city in Chile --]],
Q15661340 = "locality" --[[ ancient city --]], Q2590631 = "locality" --[[ municipality of Hungary --]], Q12134916 = "locality" --[[ center of oblast --]],
Q3184121 = "locality" --[[ municipality of Brazil --]], Q15127838 = "locality" --[[ city under State jurisdiction in Latvia --]], Q51049922 = "locality" --[[type of settlement in Estonia --]],
Q33146843 = "locality" --[[ municipality of Catalania --]], Q2989457 = "locality" --[[ urban settlement --]], Q7216840 = "locality" --[[ urban settlement of Ukraine --]], Q15078955 = "locality" --[[ urban settlement of Russia --]],
Q21672098 = "locality" --[[ village of Ukraine --]], Q7930989 = "locality" --[[ city/town --]], Q755707 = "locality" --[[ municipality of Norway --]], Q2074737 = "locality" --[[ municipality of Spain --]],
Q12131640 = "locality" --[[ city of district significance --]], Q3199141 = "locality" --[[ city of Indonesia --]], Q1093829 = "locality" --[[ city of the United States --]], Q2039348 = "locality" --[[ municipality of the Netherlands --]],
Q20202352 = "locality" --[[ locality of Mexico --]], Q3685430 = "locality" --[[ municipality of Armenia --]],
Q5 = "human",
Q43185532 = "star" --[[ B-type supergiant star --]], Q523="star" --[[ star --]], Q43185588="star" --[[ A-type supergiant star --]], Q5898="star" --[[ red supergiant --]],
Q1353952="star" --[[ F-type main-sequence star --]], Q285400="star" --[[ flare star --]], Q50053="star" --[[ binary star --]], Q244393="star" --[[ dwarf star --]], Q101600 = "star" --[[ brown dwarf --]],
Q2088753 = "star" --[[ triple star system --]], Q878367="star" --[[ multiple star --]], Q13890 = "star" --[[ double star --]], Q5875 = "star" --[[ giant star --]], Q1048372 = "star" --[[ blue supergiant --]],
Q3863="asteroid",
Q318="galaxy" --[[galaxy --]], Q2488="galaxy" --[[spiral galaxy --]],
Q7724161 = "teleserial" --[[ television serial --]], Q5398426 = "teleserial" --[[ television series --]], Q1366112 = "teleserial" --[[ television drama --]], Q63952888 = "teleserial" --[[ anime television series --]],
Q11424 = "film" --[[ film --]],
Q1445650 = "holiday" --[[ holiday --]], Q1197685 = "holiday" --[[ public holiday --]], Q422695 = "holiday" --[[ awareness day --]], Q132241 = "holiday" --[[ festival --]], Q200538 = "holiday" --[[ party --]],
Q7889 = "game" --[[ video game --]], Q7058673 = "game" --[[ video game series --]], Q862490 = "game" --[[ massively multiplayer online game --]],
Q79007 = "street" --[[ street --]], Q83620 = "street" --[[ thoroughfare --]],
Q928830 = "metro" --[[ metro station --]],
Q3624078 = "State" --[[State --]]
}
--[[
-- Главная функция - точка входа
--]]
function CategoryAutoDescription.launch(frame)
--if(frame.args[2] == "{{{Priskribo}}}") then return "true: " .. frame.args[2] end
local id = mw.wikibase.getEntityIdForCurrentPage() -- Q...
local name = mw.wikibase.label() -- имя категории
if(name == nil) then name = frame.args[1] end
local entity = mw.wikibase.getEntity()
local details, description, categories = CategoryAutoDescription.parseInstanceOf(entity) -- берём детали (то, что в скобочках), описание и категории
local out = ""
if(frame.args[2] ~= nil and frame.args[2] ~= "" and frame.args[2] ~= " " and frame.args[2] ~= "{{{Описание}}}") then out = out .. frame.args[2] .. categories
elseif (entity == nil) then do
if(frame.args[1] ~= nil) then out = out .. "'''" .. name .. "''' " .. " — ."
elseif(name ~= nil) then out = out .. "'''" .. name .. "''' " .. " — ."
end
end
else out = "'''" .. name .. "''' " .. details .. " — " .. description .. categories
end
if(out == "") then out = "[[Kategorio:Kategorio sen priskribo]]" end
return out
end
--[[
-- Вызывает для разных типов объектов (instance of) собственный обработчик для
-- создания описания и категории
--]]
function CategoryAutoDescription.parseInstanceOf(entity)
if(entity == nil) then return "", "", "" end
local p31Statements = entity:getAllStatements("P31")
for ki, vi in pairs(p31Statements) do
local idP31=vi['mainsnak']['datavalue']['value']['id']
local upP31={}
local p279Statements=mw.wikibase.getBestStatements(idP31, 'P279' )
local j=1
for kj, vj in pairs (p279Statements) do
if(vj ~= nil and vj['mainsnak'] ~= nil and vj['mainsnak']['datavalue'] ~= nil and vj['mainsnak']['datavalue']['value'] ~= nil and vj['mainsnak']['datavalue']['value']['id'] ~= nil ) then
upP31[j] = vj['mainsnak']['datavalue']['value']['id']
j=j+1
end
end
for kj, vj in pairs(essence) do
if (vi['mainsnak']['datavalue']['value']['id'] == kj) then
if (vj == "locality") then return AutoDescriptionLocality.launch(entity) end
if (vj == "human") then return AutoDescriptionHuman.launch(entity) end
if (vj == "star") then return AutoDescriptionStars.launch(entity) end
if (vj == "asteroid") then return AutoDescriptionAsteroid.launch(entity) end
if (vj == "galaxy") then return AutoDescriptionGalaxy.launch(entity) end
if (vj == "teleserial") then return AutoDescriptionTeleserial.launch(entity) end
if (vj == "film") then return AutoDescriptionFilms.launch(entity) end
if (vj == "holiday") then return AutoDescriptionHoliday.launch(entity) end
if (vj == "game") then return AutoDescriptionGames.launch(entity) end
if (vj == "street") then return AutoDescriptionStreet.launch(entity) end
if (vj == "metro") then return AutoDescriptionMetro.launch(entity) end
if (vj == "State") then return AutoDescriptionState.launch(entity) end
end
for kk, vk in pairs(upP31) do
if (kj == vk) then
if (vj == "locality") then return AutoDescriptionLocality.launch(entity) end
if (vj == "human") then return AutoDescriptionHuman.launch(entity) end
if (vj == "star") then return AutoDescriptionStars.launch(entity) end
if (vj == "asteroid") then return AutoDescriptionAsteroid.launch(entity) end
if (vj == "galaxy") then return AutoDescriptionGalaxy.launch(entity) end
if (vj == "teleserial") then return AutoDescriptionTeleserial.launch(entity) end
if (vj == "film") then return AutoDescriptionFilms.launch(entity) end
if (vj == "holiday") then return AutoDescriptionHoliday.launch(entity) end
if (vj == "game") then return AutoDescriptionGames.launch(entity) end
if (vj == "street") then return AutoDescriptionStreet.launch(entity) end
if (vj == "metro") then return AutoDescriptionMetro.launch(entity) end
if (vj == "State") then return AutoDescriptionState.launch(entity) end
end
end
end
end
return "", "", ""
end
return CategoryAutoDescription