Модуль:CategoryAutoDescription: различия между версиями

Материал из Викиновостей, свободного источника новостей
Содержимое удалено Содержимое добавлено
дополнение
Нет описания правки
(не показаны 2 промежуточные версии этого же участника)
Строка 33: Строка 33:
local details, description, categories = CategoryAutoDescription.parseInstanceOf(entity) -- берём детали (то, что в скобочках), описание и категории
local details, description, categories = CategoryAutoDescription.parseInstanceOf(entity) -- берём детали (то, что в скобочках), описание и категории
local out=""
local out=""
if(frame.args[2] ~= nil and frame.args[2] ~= "{{{Описание}}}") then out = out .. frame.args[2] .. categories
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 (frame.args[2] ~= nil and frame.args[2] ~= "{{{Описание}}}") then out = out .. frame.args[2]
elseif (entity == nil) then do
elseif (entity == nil) then do
if(frame.args[1] ~= nil) then out = out .. "'''" .. frame.args[1] .. "''' " .. " — ."
if(frame.args[1] ~= nil) then out = out .. "'''" .. frame.args[1] .. "''' " .. " — ."
elseif(name ~= nil) then out = out .. "'''" .. name .. "''' " .. " — ."
elseif(name ~= nil) then out = out .. "'''" .. name .. "''' " .. " — ."

Версия от 18:13, 7 мая 2018

Документация

Модуль для автозаполнения категорий.


--[[
------------------------------------------
--              CategoryAutoDescription
-- Модуль для автозаполнения категорий.
------------------------------------------
--]]

local CategoryAutoDescription = {}

local AutoDescriptionLocality = require("Module:AutoDescriptionLocality")

local essence = {Q515 = "locality" --[[ city --]], Q532 = "locality" --[[ village --]], Q5084 = "locality" --[[ hamlet --]], 
 Q5084 = "locality" --[[ hamlet --]], Q486972 = "locality" --[[ human 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 --]] }

--[[
-- Главная функция - точка входа
--]]
function CategoryAutoDescription.launch(frame)
 --if(frame.args[2] == "{{{Описание}}}") then return "true: " .. frame.args[2] end
 local id = mw.wikibase.getEntityIdForCurrentPage() -- Q...
 local name = mw.wikibase.label() -- имя категории
 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 .. "'''" .. frame.args[1] .. "''' " .. " — ."
    elseif(name ~= nil) then out = out .. "'''" .. name .. "''' " .. " — ."
   end
  end
  else out = "'''" .. frame.args[1] .. "''' " .. details .. " — " .. description .. categories 
 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
  for kj, vj  in pairs(essence) do
   if (vi['mainsnak']['datavalue']['value']['id'] == kj) then 
   	if (vj == "locality") then return AutoDescriptionLocality.launch(entity) end
   end
  end	
 end	
 return "", "", ""
end	

return CategoryAutoDescription