Module:sma-nominals

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

local export = {}

-- Inflection functions

function export.even(frame) local fparams = { [1] = {required = true}, }	local fargs = require("Module:parameters").process(frame.args, fparams) local params = { [1] = {required = true, default = ""}, ["attr"] = fargs[1] == "adjectives" and {list = true} or nil, ["n"] = fargs[1] == "nouns" and {} or nil, }	local args = require("Module:parameters").process(frame:getParent.args, params) local stem = require("Module:sma-common").Stem(args[1]) local data = { has_attr = fargs[1] == "adjectives", forms = {}, info = "even " .. require("Module:links").full_link({lang = lang, alt = stem.uvowel}, "term") .. "-stem", categories = {}, }	if not (mw.ustring.find(stem.uvowel, "^[ae]$") or stem.uvowel == "ie" or stem.uvowel == "oe") and mw.title.getCurrentTitle.nsText ~= "Template" then error("The final vowel(s) of the stem must be one of a, e, ie, oe.") end table.insert(data.categories, lang:getCanonicalName .. " even " .. fargs[1]) table.insert(data.categories, lang:getCanonicalName .. " even " .. (stem.uvowel or "") .. "-stem " .. fargs[1]) data.forms["nom|s"] = {stem:make_form{}} data.forms["acc|s"] = {stem:make_form{ending = "m"}} data.forms["gen|s"] = {stem:make_form{ending = "n"}} data.forms["ill|s"] = stem.uvowel == "ie" and {stem:make_form{ending = "n", variant = "e"}} or		{stem:make_form{ending = "se", variant = "normal3"}, stem:make_form{ending = "se", variant = "e"}} data.forms["ine|s"] = {stem:make_form{ending = "sne", variant = "normal3"}} data.forms["ela|s"] = {stem:make_form{ending = "ste", variant = "normal3"}} data.forms["com|s"] = {stem:make_form{ending = "jne", variant = "i3"}, stem:make_form{ending = "jne", variant = "i3_I"}} data.forms["nom|p"] = {stem:make_form{ending = "h", variant = "h"}} data.forms["acc|p"] = {stem:make_form{ending = "jde", variant = "i3"}, stem:make_form{ending = "jde", variant = "i3_I"}} data.forms["gen|p"] = {stem:make_form{ending = "j", variant = "j"}, stem:make_form{ending = "j", variant = "j_I"}} data.forms["ill|p"] = {stem:make_form{ending = "jde", variant = "i3"}, stem:make_form{ending = "jde", variant = "i3_I"}} data.forms["ine|p"] = {stem:make_form{ending = "jne", variant = "i3"}, stem:make_form{ending = "jne", variant = "i3_I"}} data.forms["ela|p"] = {stem:make_form{ending = "jste", variant = "j3"}, stem:make_form{ending = "jste", variant = "j3_I"}} data.forms["com|p"] = {stem:make_form{ending = "jgujmie", variant = "j"}, stem:make_form{ending = "jgujmie", variant = "j_I"}} data.forms["ess"] = {stem:make_form{ending = "jne", variant = "i3"}, stem:make_form{ending = "jne", variant = "i3_I"}} postprocess(args, data) return make_table(data) end

function postprocess(args, data) data.n = args["n"] if args["n"] == "p" then table.insert(data.categories, lang:getCanonicalName .. " pluralia tantum") elseif args["n"] == "s" then table.insert(data.categories, lang:getCanonicalName .. " uncountable nouns") elseif args["n"] then error("args= must be \"s\" or \"p\".") end for key, forms in pairs(data.forms) do		-- Do not show singular or plural forms for nominals that don't have them if (args["n"] == "p" and key:find("|s$")) or (args["n"] == "s" and key:find("|p$")) then forms = nil end -- Remove duplicate forms if forms then forms = require("Module:table").removeDuplicates(forms) end data.forms[key] = forms end if data.has_attr then if not args["attr"][1] then data.forms["attr"] = mw.clone(data.forms["nom|s"]) elseif args["attr"][1] ~= "-" then data.forms["attr"] = args["attr"] end end data.lemma = (data.forms["nom|" .. (data.n or "s")] or data.forms["acc|" .. (data.n or "s")])[1] -- Check if the lemma form matches the page name if (lang:makeEntryName(data.lemma)) ~= 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 repl(param) local accel = true local no_store = false if param == "info" then return mw.getContentLanguage:ucfirst(data.info or "") elseif string.sub(param, 1, 1) == "!" then no_store = true param = string.sub(param, 2) elseif string.sub(param, 1, 1) == "#" then accel = false param = string.sub(param, 2) end local forms = data.forms[param] if not forms then return "&mdash;" end local ret = {} for key, subform in ipairs(forms) do			table.insert(ret, require("Module:links").full_link({lang = lang, term = subform, accel = accel and {form = param, lemma = data.lemma, no_store = no_store} or nil})) end return table.concat(ret, " ") end local wikicode = {} table.insert(wikicode, [=[	return mw.ustring.gsub(table.concat(wikicode), "", repl) .. require("Module:utilities").format_categories(data.categories, lang) end

return export