Module:urj-fin-nominals

local m_utilities = require("Module:utilities") local m_links = require("Module:links") local m_common = require("Module:urj-fin-common")

local export = {}

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

-- Functions that do the actual inflecting by creating the forms of a basic term. local inflections = {}

-- The main entry point. -- This is the only function that can be invoked from a template. function export.show(frame) local args = frame:getParent.args local data = {forms = {}, title = nil, categories = {}} -- Generate the forms inflect(args, data) -- Apply gradation for key, forms in pairs(data.forms) do		for i, form in ipairs(forms) do			forms[i] = m_common.apply_gradation(form) end end -- Check if the lemma form matches the page name if data.forms["nom_sg"] and (lang:makeEntryName(data.forms["nom_sg"][1])) ~= mw.title.getCurrentTitle.subpageText then table.insert(data.categories, lang:getCanonicalName .. " entries with inflection not matching pagename") end return make_table(data) .. m_utilities.format_categories(data.categories, lang) end

function inflect(args, data) local prefix = args[1] or "" local stem = args[2] or "" if stem == "" then stem = prefix prefix = "" end if stem == "" then if mw.title.getCurrentTitle.nsText == "Template" then stem = "-" else error("Parameter 1 (stem) must be provided") end end local vowels = m_common.detect_harmony(stem) local stems = m_common.make_stems((mw.ustring.gsub(stem, "([aeiouäëöü])n[eë]n$", "%1c"))) if mw.ustring.find(stem, "[aeiouäëöü]n[eë]n$") then stems.final = stem end make_forms(stems, vowels, data) if mw.ustring.find(stem, "^[mc]inu$") then data.forms["nom_sg"] = {(mw.ustring.gsub(stem, "u$", "ä"))} for key, form in pairs(data.forms) do			if key:find("_pl") then data.forms[key] = nil end end elseif mw.ustring.find(stem, "^[mth]e$") then data.forms["nom_pl"] = {stem, (mw.ustring.gsub(stem, "e$", "öö"))} data.forms["acc_pl"] = {stem .. "det", stem .. "idet"} for key, form in pairs(data.forms) do			if key:find("_sg") then data.forms[key] = nil end end elseif stem == "hän" then data.forms["nom_sg"] = {"hän"} for key, form in pairs(data.forms) do			if key:find("_pl") then data.forms[key] = nil end end end for key, subforms in pairs(data.forms) do		for i, form in ipairs(subforms) do subforms[i] = prefix .. form end end for _, t in ipairs(stems.types) do table.insert(data.categories, "Proto-Finnic nominals by type/" .. t)	end end

function make_forms(stems, vowels, data) data.forms["nom_sg"] = {stems.final} data.forms["acc_sg"] = {stems.normal .. "n"} data.forms["gen_sg"] = {stems.normal .. "n"} data.forms["par_sg"] = {stems.t .. vowels.a} data.forms["ine_sg"] = {stems.normal .. "ss" .. vowels.a, stems.normal .. "hn" .. vowels.a} data.forms["ela_sg"] = {stems.normal .. "st" .. vowels.a} data.forms["ill_sg"] = {stems.normal .. "s" .. vowels.e .. "n"} data.forms["ade_sg"] = {stems.normal .. "ll" .. vowels.a} data.forms["abl_sg"] = {stems.normal .. "lt" .. vowels.a} data.forms["all_sg"] = {stems.normal .. "l" .. vowels.e .. "n", stems.normal .. "l" .. vowels.e .. "k"} data.forms["ess_sg"] = {stems.n .. vowels.a} data.forms["tra_sg"] = {stems.normal .. "ksi"} data.forms["com_sg"] = {stems.n .. vowels.e .. "k"} data.forms["ins_sg"] = {stems.normal .. "n"} data.forms["abe_sg"] = {stems.normal .. "tt" .. vowels.a} data.forms["nom_pl"] = {stems.normal .. "t"} data.forms["acc_pl"] = {stems.normal .. "t"} data.forms["gen_pl"] = {stems.t .. vowels.e .. "n", stems.i .. "t" .. vowels.e .. "n"} data.forms["par_pl"] = {stems.i .. "t" .. vowels.a} data.forms["ine_pl"] = {stems.i .. "ss" .. vowels.a, stems.i .. "hn" .. vowels.a} data.forms["ela_pl"] = {stems.i .. "st" .. vowels.a} data.forms["ill_pl"] = {stems.i .. "s" .. vowels.e .. "n"} data.forms["ade_pl"] = {stems.i .. "ll" .. vowels.a} data.forms["abl_pl"] = {stems.i .. "lt" .. vowels.a} data.forms["all_pl"] = {stems.i .. "l" .. vowels.e .. "n", stems.i .. "l" .. vowels.e .. "k"} data.forms["ess_pl"] = {stems.i .. "n" .. vowels.a} data.forms["tra_pl"] = {stems.i .. "ksi"} data.forms["com_pl"] = {stems.i .. "n" .. vowels.e .. "k"} data.forms["ins_pl"] = {stems.i .. "n"} data.forms["abe_pl"] = {stems.i .. "tt" .. vowels.a} end

-- Functions for generating the inflection table

function show_form(form) if not form then return "&mdash;" elseif type(form) ~= "table" then error("a non-table value was given in the list of inflected forms.") end local ret = {} for key, subform in ipairs(form) do table.insert(ret, m_links.full_link({lang = lang, alt = "*" .. subform})) end return table.concat(ret, " ") end

-- Make the table function make_table(data) return [=[ Inflection of ]=] .. m_links.full_link({lang = lang, alt = "*" .. mw.title.getCurrentTitle.subpageText}, "term") .. (data.title and " (" .. data.title .. ")" or "") .. [=[ ]=]

end

return export