Module:User:Victar/iir-nouns

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of Victar, for their own experimentation. Items in this module may be added and removed at Victar's discretion; do not rely on this module's stability.


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

local export = {}

local genders = {
	["m"] = "masculine",
	["f"] = "feminine",
	["n"] = "neuter",
}


-- Inflection functions

function export.a(frame)
	local params = {
		[1] = {default = mw.title.getCurrentTitle().nsText == "Template" and "{{{1}}}ás" or mw.title.getCurrentTitle().subpageText},

		["g"] = {required = true, default = "m"},
		["n"] = {},
	}

	local args = require("Module:parameters").process(frame:getParent().args, params)

	local data = {
		forms = {},
		info = nil,
		categories = {},
	}

	local stem, suffix = mw.ustring.match(args[1], "^(.-)(ás)$")

	if suffix ~= "ás" then
		error("a-stems must end in -ás")
	end
	
	data.info = "''a''-stem"
	table.insert(data.categories, lang:getCanonicalName() .. " a-stem nouns")
	
	data.forms["nom|s"] = {stem .. "ás"}
	data.forms["voc|s"] = {stem .. "á"}
	data.forms["acc|s"] = {stem .. "ám"}
	data.forms["ins|s"] = {stem .. "ā́"}
	data.forms["abl|s"] = {stem .. "ā́t"}
	data.forms["dat|s"] = {stem .. "ā́y"}
	data.forms["gen|s"] = {stem .. "ásya"}
	data.forms["loc|s"] = {stem .. "áy"}
	
	data.forms["nom|d"] = {stem .. "ā́"}
	data.forms["voc|d"] = data.forms["nom|d"]
	data.forms["acc|d"] = data.forms["nom|d"]
	data.forms["ins|d"] = {stem .. "áybʰyaH", stem .. "ā́bʰyām"}
	data.forms["abl|d"] = data.forms["ins|d"]
	data.forms["dat|d"] = data.forms["ins|d"]
	data.forms["gen|d"] = {stem .. "áyās"}
	data.forms["loc|d"] = {stem .. "áyaw"}
	
	data.forms["nom|p"] = {stem .. "ā́", stem .. "ā́s(as)"}
	data.forms["voc|p"] = data.forms["nom|p"]
	data.forms["acc|p"] = {stem .. "ā́ns"}
	data.forms["ins|p"] = {stem .. "ā́yš"}
	data.forms["abl|p"] = {stem .. "áybʰyas"}
	data.forms["dat|p"] = data.forms["abl|p"]
	data.forms["gen|p"] = {stem .. "ā́na(H)m"}
	data.forms["loc|p"] = {stem .. "áyšu"}

	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() .. " singularia tantum")
	elseif args["n"] then
		error("args= must be \"s\" or \"p\".")
	end

	for key, form 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
			form = nil
		end

		data.forms[key] = form
	end
end

-- Make the table
function make_table(data)
	local function repl(param)
		if param == "info" then
			return mw.getContentLanguage():ucfirst(data.info or "")
		end
		
		local forms = data.forms[param]
		
		if not forms then
			return "—"
		end
		
		local ret = {}
		
		for key, subform in ipairs(forms) do
			table.insert(ret, require("Module:links").full_link({lang = lang, alt = "*" .. subform}))
		end
		
		return table.concat(ret, ", ")
	end
	
	local wikicode = {}
	table.insert(wikicode, [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="border: solid 1px #CCCCCC;"
|- style="background: #CCCCCC; text-align: left;"
! class="vsToggleElement" colspan="3" | {{{info}}}
|- class="vsShow"
! style="width: 9em;" |
! style="width: 15em; background: #DDDDDD;" colspan="2" | Singular
|- class="vsShow"
! style="background: #EEEEEE" | Nominative
| colspan="2" | {{{nom|s}}}
|- class="vsShow"
! style="background: #EEEEEE" | Genitive
| colspan="2" | {{{gen|s}}}
|- class="vsHide"
| style="width: 9em;" |
! style="width: 15em; background: #DDDDDD;" | Singular
! style="width: 15em; background: #DDDDDD;" | Plural
|- class="vsHide"
! style="background: #EEEEEE" | Nominative
| {{{nom|s}}}
| {{{nom|p}}}
|- class="vsHide"
! style="background: #EEEEEE" | Accusative
| {{{acc|s}}}
| {{{acc|p}}}
|- class="vsHide"
! style="background: #EEEEEE" | Genitive
| {{{gen|s}}}
| {{{gen|p}}}
|- class="vsHide"
! style="background: #EEEEEE" | Dative
| {{{dat|s}}}
| {{{dat|p}}}
|- class="vsHide"
! style="background: #EEEEEE" | Instrumental
| {{{ins|s}}}
| {{{ins|p}}}
|}]=])

	return mw.ustring.gsub(table.concat(wikicode), "{{{([#!]?[a-z0-9|]+)}}}", repl) .. require("Module:utilities").format_categories(data.categories, lang)
end

return export