Модуль:CategoryForProfession

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

local p = {}local ListOfProfessions = mw.loadData( 'Модуль:ListOfProfessions' )local ListOfCountries = mw.loadData( 'Модуль:ListOfCountries' )local ProfessionsCategoryByAlphabet = {}for k, v in pairs(ListOfProfessions) doProfessionsCategoryByAlphabet[k] = '[[Категория:' .. v .. ' по алфавиту]]'endlocal ProfessionsCategoriesByCountry = {}local QQQ = {}for i, j in pairs(ListOfCountries) doQQQ = {}for k, v in pairs(ListOfProfessions) doQQQ[k] = '[[Категори:' .. v ..' ' .. j ..']]'endProfessionsCategoriesByCountry[i] = QQQendlocal function MakeGeneralCategories(professionsList, dict)local res = ''for i, prof in pairs(professionsList) dolocal cat=nilif(prof.mainsnak.datavalue) then -- если значение свойства "значение неизвестно", то datavalue nilid = 'Q' .. prof.mainsnak.datavalue.value['numeric-id']cat = dict[id];endif cat ~= nil thenres = res .. cat;endend    return resendlocal function MakeCountriesCategories(countriesList, professionsList)local res = ''for i, cant in pairs(countriesList) doif cant.mainsnak.datavalue ~= nil thenid = 'Q' .. cant.mainsnak.datavalue.value['numeric-id']local professionsCategories = ProfessionsCategoriesByCountry[id];if professionsCategories ~= nil thenres = res .. MakeGeneralCategories(professionsList, professionsCategories);endendend    return resendfunction p.mainFunction(frame)local result = ''local wbStatus, entity = pcall( mw.wikibase.getEntity )if wbResult ~= true thenreturn '' -- [[Категори:Википеди:Страницы с ошибками скриптов, использующих Викиданные]]endif entity ~= nil and entity.claims ~= nil thenif entity.claims[ 'P106' ] ~= nil thenprofessions = entity.claims[ 'P106' ]result = result .. MakeGeneralCategories(professions, ProfessionsCategoryByAlphabet)if entity.claims[ 'P27' ] ~= nil thencountries = entity.claims[ 'P27' ]result = result .. MakeCountriesCategories(countries, professions)endendlocal args = {}if frame == mw.getCurrentFrame() thenif frame.args['без категорий'] == nil thenframe = frame:getParent();endif frame ~= nil thenargs = frame.args;endelseargs = frameend-- исключаем ненужные категории указанные в параметре через точку с запятой    local excude = args['без категорий'];    if excude ~= nil and excude ~= '' then    exclude = mw.text.split(excude, '%s*;%s*' )for i, v in ipairs(exclude) do local cat = mw.ustring.gsub( v, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" ); -- маскируем спецсимволыresult = mw.ustring.gsub(result, '%[%[Категори:' .. cat .. '%]%]', '');end    end;endreturn resultendreturn p