Module:et-nominals

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

This module is used for inflecting Estonian 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

function get_params(args, num, gradation)
	local params = {}
	
	params.base = args[1] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{1}}}"); if not params.base or params.base == "" then error("Parameter 1 (base stem) may not be empty.") end
	
	if gradation then
		if num == 5 then
			params.strong = args[2] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{2}}}") or ""
			params.weak = args[3] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{3}}}") or ""
			params.final = args[4] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{4}}}"); if not params.final or params.final == "" then error("Parameter 4 (final letter(s)) may not be empty.") end
			params.final_nom_sg = args[5] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{5}}}") or ""
		elseif num == 4 then
			params.strong = args[2] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{2}}}") or ""
			params.weak = args[3] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{3}}}") or ""
			params.final = args[4] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{4}}}"); if not params.final or params.final == "" then error("Parameter 4 (final letter(s)) may not be empty.") end
		elseif num == 3 then
			params.strong = args[2] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{2}}}") or ""
			params.weak = args[3] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{3}}}") or ""
		end
	else
		if num == 3 then
			params.final = args[2] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{2}}}"); if not params.final or params.final == "" then error("Parameter 2 (final letter(s)) may not be empty.") end
			params.final_nom_sg = args[3] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{3}}}") or ""
		elseif num == 2 then
			params.final = args[2] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{2}}}") or ""
		end
	end
	
	return params	
end


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

local stem_endings = {}

stem_endings["nom_sg"] = {
	["nom_sg"] = "",
}

stem_endings["sg"] = {
	["gen_sg"]      = "",
	["ill_sg_long"] = "sse",
	["ine_sg"]      = "s",
	["ela_sg"]      = "st",
	["all_sg"]      = "le",
	["ade_sg"]      = "l",
	["abl_sg"]      = "lt",
	["tra_sg"]      = "ks",
	["ter_sg"]      = "ni",
	["ess_sg"]      = "na",
	["abe_sg"]      = "ta",
	["com_sg"]      = "ga",
	["nom_pl"]      = "d",
}

stem_endings["par_sg"] = {
	["par_sg"] = "",
}

stem_endings["ill_sg_short"] = {
	["ill_sg_short"] = "",
}

stem_endings["pl_long"] = {
	["gen_pl"]      = "",
	["ill_pl_long"] = "sse",
	["ine_pl_long"] = "s",
	["ela_pl_long"] = "st",
	["all_pl_long"] = "le",
	["ade_pl_long"] = "l",
	["abl_pl_long"] = "lt",
	["tra_pl_long"] = "ks",
	["ter_pl"]      = "ni",
	["ess_pl"]      = "na",
	["abe_pl"]      = "ta",
	["com_pl"]      = "ga",
}

stem_endings["pl_short"] = {
	["ill_pl_short"] = "sse",
	["ine_pl_short"] = "s",
	["ela_pl_short"] = "st",
	["all_pl_short"] = "le",
	["ade_pl_short"] = "l",
	["abl_pl_short"] = "lt",
	["tra_pl_short"] = "ks",
}

stem_endings["par_pl"] = {
	["par_pl"] = "",
}


-- Create forms based on each stem, by adding endings to it
local function process_stems(data, stems)
	-- Go through each of the stems given
	for stem_key, substems in pairs(stems) do
		for _, stem in ipairs(substems) do
			-- Attach the endings to the stem
			for form_key, ending in pairs(stem_endings[stem_key]) do
				if not data.forms[form_key] then
					data.forms[form_key] = {}
				end
				
				table.insert(data.forms[form_key], stem .. ending)
			end
		end
	end
end


inflections["ohutu"] = function(args, data)
	data.title = "ÕS type "
	table.insert(data.categories, lang:getCanonicalName() .. " ohutu-type nominals")
	
	local params = get_params(args, 1)
	local i_stem = mw.ustring.gsub(params.base, "i$", "e")
	
	if mw.ustring.find(params.base, "i$") then
		data.title = data.title .. "[[Appendix:Estonian nominal inflection#veski|1e/veski]], no gradation"
	else
		data.title = data.title .. "[[Appendix:Estonian nominal inflection#ohutu|1/ohutu]], no gradation"
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.base}
	stems["par_sg"]       = {params.base .. "t"}
	stems["ill_sg_short"] = nil
	stems["pl_long"]      = {params.base .. "te"}
	stems["pl_short"]     = {i_stem .. "i"}
	stems["par_pl"]       = {i_stem .. "id"}
	
	process_stems(data, stems)
end

inflections["õpik"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#õpik|2/õpik]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " õpik-type nominals")
	
	local params = get_params(args, 3)
	local i_stem = mw.ustring.gsub(params.base .. params.final, "i$", "e")
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.final_nom_sg}
	stems["sg"]           = {params.base .. params.final}
	stems["par_sg"]       = {params.base .. params.final .. "t"}
	stems["ill_sg_short"] = nil
	stems["pl_long"]      = {params.base .. params.final .. "te"}
	stems["pl_short"]     = {i_stem .. "i"}
	stems["par_pl"]       = {i_stem .. "id"}
	
	process_stems(data, stems)
end

