Module:smn-nominals

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

local export = {}

-- Inflection functions

function export.even(frame) local fparams = { [1] = {required = true}, ["nograd"] = {type = "boolean"}, }	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, ["poss"] = fargs[1] == "nouns" and {} or nil, ["Q31"] = not fargs["nograd"] and {type = "boolean"} or nil, }	local args = require("Module:parameters").process(frame:getParent.args, params) local stem = require("Module:smn-common").Stem(args[1], args["Q31"] and "Q31" or not fargs["nograd"]) local data = { has_attr = fargs[1] == "adjectives", has_poss = fargs[1] == "nouns" and not args["poss"], forms = {}, info = "even " .. require("Module:links").full_link({lang = lang, alt = stem.uvowel}, "term") .. "-stem", categories = {}, }	if stem.gradation then data.info = data.info .. ", " ..			require("Module:links").full_link({lang = lang, alt = stem.gradation.strong.scons}, "term") .. "-" ..			require("Module:links").full_link({lang = lang, alt = stem.gradation.weak.scons}, "term") .. " gradation" else data.info = data.info .. ", no gradation" end if not mw.ustring.find(stem.uvowel, "^[âeiouá]$") and mw.title.getCurrentTitle.nsText ~= "Template" then error("The final vowel(s) of the stem must be one of â, e, i, o, u, á.") end if fargs[1] == "nouns" and args["poss"] and args["poss"] ~= "-" then else table.insert(data.categories, lang:getCanonicalName .. " even " .. fargs[1]) table.insert(data.categories, lang:getCanonicalName .. " even " .. (stem.uvowel or "") .. "-stem " .. fargs[1]) if not stem.gradation then table.insert(data.categories, lang:getCanonicalName .. " non-gradating even " .. fargs[1]) end data.forms["nom|s"] = {stem:make_form{grade = "strong"}} data.forms["acc|s"] = {stem:make_form{grade = "weak"}} data.forms["gen|s"] = {stem:make_form{grade = "weak"}} data.forms["ill|s"] = {stem:make_form{grade = "strong", ending = "n", variant = "ill_sg"}} data.forms["loc|s"] = {stem:make_form{grade = "weak", ending = "st", variant = "loc_sg"}} data.forms["com|s"] = {stem:make_form{grade = "weak", ending = "jn", variant = "com_sg"}} data.forms["abe|s"] = {stem:make_form{grade = "weak", ending = "ttáá", variant = "abe_sg"}} data.forms["nom|p"] = {stem:make_form{grade = "weak", ending = "h", variant = "nom_pl"}} data.forms["acc|p"] = {stem:make_form{grade = "weak", ending = "jd", variant = "acc_pl"}} data.forms["gen|p"] = {stem:make_form{grade = "weak", ending = "j", variant = "abe_pl"}, stem:make_form{grade = "weak", ending = "j", variant = "acc_pl"}} data.forms["ill|p"] = {stem:make_form{grade = "weak", ending = "jd", variant = "com_sg"}} data.forms["loc|p"] = {stem:make_form{grade = "weak", ending = "jn", variant = "acc_pl"}} data.forms["com|p"] = {stem:make_form{grade = "weak", ending = "jguin", variant = "abe_pl"}} data.forms["abe|p"] = {stem:make_form{grade = "weak", ending = "jttáá", variant = "abe_pl"}} data.forms["ess"]   = {stem:make_form{grade = "strong", ending = "n", variant = "per"}} data.forms["par"]   = {stem:make_form{grade = "strong", ending = "d", variant = "per"}} end postprocess(args, data) return make_table(data) end

function postprocess(args, data) if args["poss"] then data.has_poss = false end 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, [=[ {| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="border:solid 1px #CCCCFF; text-align: left;" cellspacing="1" cellpadding="2" ! class="vsToggleElement" colspan="3" | ]=])
 * - style="background: #E2F6E2; text-align: left;"

if data.has_attr then table.insert(wikicode, [=[

! style="background: #E2F6E2;" | Attributive end table.insert(wikicode, [=[
 * - class="vsShow" style="background: #F2F2FF;"
 * colspan="2" | ]=])

! style="width: 8em; background: #E2F6E2;" | Nominative ! style="background: #E2F6E2;" | Genitive if data.has_attr then table.insert(wikicode, [=[
 * - class="vsShow" style="background: #F2F2FF;"
 * style="width: 15em;" colspan="2" |
 * - class="vsShow" style="background: #F2F2FF;"
 * colspan="2" | ]=])

! style="background: #E2F6E2;" | Attributive ]=])	end	table.insert(wikicode, [=[
 * - class="vsHide" style="background: #F2F2FF;"
 * colspan="2" |

! style="width: 8em; background: #C0E4C0;" | ! style="width: 12em; background: #C0E4C0;" | Singular ! style="width: 12em; background: #C0E4C0;" | Plural ! style="background: #E2F6E2;" | Nominative ! style="background: #E2F6E2;" | Accusative ! style="background: #E2F6E2;" | Genitive ! style="background: #E2F6E2;" | Illative ! style="background: #E2F6E2;" | Locative ! style="background: #E2F6E2;" | Comitative ! style="background: #E2F6E2;" | Abessive ! style="background: #E2F6E2;" | Essive ! style="background: #E2F6E2;" | Partitive -- Possessive forms if data.has_poss then table.insert(wikicode, [=[
 * - class="vsHide"
 * - class="vsHide" style="background: #F2F2FF;"
 * data-accel-col="1" |
 * data-accel-col="2" |
 * - class="vsHide" style="background: #F2F2FF;"
 * data-accel-col="1" |
 * data-accel-col="2" |
 * - class="vsHide" style="background: #F2F2FF;"
 * data-accel-col="1" |
 * data-accel-col="2" |
 * - class="vsHide" style="background: #F2F2FF;"
 * data-accel-col="1" |
 * data-accel-col="2" |
 * - class="vsHide" style="background: #F2F2FF;"
 * data-accel-col="1" |
 * data-accel-col="2" |
 * - class="vsHide" style="background: #F2F2FF;"
 * data-accel-col="1" |
 * data-accel-col="2" |
 * - class="vsHide" style="background: #F2F2FF;"
 * data-accel-col="1" |
 * data-accel-col="2" |
 * - class="vsHide" style="background: #F2F2FF;"
 * colspan="2" |
 * - class="vsHide" style="background: #F2F2FF;"
 * colspan="2" | ]=])

end table.insert(wikicode, "\n|}") return mw.ustring.gsub(table.concat(wikicode), "", repl) .. require("Module:utilities").format_categories(data.categories, lang) end
 * - class="vsHide"
 * colspan="3" style="padding: 0;" |

return export