Modulo:AutoDescriptionStars
Dokumentado por ĉi tiu modulo povas esti kreata ĉe Modulo:AutoDescriptionStars/dokumentado
--[[
------------------------------------------
-- AutoDescriptionStars
-- Модуль для заполнения звёзд.
------------------------------------------
--]]
local Dates = require("Module:Dates")
local Declension = require("Module:Declension")
local Langs = require("Module:Langs")
local MathTonumber = require("Module:Math/tonumber")
local ReturnGendered = require("Module:ReturnGendered")
local SerializeTable = require("Module:SerializeTable")
local Math = require("Module:Math")
local AutoDescriptionStars={}
-- Нам необходимо сформировать и вернуть три переменных
local description = "" -- Обозначения Байера
local details = "" -- строка описания
local categories = "[[Kategorio:Steloj laŭ alfabeto]]" -- категории-- Промежуточный масив сущностей, в который помещаются результаты парсинга перед формированием описания
local entitiesArray = {asterism={}, bayer="", catalog={}, code={}, child={}, constellation="", distanceFromEarth="", mass="", radius={}, rotV="", spectral=""}
local entitiesArrayP = {P31="", P361="", P398="", P881="", P1215="", P1457="", P2060="", P2067="", P2120="", P2214="", P2583="", P4296=""}
local priority = {"Q4202", "Q231982", "Q1048372", "Q1196680", "Q5898", "Q43185532", "Q43185588", "Q6227", "Q1353952", "Q5893", "Q101600", "Q5871", "Q5864", "Q50053", "Q2088753"}
-- Точка входа
function AutoDescriptionStars.launch(entity)
AutoDescriptionStars.parsing(entity) -- парсим карточку викиданных
AutoDescriptionStars.forming() -- формируем переменные
return details, description, categories
end
-- Последовательно проходим свойства в карточке викиданных, для формирования массива сущностей entitiesArray
function AutoDescriptionStars.parsing(entity)
entitiesArrayP["P31"]=AutoDescriptionStars.parseP31(entity)
AutoDescriptionStars.parseP59(entity)
AutoDescriptionStars.parseP215(entity)
entitiesArrayP['P361']=AutoDescriptionStars.parseP361(entity)
entitiesArrayP["P398"]=AutoDescriptionStars.parseP398(entity)
entitiesArrayP["P528"]=AutoDescriptionStars.parseP528(entity)
entitiesArrayP["P881"]=AutoDescriptionStars.parseP881(entity)
entitiesArrayP["P1215"]=AutoDescriptionStars.parseP1215(entity)
entitiesArrayP["P1457"]=AutoDescriptionStars.parseP1457(entity)
entitiesArrayP["P2060"]=AutoDescriptionStars.parseP2060(entity)
entitiesArrayP["P2067"]=AutoDescriptionStars.parseP2067(entity)
entitiesArrayP["P2120"]=AutoDescriptionStars.parseP2120(entity)
entitiesArrayP["P2214"]=AutoDescriptionStars.parseP2214(entity)
entitiesArrayP["P2583"]=AutoDescriptionStars.parseP2583(entity)
entitiesArrayP["P4296"]=AutoDescriptionStars.parseP4296(entity)
end
function AutoDescriptionStars.forming()
if(entitiesArray["bayer"] ~= "") then details = details .. "(" .. "''[[Обозначения Байера|Байер]]'': " .. entitiesArray["bayer"] .. ")" end
if(entitiesArrayP["P31"] == "звезда") then description = description .. "[[Звёзды|звезда]]"
else description = description .. "[[" .. entitiesArrayP.P31 .. "]]" end
if(entitiesArray["constellation"] ~= "") then description = description .. " [[" .. entitiesArray["constellation"] .. " (konstelacio)|en konstelacio " .. entitiesArray["constellation"] .. "]]."
else description = description .. "." end
if(entitiesArray["spectral"] ~= "") then description = description .. " [[Спектральный класс]]: " .. entitiesArray["spectral"] .. "." end
if(entitiesArrayP["P2067"] ~= "") then description = description .. " Масса: " .. entitiesArray["mass"] .. "M☉ ([[Солнечная масса|M☉]] = (1,98847 ± 0,00007)⋅10<sup>30</sup> кг)." end
if(entitiesArrayP["P2120"] == "full") then
description = description .. " Радиус: "
for ki, vi in pairs (entitiesArray["radius"]) do
description = description .. vi .. ", "
end
description=description:sub(1, #description - 2)
description=description.." ([[Солнечный радиус|R☉]]=6,960⋅10<sup>8</sup> м = 0,004652 [[Астрономическая единица|астрономической единицы]])."
end
if(entitiesArrayP["P4296"] ~= "") then
if(string.find(entitiesArrayP.P4296, "километр в секунду")) then description = description .. " Скорость вращения: " .. entitiesArray["rotV"] .. " км/c."
else description = description .. " Скорость вращения: " .. entitiesArrayP["P4296"] .. "." end
end
if(entitiesArrayP["P1215"] ~= "") then
description = description .. " [[Видимая звёздная величина|Блеск]]: " .. entitiesArrayP.P1215 .. "."
if(entitiesArrayP["P1215"] <= "6") then description = description .. " Видна невооружённым глазом."
else description = description .. " Видна только в телескоп." end
end
if(entitiesArrayP["P1457"] ~= "") then description = description .. " [[Абсолютная звёздная величина]]: " .. entitiesArrayP.P1457 .. "." end
if(entitiesArrayP["P2060"] ~= "") then description = description .. " Cветимость: " .. entitiesArrayP.P2060 .. "[[Солнечная светимость|L☉]]." end
if(entitiesArrayP["P881"] ~= "") then description = description .. " Класс переменных звёзд: " .. entitiesArrayP["P881"] .. "." end
if(entitiesArrayP["P2214"] ~= "") then description = description .. " Параллакс: " .. entitiesArrayP.P2214 .. "." end
if(entitiesArrayP["P2583"] == "full") then description = description .. " Расстояние от [[Земля|Земли]]: " .. entitiesArray.distanceFromEarth .. " cветовых лет." end
if (entitiesArrayP["P361"] == "full") then
description = description .. " Входит в: "
for ki, vi in pairs (entitiesArray.asterism) do
description = description .. "[[" .. vi .. "]], "
end
description=description:sub(1, #description - 2)
description=description..". "
end
if(entitiesArrayP["P398"] ~= "") then
local len=0
for k, v in pairs (entitiesArray.child) do
len=len+1
end
if (len>1) then description = description .. "<br>Тела-спутники: "
else description = description .. "<br>Тело-спутник: " end
for k, v in pairs (entitiesArray.child) do
description = description .. "[[" .. v.. "]]" .. ", "
end
description=description:sub(1, #description - 2)
description=description..". "
end
if(entitiesArrayP["P528"] == "full") then
description = description .. " <br><br>Код в каталоге: "
for k, v in pairs (entitiesArray.code) do
if(v ~= " ") then
if (entitiesArray["catalog"][k] ~= " " and entitiesArray["catalog"][k] ~= nil) then description = description .. v .. ' ([[' .. entitiesArray['catalog'][k] .. ']])' .. ", "
else description = description .. v .. ", " end
end
end
description=description:sub(1, #description - 2)
description=description..". "
end
if(entitiesArray["constellation"] ~= "") then categories = categories .. "[[Kategorio:Steloj en konstelacio " .. entitiesArray["constellation"] .. "]]" end
if(entitiesArray["spectral"] ~= "") then categories = categories .. "[[Категория:Звёзды класса " .. entitiesArray["spectral"] .. "]]" end
if(entitiesArrayP["P528"] == "full") then
for k, v in pairs (entitiesArray.code) do
if(v ~= " ") then
if (entitiesArray["catalog"][k] ~= " " and entitiesArray["catalog"][k] ~= nil) then
if(string.find(entitiesArray["catalog"][k], "каталог") or string.find(entitiesArray["catalog"][k], "Каталог") or string.find(entitiesArray["catalog"][k], "Katalog") or string.find(entitiesArray["catalog"][k], "Catalogue") or string.find(entitiesArray["catalog"][k], "Catalog") or string.find(entitiesArray["catalog"][k], "сatalog")) then categories = categories .. "[[Категория:" .. entitiesArray["catalog"][k] .. "]]"
else categories = categories .. "[[Категория:Звёзды каталога " .. entitiesArray["catalog"][k] .. "]]" end
end
end
end
end
if( entitiesArrayP["P1215"] ~= "" and entitiesArrayP["P1215"] <= "6") then categories = categories .. "[[Категория:Звёзды, видимые невооружённым глазом]]"end
end
function AutoDescriptionStars.parseP31(entity)
local p31Statements = entity:getAllStatements("P31")
local index=-1
local def=""
for ki, vi in pairs(p31Statements) do
for kj, vj in pairs(priority) do
if(vi['mainsnak']['datavalue']['value']['id'] == vj) then
if((index == -1) or (index>kj)) then
index = kj
def=mw.wikibase.getLabel(vj)
end
end
end
end
if (index==-1) then return "звезда"
else return def end
end
function AutoDescriptionStars.parseP59(entity)
local value = entity:formatPropertyValues("P59",mw.wikibase.entity.claimRanks).value
if(value ~= "") then entitiesArray["constellation"]=value end
end
function AutoDescriptionStars.parseP215(entity)
local value = entity:formatPropertyValues("P215",mw.wikibase.entity.claimRanks).value
if(value ~= "") then entitiesArray["spectral"]=value end
end
function AutoDescriptionStars.parseP361(entity)
local p361Statements=entity:getAllStatements("P361")
local i=1
for ki, vi in pairs (p361Statements) do
if(vi['mainsnak'] ~= nil) then entitiesArray['asterism'][i]=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) i=i+1 end
end
if(i>1) then return "full" end
end
function AutoDescriptionStars.parseP398(entity)
local p398Statements=entity:getAllStatements("P398")
i=1
for ki, vi in pairs (p398Statements) do
if(vi['mainsnak'] ~= nil) then
entitiesArray['child'][i]=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id'])
i=i+1
end
end
if (i>1) then return "full"
else return "" end
end
function AutoDescriptionStars.parseP528(entity)
local p528Statements=mw.wikibase.getBestStatements(entity:getId(), 'P528' )
i=1
for ki, vi in pairs (p528Statements) do
local catalog=""
local code=""
if(vi['qualifiers'] ~= nil) then
if((vi['qualifiers']['P972'] ~= nil)) then catalog=vi['qualifiers']['P972'][1]['datavalue']['value']['id'] end
if((vi['mainsnak'] ~= nil)) then code=vi['mainsnak']['datavalue']['value'] end
if (catalog ~= "") then entitiesArray["catalog"][i] = mw.wikibase.getLabel(catalog)
else entitiesArray["catalog"][i] = " " end
if (code ~= "") then entitiesArray["code"][i] = code
else entitiesArray["code"][i] = " " end
i=i+1
end
if (catalog == "Q105616") then entitiesArray["bayer"]=vi['mainsnak']['datavalue']['value'] end
end
if (i>1) then return "full"
else return "" end
end
function AutoDescriptionStars.parseP881(entity)
local value = entity:formatPropertyValues("P881",mw.wikibase.entity.claimRanks).value
if(value ~= "") then return value
else return "" end
end
function AutoDescriptionStars.parseP1215(entity)
local value = entity:formatPropertyValues("P1215",mw.wikibase.entity.claimRanks).value
if(value ~= "") then return value
else return "" end
end
function AutoDescriptionStars.parseP1457(entity)
local value = entity:formatPropertyValues("P1457",mw.wikibase.entity.claimRanks).value
if(value ~= "") then return value
else return "" end
end
function AutoDescriptionStars.parseP2060(entity)
local value = entity:formatPropertyValues("P2060",mw.wikibase.entity.claimRanks).value
if(value ~= "") then return string.gsub( value, 'солнечная светимость', '' )
else return "" end
end
function AutoDescriptionStars.parseP2067(entity)
local value = entity:formatPropertyValues("P2067",mw.wikibase.entity.claimRanks).value
if(value ~= "") then
entitiesArray["mass"]=MathTonumber.integerModule(value)
return value
else return "" end
end
function AutoDescriptionStars.parseP2120(entity)
local p2120Statements=entity:getAllStatements("P2120")
local i=1
for ki, vi in pairs (p2120Statements) do
local amount=""
local upperBound=""
local erroR=""
if(vi['mainsnak'] ~= nil) then
if(vi['mainsnak']['datavalue']['value']['amount'] ~= nil) then amount=vi['mainsnak']['datavalue']['value']['amount'] end
if(vi['mainsnak']['datavalue']['value']['upperBound'] ~= nil) then
upperBound=vi['mainsnak']['datavalue']['value']['upperBound']
erroR=MathTonumber.integerModule(upperBound)-MathTonumber.integerModule(amount)
end
if (erroR ~= "") then entitiesArray["radius"][i] = MathTonumber.integerModule(amount).."±"..erroR.." R☉"
else entitiesArray["radius"][i] = MathTonumber.integerModule(amount).." R☉" end
i=i+1
end
end
if(i>1) then return "full" end
end
function AutoDescriptionStars.parseP2214(entity)
local value = entity:formatPropertyValues("P2214",mw.wikibase.entity.claimRanks).value
if(value ~= "") then return value
else return "" end
end
function AutoDescriptionStars.parseP2583(entity)
local p2583Statements=entity:getAllStatements("P2583")
local i=1
for ki, vi in pairs (p2583Statements) do
local amount=""
local upperBound=""
local erroR=""
if(vi['mainsnak'] ~= nil) then
if(vi['mainsnak']['datavalue']['value']['amount'] ~= nil) then amount=vi['mainsnak']['datavalue']['value']['amount'] end
if(vi['mainsnak']['datavalue']['value']['upperBound'] ~= nil) then
upperBound=vi['mainsnak']['datavalue']['value']['upperBound']
erroR=MathTonumber.integerModule(upperBound)-MathTonumber.integerModule(amount)
end
if (erroR ~= "") then entitiesArray["distanceFromEarth"] = MathTonumber.integerModule(amount).."±"..erroR
else entitiesArray["distanceFromEarth"] = MathTonumber.integerModule(amount) end
i=i+1
end
end
if(i>1) then return "full" end
end
function AutoDescriptionStars.parseP4296(entity)
local value = entity:formatPropertyValues("P4296",mw.wikibase.entity.claimRanks).value
if(value ~= "") then
entitiesArray["rotV"] = MathTonumber.integerModule(value)
return value
else return "" end
end
return AutoDescriptionStars