Jump to content

Module:se-pronouns

From Wiktionary, the free dictionary

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

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

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

local export = {}

-- 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)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


-- Inflection functions

inflections["ppron"] = function(args, data)
	data.title = "irregular"
	data.single = true
	
	local nom = args[1]; if nom == "" then nom = nil end
	
	if not nom and mw.title.getCurrentTitle().nsText == "Template" then
		nom = "mun"
	end
	
	local first = mw.ustring.sub(nom, 1, 1)
	
	if nom == "mun" or nom == "don" or nom == "son" then
		data.forms["nom"] = {first .. "on"}
		data.forms["acc"] = {first .. "ū"}
		data.forms["gen"] = {first .. "ū"}
		data.forms["ill"] = {first .. "u" .. (first == "m" and "n" or "t") .. "nje"}
		data.forms["loc"] = {first .. "ūs"}
		data.forms["com"] = {first .. "uinna"}
		data.forms["ess"] = {first .. "ūnin"}
		
		if nom == "mun" then
			table.insert(data.forms["nom"], 1, "mun")
		end
	elseif nom == "moai" or nom == "doai" or nom == "soai" then
		data.forms["nom"] = {first .. "oai"}
		data.forms["acc"] = {first .. "u" .. (first == "m" and "nˈ" or "d") .. "no"}
		data.forms["gen"] = {first .. "u" .. (first == "m" and "nˈ" or "d") .. "no"}
		data.forms["ill"] = {first .. "u" .. (first == "m" and "nˈ" or "d") .. "nuide"}
		data.forms["loc"] = {first .. "u" .. (first == "m" and "nˈ" or "d") .. "nos"}
		data.forms["com"] = {first .. "u" .. (first == "m" and "nˈ" or "d") .. "nuin"}
		data.forms["ess"] = {first .. "u" .. (first == "m" and "nˈ" or "d") .. "non"}
	elseif nom == "mii" or nom == "dii" or nom == "sii" then
		data.forms["nom"] = {first .. "ii"}
		data.forms["acc"] = {first .. "īn"}
		data.forms["gen"] = {first .. "īn"}
		data.forms["ill"] = {first .. "idjiide"}
		data.forms["loc"] = {first .. "īs"}
		data.forms["com"] = {first .. "īnguin"}
		data.forms["ess"] = {first .. "īnin"}
	else
		error("Invalid pronoun.")
	end
end


function postprocess(args, data)
	-- 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().text) or (data.forms["nom"] and (lang:makeEntryName(data.forms["nom"][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 "—"
		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, term = subform}))
		end
		
		return table.concat(ret, ", ")
	end
	
	local function repl(param)
		if param == "lemma" then
			return m_links.full_link({lang = lang, alt = mw.title.getCurrentTitle().text}, "term")
		elseif param == "info" then
			return data.title and " (" .. data.title .. ")" or ""
		else
			return show_form(data.forms[param])
		end
	end
	
	local wikicode
	
	if data.single then
		wikicode = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="border:solid 1px #CCCCFF; text-align: left;" cellspacing="1" cellpadding="2"
|- style="background: #E2F6E2; text-align: left;"
! class="vsToggleElement" colspan="2" | Inflection of {{{lemma}}}{{{info}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="width: 10em; background: #E2F6E2;" | Nominative
| style="width: 15em;" | {{{nom}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Genitive
| {{{gen}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="width: 10em; background: #E2F6E2;" | Nominative
| style="width: 15em;" | {{{nom}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Genitive
| {{{gen}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Accusative
| {{{acc}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Illative
| {{{ill}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Locative
| {{{loc}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Comitative
| {{{com}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Essive
| {{{ess}}}
|}]=]
	else
		wikicode = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="border:solid 1px #CCCCFF; text-align: left;" cellspacing="1" cellpadding="2"
|- style="background: #E2F6E2; text-align: left;"
! class="vsToggleElement" colspan="3" | Inflection of {{{lemma}}}{{{info}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="width: 10em; background: #E2F6E2;" | Nominative
| style="width: 15em;" colspan="2" | {{{nom_sg}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Genitive
| colspan="2" | {{{gen_sg}}}
|- class="vsHide"
! style="width: 10em; background:#c0e4c0" |
! style="width: 15em; background:#c0e4c0" | singular
! style="width: 15em; background:#c0e4c0" | plural
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Nominative
| {{{nom_sg}}}
| {{{nom_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Genitive
| {{{gen_sg}}}
| {{{gen_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Accusative
| {{{acc_sg}}}
| {{{acc_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Illative
| {{{ill_sg}}}
| {{{ill_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Locative
| {{{loc_sg}}}
| {{{loc_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Comitative
| {{{com_sg}}}
| {{{com_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Essive
| colspan="2" | {{{ess}}}
|}]=]
	end
	
	return mw.ustring.gsub(wikicode, "{{{([a-z_]+)}}}", repl)
end

return export