Эчтәлеккә күчү

Модуль:CategoryForProfession

Wikipedia — ирекле энциклопедия проектыннан ([http://tt.wikipedia.org.ttcysuttlart1999.aylandirow.tmf.org.ru/wiki/CategoryForProfession latin yazuında])

Для документации этого модуля может быть создана страница Модуль:CategoryForProfession/doc

local p = {}

local ListOfProfessions = mw.loadData('Модуль:ListOfProfessions')
local ListOfCountries = mw.loadData('Модуль:ListOfCountries')
local ListOfProfessions2 = mw.loadData('Модуль:ListOfProfessions2')

local ProfessionsCategoryByAlphabet = {}
for k, v in pairs(ListOfProfessions2) do
	ProfessionsCategoryByAlphabet[k] = '[[Төркем: Әлифба буенча ' .. v .. ']]'
end

local ProfessionsCategoriesByCountry = {}
local QQQ = {}
for i, j in pairs(ListOfCountries) do
	QQQ = {}
	for k, v in pairs(ListOfProfessions) do
		QQQ[k] = '[[Төркем:' .. j ..' ' .. v ..' ]]'
	end
	ProfessionsCategoriesByCountry[i] = QQQ
end

local function MakeGeneralCategories(professionsList, dict)
	local res = ''
	for i, prof in pairs(professionsList) do
		id = 'Q' .. prof.mainsnak.datavalue.value['numeric-id']
		local cat = dict[id];
		if cat ~= nil then
			res = res .. cat;	
		end
	end
    return res
end

local function MakeCountriesCategories(countriesList, professionsList)
	local res = ''
	for i, cant in pairs(countriesList) do
		if cant.mainsnak.datavalue ~= nil then
			id = 'Q' .. cant.mainsnak.datavalue.value['numeric-id']
			local professionsCategories = ProfessionsCategoriesByCountry[id];
			if professionsCategories ~= nil then
				res = res .. MakeGeneralCategories(professionsList, professionsCategories);
			end
		end
	end
    return res
end

function p.mainFunction()
	local result = ''
	local entity = mw.wikibase.getEntityObject()
	if entity ~= nil and entity.claims ~= nil then
		if entity.claims[ 'P106' ] ~= nil then
			professions = entity.claims[ 'P106' ]
			result = result .. MakeGeneralCategories(professions, ProfessionsCategoryByAlphabet)
			if entity.claims[ 'P27' ] ~= nil then
				countries = entity.claims[ 'P27' ]
				result = result .. MakeCountriesCategories(countries, professions)
			end
		end
	end
	return result
end

return p