inflections["vaher"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#vaher|3/vaher]]"
	table.insert(data.categories, lang:getCanonicalName() .. " vaher-type nominals")
	
	local params = get_params(args, 5, true)
	local i_stem = mw.ustring.gsub(params.base .. params.strong .. params.final, "i$", "e")
	
	if params.strong == params.weak or params.strong == params.weak .. params.weak then
		data.title = data.title .. ", length gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.weak .. params.final_nom_sg}
	stems["sg"]           = {params.base .. params.strong .. params.final}
	stems["par_sg"]       = {params.base .. params.strong .. params.final .. "t"}
	stems["ill_sg_short"] = nil
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "te"}
	stems["pl_short"]     = {i_stem .. "i"}
	stems["par_pl"]       = {i_stem .. "id"}
	
	process_stems(data, stems)
end

inflections["ase"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#ase|4/ase]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " ase-type nominals")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.base .. "me"}
	stems["par_sg"]       = {params.base .. params.final}
	stems["ill_sg_short"] = nil
	stems["pl_long"]      = {params.base .. "mete"}
	stems["pl_short"]     = {params.base .. "mei"}
	stems["par_pl"]       = {params.base .. "meid"}
	
	process_stems(data, stems)
end

inflections["liige"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#liige|5/liige]]"
	table.insert(data.categories, lang:getCanonicalName() .. " liige-type nominals")
	
	local params = get_params(args, 5, true)
	local i_stem = mw.ustring.gsub(params.base .. params.strong .. params.final, "i$", "e")
	
	if params.strong == params.weak or params.strong == params.weak .. params.weak then
		data.title = data.title .. ", length gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.weak .. params.final_nom_sg}
	stems["sg"]           = {params.base .. params.strong .. params.final}
	stems["par_sg"]       = {params.base .. params.weak .. params.final_nom_sg .. "t"}
	stems["ill_sg_short"] = nil
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "te"}
	stems["pl_short"]     = {i_stem .. "i"}
	stems["par_pl"]       = {i_stem .. "id"}
	
	process_stems(data, stems)
end

inflections["mõte"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#mõte|6/mõte]]"
	table.insert(data.categories, lang:getCanonicalName() .. " mõte-type nominals")
	
	local params = get_params(args, 4, true)
	
	if params.strong == params.weak or params.strong == params.weak .. params.weak then
		data.title = data.title .. ", length gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.weak .. params.final}
	stems["sg"]           = {params.base .. params.strong .. params.final}
	stems["par_sg"]       = {params.base .. params.weak .. params.final .. "t"}
	stems["ill_sg_short"] = nil
	stems["pl_long"]      = {params.base .. params.weak .. params.final .. "te"}
	stems["pl_short"]     = {params.base .. params.strong .. params.final .. "i"}
	stems["par_pl"]       = {params.base .. params.strong .. params.final .. "id"}
	
	process_stems(data, stems)
end

inflections["kallas"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#kallas|7/kallas]]"
	table.insert(data.categories, lang:getCanonicalName() .. " kallas-type nominals")
	
	local params = get_params(args, 5, true)
	local i_stem = mw.ustring.gsub(params.base .. params.strong .. params.final, "i$", "e")
	
	if params.strong == params.weak or params.strong == params.weak .. params.weak then
		data.title = data.title .. ", length gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.weak .. params.final_nom_sg}
	stems["sg"]           = {params.base .. params.strong .. params.final}
	stems["par_sg"]       = {params.base .. params.weak .. params.final_nom_sg .. "t"}
	stems["ill_sg_short"] = nil
	stems["pl_long"]      = {params.base .. params.weak .. params.final_nom_sg .. "te"}
	stems["pl_short"]     = {i_stem .. "i"}
	stems["par_pl"]       = {i_stem .. "id"}
	
	process_stems(data, stems)
end

inflections["küünal"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#küünal|8/küünal]]"
	table.insert(data.categories, lang:getCanonicalName() .. " küünal-type nominals")
	
	local params = get_params(args, 5, true)
	
	if params.strong == params.weak or params.strong == params.weak .. params.weak then
		data.title = data.title .. ", length gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.weak .. params.final_nom_sg}
	stems["sg"]           = {params.base .. params.strong .. params.final}
	stems["par_sg"]       = {params.base .. params.weak .. params.final_nom_sg .. "t"}
	stems["ill_sg_short"] = nil
	stems["pl_long"]      = {params.base .. params.weak .. params.final_nom_sg .. "de"}
	stems["pl_short"]     = {params.base .. params.strong .. params.final .. "i"}
	stems["par_pl"]       = {params.base .. params.strong .. params.final .. "id"}
	
	process_stems(data, stems)
end

inflections["katus"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#katus|9/katus]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " katus-type nominals")
	
	local params = get_params(args, 1)
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. "s"}
	stems["sg"]           = {params.base .. "se"}
	stems["par_sg"]       = {params.base .. "st"}
	stems["ill_sg_short"] = nil
	stems["pl_long"]      = {params.base .. "ste"}
	stems["pl_short"]     = {params.base .. "sei"}
	stems["par_pl"]       = {params.base .. "seid"}
	
	process_stems(data, stems)
end

inflections["soolane"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#soolane|10/soolane]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " soolane-type nominals")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.final}
	stems["sg"]           = {params.base .. "se"}
	stems["par_sg"]       = {params.base .. "st"}
	stems["ill_sg_short"] = nil
	stems["pl_long"]      = {params.base .. "ste"}
	stems["pl_short"]     = {params.base .. "sei"}
	stems["par_pl"]       = {params.base .. "seid"}
	
	process_stems(data, stems)
end

inflections["harjutus"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#harjutus|11/harjutus]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " harjutus-type nominals")
	
	local params = get_params(args, 1)
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. "s"}
	stems["sg"]           = {params.base .. "se"}
	stems["par_sg"]       = {params.base .. "st"}
	stems["ill_sg_short"] = {params.base .. "sse"}
	stems["pl_long"]      = {params.base .. "ste"}
	stems["pl_short"]     = {params.base .. "si"}
	stems["par_pl"]       = {params.base .. "si"}
	
	process_stems(data, stems)
end

inflections["oluline"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#oluline|12/oluline]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " oluline-type nominals")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.final}
	stems["sg"]           = {params.base .. "se"}
	stems["par_sg"]       = {params.base .. "st"}
	stems["ill_sg_short"] = {params.base .. "sse"}
	stems["pl_long"]      = {params.base .. "ste"}
	stems["pl_short"]     = {params.base .. "si"}
	stems["par_pl"]       = {params.base .. "si"}
	
	process_stems(data, stems)
end

inflections["suur"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#suur|13/suur]], length gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " suur-type nominals")
	
	local params = get_params(args, 1)
	local weak_stem = params.base
	local par_stem = params.base
	local ill_sg_stem = params.base .."de"
	local pl_stem = params.base
	
	if mw.ustring.find(params.base, "m$") then 
		par_stem = mw.ustring.gsub(params.base, "m$", "n")
		ill_sg_stem = mw.ustring.gsub(params.base, "m$", "n")
		pl_stem = mw.ustring.gsub(params.base, "m$", "n")
	end
	
	if mw.ustring.find(params.base, "mees$") then 
		ill_sg_stem = nil
		weak_stem = mw.ustring.gsub(params.base, "es$", "h")
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {weak_stem .. "e"}
	stems["par_sg"]       = {par_stem .. "t"}
	stems["ill_sg_short"] = {ill_sg_stem}
	stems["pl_long"]      = {pl_stem .. "te"}
	stems["pl_short"]     = {weak_stem .. "i"}
	stems["par_pl"]       = {weak_stem .. "i"}
	
	process_stems(data, stems)
end

inflections["uus"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#uus|14/uus]]"
	table.insert(data.categories, lang:getCanonicalName() .. " uus-type nominals")
	
	local params = get_params(args, 2)
	local s_stem = mw.ustring.gsub(params.base .. params.final, "n$", "")
	local t_stem = params.base .. params.final
	
	if params.final ~= "" then
		data.title = data.title .. ", ''" .. params.final .. "d/" .. params.final .. "t-" .. params.final .. params.final .. "-" .. params.final .. "s'' gradation"
	else
		data.title = data.title .. ", ''d/t-ø-s'' gradation"
	end
	
	if mw.ustring.find(t_stem, "([ptk])s$") then
		s_stem = mw.ustring.gsub(params.base, "s$", "")
		
		local consonant = mw.ustring.match(t_stem, "([ptk])")
		t_stem = mw.ustring.gsub(t_stem, consonant .. "s$", "s")
	end
	
	local stems = {}
	stems["nom_sg"]       = {s_stem .. "s"}
	stems["sg"]           = {params.base .. params.final .. params.final .. "e"}
	stems["par_sg"]       = {t_stem .. "t"}
	stems["ill_sg_short"] = {params.base .. params.final .. "de"}
	stems["pl_long"]      = {t_stem .. "te"}
	stems["pl_short"]     = {s_stem .. "si"}
	stems["par_pl"]       = {s_stem .. "si"}
	
	process_stems(data, stems)
end

inflections["käsi"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#käsi|15/käsi]], ''d/t-ø-s'' gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " käsi-type nominals")
	
	local params = get_params(args, 1)
	local weak_stem = params.base
	
	if mw.ustring.find(params.base, "u$") then
		-- susi
		weak_stem = mw.ustring.gsub(params.base, "u$", "o")
	elseif mw.ustring.find(params.base, "ü$") then
		-- süsi
		weak_stem = mw.ustring.gsub(params.base, "ü$", "ö")
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. "si"}
	stems["sg"]           = {weak_stem .. "e"}
	stems["par_sg"]       = {params.base .. "tt"}
	stems["ill_sg_short"] = {params.base .. "tte"}
	stems["pl_long"]      = {params.base .. "te"}
	stems["pl_short"]     = {params.base .. "si"}
	stems["par_pl"]       = {params.base .. "si"}
	
	process_stems(data, stems)
end

inflections["pere"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#pere|16/pere]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " pere-type nominals")
	
	local params = get_params(args, 1)
	local ill_sg_stem = params.base
	
	if mw.ustring.find(ill_sg_stem, "[^aeiouõäöü][aeiouõäöü][^aeiouõäöü][aeiouõäöü]$") or mw.ustring.find(ill_sg_stem, "^[aeiouõäöü][^aeiouõäöü][aeiouõäöü]$") then
		ill_sg_stem = mw.ustring.gsub(ill_sg_stem, "(.)(.)$", "%1%1%2")
		else ill_sg_stem = nil
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.base}
	stems["par_sg"]       = {params.base .. "t"}
	stems["ill_sg_short"] = {ill_sg_stem}
	stems["pl_long"]      = {params.base .. "de"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.base .. "sid"}
	
	process_stems(data, stems)
end

inflections["elu"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#elu|17/elu]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " elu-type nominals")
	
	local params = get_params(args, 1)
	local ill_sg_stem = params.base
	
	if mw.ustring.find(ill_sg_stem, "[^aeiouõäöü][aeiouõäöü][^aeiouõäöü][aeiouõäöü]$") or mw.ustring.find(ill_sg_stem, "^[aeiouõäöü][^aeiouõäöü][aeiouõäöü]$") then
		local base, cons, vowel = mw.ustring.match(ill_sg_stem, "^(.-)(.)(.)$")
		
		if cons == "b" then
			ill_sg_stem = base .. "pp" .. vowel
		elseif cons == "d" then
			ill_sg_stem = base .. "tt" .. vowel
		elseif cons == "g" then
			ill_sg_stem = base .. "kk" .. vowel
		elseif cons == "v" then
			ill_sg_stem = nil
		elseif cons == "" then
			ill_sg_stem = nil
		else
			ill_sg_stem = base .. cons .. cons .. vowel
		end
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.base}
	stems["par_sg"]       = {params.base}
	stems["ill_sg_short"] = {ill_sg_stem}
	stems["pl_long"]      = {params.base .. "de"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.base .. "sid"}
	
	process_stems(data, stems)
end

inflections["kivi"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#kivi|17e/kivi]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " kivi-type nominals")
	
	local params = get_params(args, 1)
	local pl_stem = mw.ustring.gsub(params.base, "[aeiouõäöü]$", "e")
	local ill_sg_stem = params.base
	
	if mw.ustring.find(ill_sg_stem, "[^aeiouõäöü][aeiouõäöü][^aeiouõäöü][aeiouõäöü]$") or mw.ustring.find(ill_sg_stem, "^[aeiouõäöü][^aeiouõäöü][aeiouõäöü]$") then
		ill_sg_stem = mw.ustring.gsub(ill_sg_stem, "(.)(.)$", "%1%1%2")
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.base}
	stems["par_sg"]       = {params.base}
	stems["ill_sg_short"] = {ill_sg_stem}
	stems["pl_long"]      = {params.base .. "de"}
	stems["pl_short"]     = {pl_stem}
	stems["par_pl"]       = {pl_stem, params.base .. "sid"}
	
	process_stems(data, stems)
end

inflections["pesa"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#pesa|17i/pesa]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " pesa-type nominals")
	
	local params = get_params(args, 1)
	local pl_stem = mw.ustring.gsub(params.base, "[aeiouõäöü]$", "i")
	local ill_sg_stem = params.base
	
	if mw.ustring.find(ill_sg_stem, "[^aeiouõäöü][aeiouõäöü][^aeiouõäöü][aeiouõäöü]$") or mw.ustring.find(ill_sg_stem, "^[aeiouõäöü][^aeiouõäöü][aeiouõäöü]$") then
		ill_sg_stem = mw.ustring.gsub(ill_sg_stem, "(.)(.)$", "%1%1%2")
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.base}
	stems["par_sg"]       = {params.base}
	stems["ill_sg_short"] = {ill_sg_stem}
	stems["pl_long"]      = {params.base .. "de"}
	stems["pl_short"]     = {pl_stem}
	stems["par_pl"]       = {pl_stem, params.base .. "sid"}
	
	process_stems(data, stems)
end

inflections["sõna"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#sõna|17u/sõna]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " sõna-type nominals")
	
	local params = get_params(args, 1)
	local pl_stem = mw.ustring.gsub(params.base, "[aeiouõäöü]$", "u")
	local ill_sg_stem = params.base
	
	if mw.ustring.find(ill_sg_stem, "[^aeiouõäöü][aeiouõäöü][^aeiouõäöü][aeiouõäöü]$") or mw.ustring.find(ill_sg_stem, "^[aeiouõäöü][^aeiouõäöü][aeiouõäöü]$") then
		local base, cons, vowel = mw.ustring.match(ill_sg_stem, "^(.-)(.)(.)$")
		
		if cons == "b" then
			ill_sg_stem = base .. "pp" .. vowel
		else
			ill_sg_stem = base .. cons .. cons .. vowel
		end
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.base}
	stems["par_sg"]       = {params.base}
	stems["ill_sg_short"] = {ill_sg_stem}
	stems["pl_long"]      = {params.base .. "de"}
	stems["pl_short"]     = {pl_stem}
	stems["par_pl"]       = {pl_stem, params.base .. "sid"}
	
	process_stems(data, stems)
end

inflections["nägu"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#nägu|18/nägu]]"
	table.insert(data.categories, lang:getCanonicalName() .. " nägu-type nominals")
	
	local params = get_params(args, 4, true)
	
	if params.strong == params.weak then
		data.title = data.title .. ", no gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end
	
	local extra_strong = params.strong
	local weak_stem = params.base .. params.weak .. params.final
	
	if params.strong == "b" then
		extra_strong = "pp"
	elseif params.strong == "d" then
		extra_strong = "tt"
	elseif params.strong == "g" then
		extra_strong = "kk"
	end
	
	if params.weak == "" then
		if mw.ustring.find(params.base, "ä$") and params.final == "u" then
			-- nägu
			weak_stem = params.base .. "o"
		elseif mw.ustring.find(params.base, "a$") and params.final == "u" then
			-- madu
			weak_stem = params.base .. "o"
		end
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.strong .. params.final}
	stems["sg"]           = {weak_stem}
	stems["par_sg"]       = {params.base .. params.strong .. params.final}
	stems["ill_sg_short"] = {params.base .. extra_strong .. params.final}
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "de"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.base .. params.strong .. params.final .. "sid"}
	
	process_stems(data, stems)
end

inflections["tuba"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#tuba|18e/tuba]]"
	table.insert(data.categories, lang:getCanonicalName() .. " tuba-type nominals")
	
	local params = get_params(args, 4, true)
	
	if params.strong == params.weak then
		data.title = data.title .. ", no gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end
	
	local extra_strong = params.strong
	local weak_stem = params.base .. params.weak .. params.final
	
	if params.strong == "b" then
		extra_strong = "pp"
	elseif params.strong == "d" then
		extra_strong = "tt"
	elseif params.strong == "g" then
		extra_strong = "kk"
	end
	
	if params.weak == "" then
		if mw.ustring.find(params.base, "u$") then
			-- tuba
			if params.final == "a" then
				weak_stem = mw.ustring.gsub(params.base, "u$", "o") .. params.final
			end
		end
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.strong .. params.final}
	stems["sg"]           = {weak_stem}
	stems["par_sg"]       = {params.base .. params.strong .. params.final}
	stems["ill_sg_short"] = {params.base .. extra_strong .. params.final}
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "de"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.base .. params.strong .. "e", params.base .. params.strong .. params.final .. "sid"}
	
	process_stems(data, stems)
end

inflections["sõda"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#sõda|18u/sõda]]"
	table.insert(data.categories, lang:getCanonicalName() .. " sõda-type nominals")
	
	local params = get_params(args, 4, true)
	
	if params.strong == params.weak then
		data.title = data.title .. ", no gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end
	
	local extra_strong = params.strong
	local weak_stem = params.base .. params.weak .. params.final
	local weak_pl_stem = params.base .. params.weak .. "u"
	
	if params.strong == "b" then
		extra_strong = "pp"
	elseif params.strong == "d" then
		extra_strong = "tt"
	elseif params.strong == "g" then
		extra_strong = "kk"
	end
	
	if params.weak == "" then
		if mw.ustring.find(params.base, "i$") then
			-- rida
			if params.final == "a" then
				weak_stem = mw.ustring.gsub(params.base, "i$", "e") .. params.final
			end
			
			weak_pl_stem = nil
		end
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.strong .. params.final}
	stems["sg"]           = {weak_stem}
	stems["par_sg"]       = {params.base .. params.strong .. params.final}
	stems["ill_sg_short"] = {params.base .. extra_strong .. params.final}
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "de"}
	stems["pl_short"]     = {weak_pl_stem}
	stems["par_pl"]       = {params.base .. params.strong .. "u", params.base .. params.strong .. params.final .. "sid"}
	
	process_stems(data, stems)
end

inflections["seminar"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#seminar|19/seminar]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " seminar-type nominals")
	
	local params = get_params(args, 1)
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.base .. "i"}
	stems["par_sg"]       = {params.base .. "i"}
	stems["ill_sg_short"] = {params.base .. "i"}
	stems["pl_long"]      = {params.base .. "ide"}
	stems["pl_short"]     = {params.base .. "e"}
	stems["par_pl"]       = {params.base .. "e", params.base .. "isid"}
	
	process_stems(data, stems)
end

inflections["süli"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#süli|20/süli]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " süli-type nominals")
	
	local params = get_params(args, 1)
	local ill_sg_stem = params.base
	
	if mw.ustring.find(ill_sg_stem, "[^aeiouõäöü][aeiouõäöü][^aeiouõäöü]$") or mw.ustring.find(ill_sg_stem, "^[aeiouõäöü][^aeiouõäöü]$") then
		local base, cons = mw.ustring.match(ill_sg_stem, "^(.-)(.)$")
		ill_sg_stem = base .. cons .. cons
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. "i"}
	stems["sg"]           = {params.base .. "e"}
	stems["par_sg"]       = {params.base .. "e"}
	stems["ill_sg_short"] = {ill_sg_stem .. "e"}
	stems["pl_long"]      = {params.base  .. "ede"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.base .. "esid"}
	
	process_stems(data, stems)
end

inflections["meri"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#meri|20/meri]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " meri-type nominals")
	
	local params = get_params(args, 1)
	local ill_sg_stem = params.base
	local par_t = "d"
	local par_stem = params.base .. par_t
	
	if mw.ustring.find(params.base, "m$") then 
		par_stem = mw.ustring.gsub(params.base, "m$", "n") .. par_t
	end
	
	if mw.ustring.find(ill_sg_stem, "[^aeiouõäöü][aeiouõäöü][^aeiouõäöü]$") or mw.ustring.find(ill_sg_stem, "^[aeiouõäöü][^aeiouõäöü]$") then
		local base, cons = mw.ustring.match(ill_sg_stem, "^(.-)(.)$")
		ill_sg_stem = base .. cons .. cons
	end
	
	if mw.ustring.find(params.base, "[ptks]$") then 
		par_t = "t" -- kusi
		else par_t = "d"
	end	
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. "i"}
	stems["sg"]           = {params.base .. "e"}
	stems["par_sg"]       = {par_stem}
	stems["ill_sg_short"] = {ill_sg_stem .. "e"}
	stems["pl_long"]      = {params.base  .. "ede"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.base .. "esid"}
	
	process_stems(data, stems)
end

inflections["jõgi"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#jõgi|21/jõgi]]"
	table.insert(data.categories, lang:getCanonicalName() .. " jõgi-type nominals")
	
	local params = get_params(args, 3, true)
	local extra_strong = params.strong
	
	if params.strong == "g" then
		extra_strong = "kk"
	end
	
	if params.strong == params.weak or params.strong == params.weak .. params.weak then
		data.title = data.title .. ", length gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.strong .. "i"}
	stems["sg"]           = {params.base .. params.weak .. "e"}
	stems["par_sg"]       = {params.base .. params.strong .. "e"}
	stems["ill_sg_short"] = {params.base .. extra_strong .. "e"}
	stems["pl_long"]      = {params.base .. params.strong .. "ede"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.base .. params.strong .. "esid"}
	
	process_stems(data, stems)
end

inflections["põu"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#põu|22/põu]]"
	table.insert(data.categories, lang:getCanonicalName() .. " põu-type nominals")
	
	local params = get_params(args, 4, true)
	
	if params.strong == params.weak or params.strong == params.weak .. params.weak then
		data.title = data.title .. ", length gradation"
	elseif mw.ustring.find(params.base, "ks$") then
		data.title = data.title .. ", irregular gradation"
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.weak .. params.final}
	stems["par_sg"]       = {params.strong .. params.final}
	stems["ill_sg_short"] = {params.strong .. params.final}
	stems["pl_long"]      = {params.strong .. params.final .. "de"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.strong .. params.final .. "sid"}
	
	process_stems(data, stems)
end

inflections["riik"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#riik|22e/riik]]"
	table.insert(data.categories, lang:getCanonicalName() .. " riik-type nominals")
	
	local params = get_params(args, 4, true)
	local weak_stem = params.base .. params.weak .. params.final
	local pl_short_stem = params.base .. params.weak .. "e"
	
	if params.strong == params.weak or params.strong == params.weak .. params.weak then
		data.title = data.title .. ", length gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end
	
	if mw.ustring.find(params.base, "[ou]$") and params.final == "u" and params.weak == "" then 
		weak_stem = params.base .. params.weak
	end

	if params.weak == "" and mw.ustring.match(params.base, "([aeiouõäöü])([aeiouõäöü])$") then
		pl_short_stem = nil
	else
		pl_short_stem = pl_short_stem
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.strong}
	stems["sg"]           = {weak_stem}
	stems["par_sg"]       = {params.base .. params.strong .. params.final}
	stems["ill_sg_short"] = {params.base .. params.strong .. params.final}
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "de"}
	stems["pl_short"]     = {pl_short_stem}
	stems["par_pl"]       = {params.base .. params.strong .. "e", params.base .. params.strong .. params.final .. "sid"}
	
	process_stems(data, stems)
	
end

inflections["külm"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#külm|22i/külm]]"
	table.insert(data.categories, lang:getCanonicalName() .. " külm-type nominals")
	
	local params = get_params(args, 4, true)
	local pl_short_stem = params.base .. params.weak .. "i"
	
	if params.strong == params.weak or params.strong == params.weak .. params.weak then
		data.title = data.title .. ", length gradation"
	elseif params.strong == "eg" and params.weak == "j" then
		data.title = data.title .. ", ''g-j'' gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end

	if params.weak == "" and mw.ustring.match(params.base, "([aeiouõäöü])([aeiouõäöü])$") then
		pl_short_stem = nil
	else
		pl_short_stem = pl_short_stem
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.strong}
	stems["sg"]           = {params.base .. params.weak .. params.final}
	stems["par_sg"]       = {params.base .. params.strong .. params.final}
	stems["ill_sg_short"] = {params.base .. params.strong .. params.final}
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "de"}
	stems["pl_short"]     = {pl_short_stem}
	stems["par_pl"]       = {params.base .. params.strong .. "i", params.base .. params.strong .. params.final .. "sid"}
	
	process_stems(data, stems)
	
end
	
inflections["leib"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#leib|22u/leib]]"
	table.insert(data.categories, lang:getCanonicalName() .. " leib-type nominals")
	
	local params = get_params(args, 4, true)
	local pl_short_stem = params.base .. params.weak .. "u"
	
	if params.strong == params.weak or params.strong == params.weak .. params.weak then
		data.title = data.title .. ", length gradation"
	elseif params.strong == "tv" and params.weak == "dv" then -- only for the word "lõtv"
		data.title = data.title .. ", length gradation"
	elseif params.strong == "eg" and params.weak == "j" then
		data.title = data.title .. ", ''g-j'' gradation"
	elseif params.strong == "ed" and params.weak == "i" then
		data.title = data.title .. ", ''d-ø'' gradation"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. (params.weak == "" and "ø" or params.weak) .. "'' gradation"
	end

	if params.weak == "" and mw.ustring.match(params.base, "([aeiouõäöü])([aeiouõäöü])$") then
		pl_short_stem = nil
	else
		pl_short_stem = pl_short_stem
	end
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.strong}
	stems["sg"]           = {params.base .. params.weak .. params.final}
	stems["par_sg"]       = {params.base .. params.strong .. params.final}
	stems["ill_sg_short"] = {params.base .. params.strong .. params.final}
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "de"}
	stems["pl_short"]     = {pl_short_stem}
	stems["par_pl"]       = {params.base .. params.strong .. "u", params.base .. params.strong .. params.final .. "sid"}
	
	process_stems(data, stems)
	
end

inflections["puri"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#puri|24/puri]], length gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " puri-type nominals")
	
	local params = get_params(args, 3)
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.final_nom_sg}
	stems["sg"]           = {params.base .. params.final}
	stems["par_sg"]       = {params.base .. params.final}
	stems["ill_sg_short"] = {params.base .. params.final}
	stems["pl_long"]      = {params.base .. params.final .. "de"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.base .. params.final .. "sid"}
	
	process_stems(data, stems)
end

inflections["tühi"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#tühi|24e/tühi]]"
	table.insert(data.categories, lang:getCanonicalName() .. " tühi-type nominals")
	
	local params = get_params(args, 5, true)
	local weak_pl_stem = params.base .. params.weak .. params.final
	local strong_pl_stem = params.base .. params.strong .. params.final
	
	if mw.ustring.find(params.final, "a$") then 
		weak_pl_stem = mw.ustring.gsub(params.base .. params.weak .. params.final, "a$", "e")
		strong_pl_stem = mw.ustring.gsub(params.base .. params.strong .. params.final, "a$", "e")
	elseif mw.ustring.find(params.final, "u$") then 
		weak_pl_stem = mw.ustring.gsub(params.base .. params.weak .. params.final, "u$", "e")
		strong_pl_stem = mw.ustring.gsub(params.base .. params.strong .. params.final, "u$", "e")
	end
	
	if params.strong == "t" and params.weak == "" then
		data.title = data.title .. ", ''" .. (params.weak == "" and "ø" or params.weak) .. "-" .. params.strong .. "'' gradation"
	else
		data.title = data.title .. ", length gradation"
	end

	local stems = {}
	stems["nom_sg"]       = {params.base .. params.weak .. params.final_nom_sg}
	stems["sg"]           = {params.base .. params.weak .. params.final}
	stems["par_sg"]       = {params.base .. params.strong .. params.final}
	stems["ill_sg_short"] = {params.base .. params.strong .. params.final}
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "de"}
	stems["pl_short"]     = {weak_pl_stem}
	stems["par_pl"]       = {strong_pl_stem, params.base .. params.strong .. params.final .. "sid"}
	
	process_stems(data, stems)
end

inflections["oder"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#oder|24i/oder]]"
	table.insert(data.categories, lang:getCanonicalName() .. " oder-type nominals")
	
	local params = get_params(args, 5, true)
	local weak_pl_stem = params.base .. params.weak .. params.final
	local strong_pl_stem = params.base .. params.strong .. params.final

	if mw.ustring.find(params.final, "a$") then 
		weak_pl_stem = mw.ustring.gsub(params.base .. params.weak .. params.final, "a$", "i")
		strong_pl_stem = mw.ustring.gsub(params.base .. params.strong .. params.final, "a$", "i")
	elseif mw.ustring.find(params.final, "e$") then 
		weak_pl_stem = mw.ustring.gsub(params.base .. params.weak .. params.final, "e$", "i")
		strong_pl_stem = mw.ustring.gsub(params.base .. params.strong .. params.final, "e$", "i")
	end
	
	if params.strong == "t" and params.weak == "" then
		data.title = data.title .. ", ''" .. (params.weak == "" and "ø" or params.weak) .. "-" .. params.strong .. "'' gradation"
	else
		data.title = data.title .. ", length gradation"
	end

	local stems = {}
	stems["nom_sg"]       = {params.base .. params.weak .. params.final_nom_sg}
	stems["sg"]           = {params.base .. params.weak .. params.final}
	stems["par_sg"]       = {params.base .. params.strong .. params.final}
	stems["ill_sg_short"] = {params.base .. params.strong .. params.final}
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "de"}
	stems["pl_short"]     = {weak_pl_stem}
	stems["par_pl"]       = {strong_pl_stem, params.base .. params.strong .. params.final .. "sid"}
	
	process_stems(data, stems)
end

inflections["padi"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#padi|24u/padi]], length gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " padi-type nominals")
	
	local params = get_params(args, 5, true)
	local weak_pl_stem = mw.ustring.gsub(params.base .. params.weak .. params.final, "a$", "u")
	local strong_pl_stem = mw.ustring.gsub(params.base .. params.strong .. params.final, "a$", "u")
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. params.weak .. params.final_nom_sg}
	stems["sg"]           = {params.base .. params.weak .. params.final}
	stems["par_sg"]       = {params.base .. params.strong .. params.final}
	stems["ill_sg_short"] = {params.base .. params.strong .. params.final}
	stems["pl_long"]      = {params.base .. params.strong .. params.final .. "de"}
	stems["pl_short"]     = {weak_pl_stem}
	stems["par_pl"]       = {strong_pl_stem, params.base .. params.strong .. params.final .. "sid"}
	
	process_stems(data, stems)
end

inflections["õnnelik"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#õnnelik|25/õnnelik]], length gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " õnnelik-type nominals")
	
	local params = get_params(args, 1)
	
	local stems = {}
	stems["nom_sg"]       = {params.base .. "k"}
	stems["sg"]           = {params.base .. "ku"}
	stems["par_sg"]       = {params.base .. "kku"}
	stems["ill_sg_short"] = {params.base .. "kku"}
	stems["pl_long"]      = {params.base .. "ke", params.base .. "kkude"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.base .. "kke", params.base .. "kkusid"}
	
	process_stems(data, stems)
end

inflections["koi"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#koi|26/koi]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " koi-type nominals")
	
	local params = get_params(args, 1)
	local par_sg = args["par_sg"]; if par_sg == "" then par_sg = nil end  -- For nõu
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.base}
	stems["par_sg"]       = {par_sg or params.base .. "d"}
	stems["ill_sg_short"] = {}
	stems["pl_long"]      = {params.base .. "de"}
	stems["pl_short"]     = {}
	stems["par_pl"]       = {params.base .. "sid"}
	
	process_stems(data, stems)
end

inflections["idee"] = function(args, data)
	data.title = "ÕS type [[Appendix:Estonian nominal inflection#idee|26i/idee]], no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " idee-type nominals")
	
	local params = get_params(args, 1)
	local ill_sg2 = args["ill_sg2"]; if ill_sg2 == "" then ill_sg2 = nil end
	local shortened_stem, vowel = mw.ustring.match(params.base, "^(.-)([aeiouõäöü]?)$")
	
	if mw.ustring.find(params.base, "ea$") then 
		shortened_stem = mw.ustring.gsub(params.base, "ea$", "ä")
	end 
	
	local stems = {}
	stems["nom_sg"]       = {params.base}
	stems["sg"]           = {params.base}
	stems["par_sg"]       = {params.base .. "d"}
	stems["ill_sg_short"] = {}
	stems["pl_long"]      = {params.base .. "de"}
	stems["pl_short"]     = {shortened_stem .. "i"}
	stems["par_pl"]       = {shortened_stem .. "id", params.base .. "sid"}
	
	process_stems(data, stems)
	
	if ill_sg2 then
		table.insert(data.forms["ill_sg_long"], shortened_stem .. "h" .. vowel)
	end
end


-- Helper functions

local function combine(forms1, forms2)
	if forms1 and forms2 then
		local ret = mw.clone(forms1)
		
		for _, form in ipairs(forms2) do
			table.insert(ret, form)
		end
		
		return ret
	elseif forms1 then
		return mw.clone(forms1)
	elseif forms2 then
		return mw.clone(forms2)
	else
		return nil
	end
end

function postprocess(args, data)
	local n = args["n"]; if n == "" then n = nil end
	
	data.forms["ill_sg"] = combine(data.forms["ill_sg_short"], data.forms["ill_sg_long"])
	
	for _, case in ipairs({"ill", "ine", "ela", "all", "ade", "abl", "tra"}) do
		data.forms[case .. "_pl"] = combine(data.forms[case .. "_pl_long"], data.forms[case .. "_pl_short"])
	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
	if (lang:makeEntryName(data.forms[n == "pl" and "nom_pl" or "nom_sg"][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, "<br/>")
	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 = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="declension" style="color: rgb(0%,0%,30%); border: solid 1px rgb(80%,80%,100%); text-align:left;" cellspacing="1" cellpadding="2"
|-
! class="vsToggleElement" colspan="4" style="background:rgb(80%,80%,100%);" | Declension of {{{lemma}}}{{{info}}}
|- class="vsHide"
! style="min-width: 11em; background:rgb(80%,80%,100%);" colspan="2" |
! style="min-width: 10em; background:rgb(80%,80%,100%);" | singular
! style="min-width: 10em; background:rgb(80%,80%,100%);" | plural
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | nominative
| rowspan="2" | {{{nom_sg}}}
| rowspan="3" | {{{nom_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! rowspan="2" style="background:rgb(80%,80%,100%);" | accusative
! style="background:rgb(88%,88%,100%);" | nom.
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! style="background:rgb(88%,88%,100%);" | gen.
| rowspan="2" | {{{gen_sg}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | genitive
| {{{gen_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | partitive
| {{{par_sg}}}
| {{{par_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | illative
| {{{ill_sg}}}
| {{{ill_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | inessive
| {{{ine_sg}}}
| {{{ine_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | elative
| {{{ela_sg}}}
| {{{ela_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | allative
| {{{all_sg}}}
| {{{all_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | adessive
| {{{ade_sg}}}
| {{{ade_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | ablative
| {{{abl_sg}}}
| {{{abl_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | translative
| {{{tra_sg}}}
| {{{tra_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | terminative
| {{{ter_sg}}}
| {{{ter_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | essive
| {{{ess_sg}}}
| {{{ess_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | abessive
| {{{abe_sg}}}
| {{{abe_pl}}}
|- class="vsHide" style="background:rgb(95%,95%,100%)"
! colspan="2" style="background:rgb(80%,80%,100%);" | comitative
| {{{com_sg}}}
| {{{com_pl}}}
|}]=]
	return mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)
end

return export