Module:gem-decl-adj

local export = {}

local m_pron = require("Module:gem-pronunc") local m_links = require("Module:links") local m_utils = require("Module:utilities")

local lang = require("Module:languages").getByCode("gem-pro")

local i_muts = m_pron.i_mutations

local decl_data = require("Module:gem-decl-adj/data") --local decl_data_irreg = require("Module:gem-decl-adj/data/irreg")

local endings = { ["az"] = "a", ["iz"] = "i", ["ô"] = "an/in", ["uz"] = "u", }

local endings_reverse = { ["a"] = "az", ["i"] = "iz", ["an/in"] = "ô", ["u"] = "uz", }

local function detect_decl(word, stem) if stem then return decl, {mw.ustring.sub(word, 1, -(mw.ustring.len(endings_reverse[stem]) + 1))} else for ending, decl in pairs(endings) do if mw.ustring.find(word, ending .. "$") then return decl, {mw.ustring.sub(word, 1, -(mw.ustring.len(ending) + 1))} end end end end local function add_asterisks(forms, data) for _, form in ipairs(forms) do		for i, subform in ipairs(data.forms[form]) do data.forms[form][i] = "*" .. subform end end end

-- The main entry point. -- This is the only function that can be invoked from a template. function export.show(frame) local parent_args = frame:getParent.args if mw.title.getCurrentTitle.nsText ~= "Reconstruction" then return end local stems = nil local decl_type = {} local word = mw.title.getCurrentTitle.subpageText local args = {}

--	if not decl_data_irreg[word] then if frame.args.decl then decl_type = frame.args.decl else if parent_args.stem and parent_args[1] then decl_type = parent_args.stem stems = {parent_args[1]} else decl_type, stems = detect_decl(word, parent_args.stem) end end if not decl_type then error("Unknown declension '" .. decl_type .. "'") end args = require("Module:parameters").process(parent_args, decl_data[decl_type].params, true) if stems then for i, stem in ipairs(stems) do				args[i] = stem end end --	end

local data = {forms = {}, categories = {}} data.head = parent_args["head"] or nil -- Generate the forms decl_data[decl_type](args, data)

-- Make the table return make_table(data) end

local function show_form(form) if not form then return "—" end local ret = {} for key, subform in ipairs(form) do		if mw.ustring.find(subform, "[iīįǐj]") or mw.ustring.find(subform, "e[mn]") then subform = i_muts(subform) end if subform ~= "—" then subform = "*" .. subform end table.insert(ret, subform) end return table.concat(ret, ", ") end

local function make_caseline(data, prefix) local line = {"sg_m", "pl_m", "sg_f", "pl_f", "sg_n", "pl_n"} local ret = {} for _, lineform in ipairs(line) do table.insert(ret, "| " .. show_form(data.forms[prefix .. "_" .. lineform]) .. "\n") end return table.concat(ret) end

local function make_inner_table(data, tcode, str_or_wk) table.insert(tcode, '! style="background-color:#F3E5AB" colspan="7" | ' .. (str_or_wk == "s_" and "strong" or "weak") .. [=[ declension ! style="width:33%; background-color:#FAEBD7" colspan="2" | masculine ! style="width:33%; background-color:#FAEBD7" colspan="2" | feminine ! style="width:33%; background-color:#FAEBD7" colspan="2" | neuter ! style="width:16%; background-color:#FAEBD7" | singular ! style="width:16%; background-color:#FAEBD7" | plural ! style="width:16%; background-color:#FAEBD7" | singular ! style="width:16%; background-color:#FAEBD7" | plural ! style="width:16%; background-color:#FAEBD7" | singular ! style="width:16%; background-color:#FAEBD7" | plural ! style="background: #FAEBD7" | nominative ]=]) table.insert(tcode, make_caseline(data, str_or_wk .. "nom")) table.insert(tcode, '|-\n! style="background: #FAEBD7" | accusative\n') table.insert(tcode, make_caseline(data, str_or_wk .. "acc")) table.insert(tcode, '|-\n! style="background: #FAEBD7" | genitive\n') table.insert(tcode, make_caseline(data, str_or_wk .. "gen")) table.insert(tcode, '|-\n! style="background: #FAEBD7" | dative\n') table.insert(tcode, make_caseline(data, str_or_wk .. "dat")) table.insert(tcode, '|-\n! style="background: #FAEBD7" | instrumental\n') table.insert(tcode, make_caseline(data, str_or_wk .. "ins")) end

function make_table(data) local wikicode = {[=[ Declension of *]=] .. mw.title.getCurrentTitle.subpageText .. " (" .. data.decl_type .. [=[) {| style="width:100%; line-height:125%; background-color:#F9F9F9; text-align:center; border:1px solid #CCCCFF;" cellpadding="3" cellspacing="1" class="inflection-table" ]=]}
 * - style="background-color:#EFEFEF;"

local pagename = mw.title.getCurrentTitle.subpageText if not decl_data.weak_only[pagename] then make_inner_table(data, wikicode, "s_") if not decl_data.strong_only[pagename] then table.insert(wikicode, '|-\n| colspan="7" |\n|-\n') end end if not decl_data.strong_only[pagename] then make_inner_table(data, wikicode, "w_") end table.insert(wikicode, '|} \n ')

return table.concat(wikicode) .. m_utils.format_categories(data.categories, lang) end

return export