Module:Åøy-nominals

local m_utilities = require("Module:utilities") local m_links = require("Module:links")

local export = {}

local lang = require("Module:languages").getByCode("et")

-- 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 infl_type = frame.args[1] or error("Inflection type has not been specified. Please pass parameter 1 to the module invocation") local args = frame:getParent.args if not inflections[infl_type] then error("Unknown inflection type '" .. infl_type .. "'") end local data = {forms = {}, title = nil, categories = {}} -- Generate the forms inflections[infl_type](args, data) -- Postprocess postprocess(args, data) if args["nosg"] then table.insert(data.categories, "et-decl with nosg") end if args["nopl"] then table.insert(data.categories, "et-decl with nopl") end if args["type"] then table.insert(data.categories, "et-decl with type") end return make_table(data) .. m_utilities.format_categories(data.categories, lang) end

--[=[	Inflection functions ]=]--

local stem_endings = {}

-- Singular stem_endings["nom_sg"] = stem_endings["gen_sg"] = "n"

stem_endings["dist_sg"] = {{stem = "dist_sg", ending = "k"} }stem_endings["comp_sg"] = {{stem = "comp_sg", ending = "kaan"}

-- Plural }stem_endings["nom_pl"] = {{stem = "gen_sg", ending = "t"} }stem_endings["gen_pl"] =

stem_endings["dist_pl"] = stem_endings["comp_pl"] = {{stem = "all_pl", ending = "ikaan"}

-- Make a copy of the endings, with front vowels }stem_endings = {["a"] = stem_endings, ["ä"] = mw.clone(stem_endings)} for form_key, subforms in pairs(stem_endings["ä"]) do	for _, form in pairs(subforms) do		form.ending = mw.ustring.gsub(form.ending, "([aouõ])", {["a"] = "ä", ["o"] = "ö", ["u"] = "ü", ["õ"] = "e"}) end end

-- Create forms based on each stem, by adding endings to it local function process_stems(data, stems, vh) -- For each of the case-and-number combinations that is defined above... for form_key, subforms in pairs(stem_endings[vh]) do		--- ...and each subform defined for it		for _, form in ipairs(subforms) do -- If the required stem has been provided, then... if stems[form.stem] and #stems[form.stem] > 0 then if not data.forms[form_key] then data.forms[form_key] = {} end -- ...add the ending to each provided stem for _, stem in ipairs(stems[form.stem]) do table.insert(data.forms[form_key], stem .. form.ending) end end end end end

local function get_param(args, first, prefix) local param = args[first]; if param == "" then param = nil end if not param then return {mw.title.getCurrentTitle.nsText == "Template" and "" or nil} end local ret = {param} local i = 2 while args[prefix .. i] do param = args[prefix .. i]; if param == "" then param = nil end table.insert(ret, param) i = i + 1 end return ret end

inflections["stems"] = function(args, data) local vh = args[1] or (mw.title.getCurrentTitle.nsText == "Template" and "a"); if not (vh == "a" or vh == "ä") then error("Parameter 9 must be \"a\" or \"ä\".") end local stems = {} stems["nom_sg"] = get_param(args, 1, "nom_sg") stems["nom_pl"] = get_param(args, 2, "nom_pl") stems["gen_sg"] = get_param(args, 3, "gen_sg") stems["gen_pl"] = get_param(args, 4, "gen_pl") stems["comp_sg"] = get_param(args, 5, "comp_sg") stems["comp_pl"] = get_param(args, 6, "comp_pl") stems["dist_sg"] = get_param(args, 7, "dist_sg") stems["dist_pl"] = get_param(args, 8, "dist_pl") process_stems(data, stems, vh) end

inflections["vastaus"] = function(args, data) local vh = args[1] or (mw.title.getCurrentTitle.nsText == "Template" and "a"); if not (vh == "a" or vh == "ä") then error("Parameter 9 must be \"a\" or \"ä\".") end local stems = {} stems["nom_sg"] = {params.base .. "s" .. params.a} stems["gen_sg"] = {params.base .. "ksen" .. params.a} stems["dist_sg"] = {params.base .. "ksek" .. params.a} stems["comp_sg"] = {params.base .. "ksekaan" .. params.a} stems["gen_pl"] = {params.base .. "ksent" .. params.a} stems["dist_pl"] = {params.base .. "kseki" .. params.a} stems["comp_pl"] = {params.base .. "ksikaan" .. params.a}	process_stems(data, stems, vh) end

-- Helper functions

function postprocess(args, data) local n = args["n"]; if n == "" then n = nil end if n == "pl" then table.insert(data.categories, lang:getCanonicalName .. " pluralia tantum") end -- TODO: This says "nouns", but this module is also used for adjectives! if n == "sg" then table.insert(data.categories, lang:getCanonicalName .. " uncountable nouns") end for key, form in pairs(data.forms) do		-- Do not show singular or plural forms for nominals that don't have them if (n == "pl" and key:find("_sg$")) or (n == "sg" and key:find("_pl$")) then form = nil end data.forms[key] = form end -- Check if the lemma form matches the page name local lemma_key = n == "pl" and "nom_pl" or "nom_sg" if data.forms[lemma_key] and data.forms[lemma_key][1] and lang:makeEntryName(data.forms[lemma_key][1]) ~= mw.title.getCurrentTitle.text then table.insert(data.categories, lang:getCanonicalName .. " entries with inflection not matching pagename") end end

-- Make the table function make_table(data) local 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(subform, nil, lang, nil, nil, nil, {}, false)) end return table.concat(ret, " ") end local function repl(param) if param == "lemma" then return m_links.full_link(nil, mw.title.getCurrentTitle.text, lang, nil, "term", nil, {}, false) elseif param == "info" then return data.title and " (" .. data.title .. ")" or "" else return show_form(data.forms[param]) end end local wikicode = [=[ Inflection of 	 ]=] return mw.ustring.gsub(wikicode, "", repl) end

return export