Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:fi-jména

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

local export = {}

local lang = require("Modul:languages").getByCode("fi")

-- 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["nocheck"] then
		table.insert(data.categories, "fi-decl with nocheck")
	end
	
	if args["nosg"] then
		table.insert(data.categories, "fi-decl with nosg")
	end
	
	if args["nopl"] then
		table.insert(data.categories, "fi-decl with nopl")
	end
	
	if args["type"] then
		table.insert(data.categories, "fi-decl with type")
	end
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end

function get_params(args, num, invert_grades)
	local params = {}
	
	if num == 5 then
		params.base = args[1] or (mw.title.getCurrentTitle().nsText == "Šablona" and "{{{1}}}"); if not params.base or params.base == "" then error("Parameter 1 (base stem) may not be empty.") end
		params.strong = args[2] or (mw.title.getCurrentTitle().nsText == "Šablona" and "{{{2}}}"); if not params.strong then error("Parameter 2 (nominative grade) may not be omitted.") end
		params.weak = args[3] or (mw.title.getCurrentTitle().nsText == "Šablona" and "{{{3}}}"); if not params.weak then error("Parameter 3 (genitive grade) may not be omitted.") end
		params.final = args[4] or (mw.title.getCurrentTitle().nsText == "Šablona" and "{{{4}}}"); if not params.final or params.final == "" then error("Parameter 4 (final letter(s)) may not be empty.") end
		params.a = args[5] or (mw.title.getCurrentTitle().nsText == "Šablona" and "a"); if params.a ~= "a" and params.a ~= "ä" then error("Parameter 5 must be \"a\" or \"ä\".") end
	elseif num == 4 then
		params.base = args[1] or (mw.title.getCurrentTitle().nsText == "Šablona" and "{{{1}}}"); if not params.base or params.base == "" then error("Parameter 1 (base stem) may not be empty.") end
		params.strong = args[2] or (mw.title.getCurrentTitle().nsText == "Šablona" and "{{{2}}}"); if not params.strong then error("Parameter 2 (nominative grade) may not be omitted.") end
		params.weak = args[3] or (mw.title.getCurrentTitle().nsText == "Šablona" and "{{{3}}}"); if not params.weak then error("Parameter 3 (genitive grade) may not be omitted.") end
		params.a = args[4] or (mw.title.getCurrentTitle().nsText == "Šablona" and "a"); if params.a ~= "a" and params.a ~= "ä" then error("Parameter 4 must be \"a\" or \"ä\".") end
	elseif num == 2 then
		params.base = args[1] or (mw.title.getCurrentTitle().nsText == "Šablona" and "{{{1}}}"); if not params.base or params.base == "" then error("Parameter 1 (base stem) may not be empty.") end
		params.a = args[2] or (mw.title.getCurrentTitle().nsText == "Šablona" and "a"); if params.a ~= "a" and params.a ~= "ä" then error("Parameter 2 must be \"a\" or \"ä\".") end
	elseif num == 1 then
		params.base = args[1] or ""
	end
	
	-- Swap the grades
	if invert_grades then
		params.strong, params.weak = params.weak, params.strong
	end
	
	if params.a then
		params.o = params.a == "ä" and "ö" or "o"
		params.u = params.a == "ä" and "y" or "u"
	end
	
	return params	
end

local make_weak = require("Module:fi-utilities").make_weak

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

local stem_endings = {}

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

stem_endings["sg"] = {
	["ess_sg"] = "na",
}

stem_endings["sg_weak"] = {
	["gen_sg"] = "n",
	["ine_sg"] = "ssa",
	["ela_sg"] = "sta",
	["ade_sg"] = "lla",
	["abl_sg"] = "lta",
	["all_sg"] = "lleˣ",
	["tra_sg"] = "ksi",
	["ins_sg"] = "n",
	["abe_sg"] = "tta",
	["nom_pl"] = "t",
}

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

stem_endings["ill_sg"] = {
	["ill_sg"] = "Vn",
}

stem_endings["pl"] = {
	["ess_pl"] = "na",
	["com_pl"] = "ne",
}

stem_endings["pl_weak"] = {
	["ine_pl"] = "ssa",
	["ela_pl"] = "sta",
	["ade_pl"] = "lla",
	["abl_pl"] = "lta",
	["all_pl"] = "lleˣ",
	["tra_pl"] = "ksi",
	["ins_pl"] = "n",
	["abe_pl"] = "tta",
}

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

stem_endings["gen_pl"] = {
	["gen_pl"] = "en",
}

stem_endings["ill_pl"] = {
	["ill_pl"] = "Vn",
}


-- Make a copy of the endings, with front vowels
stem_endings = {["a"] = stem_endings, ["ä"] = mw.clone(stem_endings)}

for stem_key, endings in pairs(stem_endings["ä"]) do
	for key, ending in pairs(endings) do
		endings[key] = mw.ustring.gsub(endings[key], "([aou])", {["a"] = "ä", ["o"] = "ö", ["u"] = "y"})
	end
end

-- Create forms based on each stem, by adding endings to it
local function process_stems(data, stems, vh)
	-- Create any stems that were not given
	if not stems["nom_sg"] then
		stems["nom_sg"] = mw.clone(stems["sg"])
	end
	
	if not stems["sg_weak"] then
		stems["sg_weak"] = mw.clone(stems["sg"])
	end
	
	if not stems["par_sg"] then
		stems["par_sg"] = mw.clone(stems["sg"])
	end
	
	if not stems["ill_sg"] then
		stems["ill_sg"] = {}
		
		for _, stem in ipairs(stems["sg"]) do
			-- If the stem ends in a long vowel or diphthong, then add -h
			if mw.ustring.find(stem, "([aeiouyäö])%1$") or mw.ustring.find(stem, "[aeiouyäö][iyü]$") then
				table.insert(stems["ill_sg"], stem .. "h")
			else
				table.insert(stems["ill_sg"], stem)
			end
		end
	end
	
	if not stems["pl_weak"] then
		stems["pl_weak"] = mw.clone(stems["pl"])
	end
	
	if not stems["par_pl"] then
		stems["par_pl"] = {}
		
		for _, stem in ipairs(stems["pl"]) do
			-- If the plural stem ends in a vowel + i, then replace the i with j
			if mw.ustring.find(stem, "[aeiouyäö]i$") then
				table.insert(stems["par_pl"], (mw.ustring.gsub(stem, "i$", "j")))
			else
				table.insert(stems["par_pl"], stem)
			end
		end
	end
	
	if not stems["gen_pl"] then
		stems["gen_pl"] = {}
		
		for _, stem in ipairs(stems["par_pl"]) do
			-- If the partitive plural stem ends in -it, then replace the t with d or tt
			if mw.ustring.find(stem, "it$") then
				table.insert(stems["gen_pl"], (mw.ustring.gsub(stem, "t$", "d")))
				table.insert(stems["gen_pl"], stem .. "t")
			else
				table.insert(stems["gen_pl"], stem)
			end
		end
	end
	
	if not stems["ill_pl"] then
		stems["ill_pl"] = {}
		
		for _, stem in ipairs(stems["pl"]) do
			-- If the stem ends in a long vowel or diphthong, then add -h
			if mw.ustring.find(stem, "([aeiouyäö])%1$") or mw.ustring.find(stem, "[aeiouyäö][iyü]$") then
				table.insert(stems["ill_pl"], stem .. "h")
			else
				table.insert(stems["ill_pl"], stem)
			end
		end
	end
	
	-- 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[vh][stem_key]) do
				if not data.forms[form_key] then
					data.forms[form_key] = {}
				end
				
				-- "V" is a copy of the last vowel in the stem
				if mw.ustring.find(ending, "V") then
					local vowel = mw.ustring.match(stem, "([aeiouyäö])[^aeiouyäö]*$")
					ending = mw.ustring.gsub(ending, "V", vowel or "?")
				end
				
				table.insert(data.forms[form_key], stem .. ending)
			end
		end
	end
end


inflections["valo"] = function(args, data)
	data.title = "Kotus typ 1/valo"
	table.insert(data.categories, "Finská jména typu valo")
	
	local params = get_params(args, 5)
	
	make_weak(params.base, params.strong, params.final, params.weak)
	
	if params.strong == params.weak then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local wk_sg = params.weak
	local wk_pl = params.weak
	
	if mw.ustring.sub(params.base, -1) == params.final then
		if wk_sg == "" and (mw.ustring.find(params.base, "[aeiouyäö][iuy]$") or mw.ustring.find(params.base, "[iuy][eoö]$")) then
			wk_sg = "'"
		end
		
		if wk_pl == "" then
			wk_pl = "'"
		end
	end
	
	local stems = {}
	stems["sg"]      = {params.base .. params.strong .. params.final}
	stems["sg_weak"] = {params.base .. wk_sg .. params.final}
	stems["pl"]      = {params.base .. params.strong .. params.final .. "i"}
	stems["pl_weak"] = {params.base .. wk_pl .. params.final .. "i"}
	
	process_stems(data, stems, params.a)
end

inflections["palvelu"] = function(args, data)
	data.title = "Kotus typ 2, vzor palvelu, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru palvelu")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["sg"]      = {params.base}
	stems["pl"]      = {params.base .. "i"}
	stems["par_pl"]  = {params.base .. "j", params.base .. "it"}
	
	process_stems(data, stems, params.a)
end

inflections["valtio"] = function(args, data)
	data.title = "Kotus typ 3, vzor valtio, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru valtio")
	
	local params = get_params(args, 2)
	local final = mw.ustring.sub(params.base, -1)
	
	local stems = {}
	stems["sg"]      = {params.base}
	stems["par_sg"]  = {params.base .. "t"}
	stems["pl"]      = {params.base .. "i"}
	stems["par_pl"]  = {params.base .. "it"}
	
	process_stems(data, stems, params.a)
end

inflections["laatikko"] = function(args, data)
	data.title = "Kotus typ 4, vzor laatikko"
	table.insert(data.categories, "Finská slova vzoru laatikko")
	
	local params = get_params(args, 5, false, "kk", "k", "o")
	
	make_weak(params.base, params.strong, params.final, params.weak)
	
	if params.strong == params.weak then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local stems = {}
	stems["sg"]      = {params.base .. params.strong .. params.final}
	stems["sg_weak"] = {params.base .. params.weak .. params.final}
	stems["pl"]      = {params.base .. params.strong .. params.final .. "i"}
	stems["pl_weak"] = {params.base .. params.weak .. params.final .. "i"}
	stems["par_pl"]  = {params.base .. params.strong .. params.final .. "j", params.base .. params.weak .. params.final .. "it"}
	stems["ill_pl"]  = {params.base .. params.strong .. params.final .. "ih", params.base .. params.weak .. params.final .. "ih"}
	
	process_stems(data, stems, params.a)
end

inflections["risti"] = function(args, data)
	data.title = "Kotus typ 5, vzor risti"
	table.insert(data.categories, "Finská slova vzoru risti")
	
	local params = get_params(args, 4)
	local i = args["i"]; if i == "0" then i = "" else i = "i" end
	
	make_weak(params.base, params.strong, "i", params.weak)
	
	if params.strong == params.weak then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. params.strong .. i}
	stems["sg"]      = {params.base .. params.strong .. "i"}
	stems["sg_weak"] = {params.base .. params.weak .. "i"}
	stems["pl"]      = {params.base .. params.strong .. "ei"}
	stems["pl_weak"] = {params.base .. params.weak .. "ei"}
	stems["gen_pl"]  = {params.base .. params.strong .. "i"}
	
	process_stems(data, stems, params.a)
end

inflections["paperi"] = function(args, data)
	data.title = "Kotus typ 6, vzor paperi, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru paperi")
	
	local params = get_params(args, 2)
	local i = args["i"]; if i == "0" then i = "" else i = "i" end
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. i}
	stems["sg"]      = {params.base .. "i"}
	stems["pl"]      = {params.base .. "ei"}
	stems["par_pl"]  = {params.base .. "eit", params.base .. "ej"}
	stems["gen_pl"]  = {params.base .. "i", params.base .. "eid", params.base .. "eitt"}
	
	process_stems(data, stems, params.a)
end

inflections["ovi"] = function(args, data)
	data.title = "Kotus typ 7, vzor ovi"
	table.insert(data.categories, "Finská slova vzoru ovi")
	
	local params = get_params(args, 4)
	local nom_sg = args["nom_sg"]; if nom_sg == "" then nom_sg = nil end
	
	make_weak(params.base, params.strong, "e", params.weak)
	
	if params.strong == params.weak then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local stems = {}
	stems["nom_sg"]  = {nom_sg or params.base .. params.strong .. "i"}
	stems["sg"]      = {params.base .. params.strong .. "e"}
	stems["sg_weak"] = {params.base .. params.weak .. "e"}
	stems["pl"]      = {params.base .. params.strong .. "i"}
	stems["pl_weak"] = {params.base .. params.weak .. "i"}
	
	process_stems(data, stems, params.a)
end

inflections["nalle"] = function(args, data)
	data.title = "Kotus typ 8, vzor nalle"
	table.insert(data.categories, "Finská slova vzoru nalle")
	
	local params = get_params(args, 4)
	
	make_weak(params.base, params.strong, "e", params.weak)
	
	if params.strong == params.weak then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local stems = {}
	stems["sg"]      = {params.base .. params.strong .. "e"}
	stems["sg_weak"] = {params.base .. params.weak .. "e"}
	stems["pl"]      = {params.base .. params.strong .. "ei"}
	stems["pl_weak"] = {params.base .. params.weak .. "ei"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. params.strong .. "ein"}
end

inflections["kala"] = function(args, data)
	data.title = "Kotus typ 9, vzor kala"
	table.insert(data.categories, "Finská slova vzoru kala")
	
	local params = get_params(args, 4)
	
	make_weak(params.base, params.strong, params.a, params.weak)
	
	if params.strong == params.weak then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local wk_sg = params.weak
	
	if wk_sg == "" and mw.ustring.sub(params.base, -2) == params.a .. params.a then
		wk_sg = "'"
	end
	
	local stems = {}
	stems["sg"]      = {params.base .. params.strong .. params.a}
	stems["sg_weak"] = {params.base .. wk_sg .. params.a}
	stems["pl"]      = {params.base .. params.strong .. params.o .. "i"}
	stems["pl_weak"] = {params.base .. params.weak .. params.o .. "i"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. params.strong .. params.a .. "in"}
end

inflections["koira"] = function(args, data)
	data.title = "Kotus typ 10, vzor koira"
	table.insert(data.categories, "Finská slova vzoru koira")
	
	local params = get_params(args, 4)
	
	make_weak(params.base, params.strong, params.a, params.weak)
	
	if params.strong == params.weak then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local wk_sg = params.weak
	local wk_pl = params.weak
	
	if wk_sg == "" and mw.ustring.sub(params.base, -2) == params.a .. params.a then
		wk_sg = "'"
	end
	
	if wk_pl == "" and mw.ustring.sub(params.base, -1) == "i" then
		wk_pl = "'"
	end
	
	local stems = {}
	stems["sg"]      = {params.base .. params.strong .. params.a}
	stems["sg_weak"] = {params.base .. wk_sg .. params.a}
	stems["pl"]      = {params.base .. params.strong .. "i"}
	stems["pl_weak"] = {params.base .. wk_pl .. "i"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. params.strong .. params.a .. "in"}
end

inflections["omena"] = function(args, data)
	data.title = "Kotus typ 11, vzor omena, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru omena")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["sg"]      = {params.base .. params.a}
	stems["pl"]      = {params.base .. params.o .. "i", params.base .. "i"}
	stems["par_pl"]  = {params.base .. "i", params.base .. params.o .. "it"}
	stems["ill_pl"]  = {params.base .. "i", params.base .. params.o .. "ih"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. params.o .. "jen", params.base .. params.a .. "in"}
	data.forms["par_pl"].rare = {params.base .. params.o .. "j" .. params.a}
end

inflections["kulkija"] = function(args, data)
	data.title = "Kotus typ 12, vzor kulkija, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru kulkija")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["sg"]      = {params.base .. params.a}
	stems["pl"]      = {params.base .. params.o .. "i"}
	stems["par_pl"]  = {params.base .. params.o .. "it"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. params.a .. "in"}
end

inflections["katiska"] = function(args, data)
	data.title = "Kotus typ 13, vzor katiska, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru katiska")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["sg"]      = {params.base .. params.a}
	stems["pl"]      = {params.base .. params.o .. "i"}
	stems["par_pl"]  = {params.base .. params.o .. "it", params.base .. params.o .. "j"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. params.a .. "in"}
end

inflections["solakka"] = function(args, data)
	data.title = "Kotus typ 14, vzor solakka"
	table.insert(data.categories, "Finská slova vzoru solakka")
	
	local params = get_params(args, 4)
	
	make_weak(params.base, params.strong, params.a, params.weak)
	
	if params.strong == params.weak then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local stems = {}
	stems["sg"]      = {params.base .. params.strong .. params.a}
	stems["sg_weak"] = {params.base .. params.weak .. params.a}
	stems["pl"]      = {params.base .. params.strong .. params.o .. "i"}
	stems["pl_weak"] = {params.base .. params.weak .. params.o .. "i"}
	stems["par_pl"]  = {params.base .. params.weak .. params.o .. "it", params.base .. params.strong .. params.o .. "j"}
	stems["ill_pl"]  = {params.base .. params.strong .. params.o .. "ih", params.base .. params.weak .. params.o .. "ih"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. params.strong .. params.a .. "in"}
end

inflections["korkea"] = function(args, data)
	data.title = "Kotus typ 15, vzor korkea, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru korkea")
	
	local params = get_params(args, 2)
	local final = mw.ustring.sub(params.base, -1)
	
	local stems = {}
	stems["sg"]      = {params.base .. params.a}
	stems["par_sg"]  = {params.base .. params.a, params.base .. params.a .. "t"}
	stems["pl"]      = {params.base .. "i"}
	stems["par_pl"]  = {params.base .. "it"}
	stems["ill_pl"]  = {params.base .. "isi", params.base .. "ih"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. params.a .. "in"}
end

inflections["vanhempi"] = function(args, data)
	data.title = "Kotus typ 16, vzor vanhempi, ''mp-mm'' stupňování"
	table.insert(data.categories, "Finská slova vzoru vanhempi")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "mpi"}
	stems["sg"]      = {params.base .. "mp" .. params.a}
	stems["sg_weak"] = {params.base .. "mm" .. params.a}
	stems["pl"]      = {params.base .. "mpi"}
	stems["pl_weak"] = {params.base .. "mmi"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. "mp" .. params.a .. "in"}
end

inflections["vapaa"] = function(args, data)
	data.title = "Kotus typ 17, vzor vapaa, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru vapaa")
	
	local params = get_params(args, 2)
	local final = mw.ustring.sub(params.base, -1)
	
	local stems = {}
	stems["sg"]      = {params.base .. final}
	stems["par_sg"]  = {params.base .. final .. "t"}
	stems["ill_sg"]  = {params.base .. final .. "se"}
	stems["pl"]      = {params.base .. "i"}
	stems["par_pl"]  = {params.base .. "it"}
	stems["ill_pl"]  = {params.base .. "isi"}
	
	process_stems(data, stems, params.a)
	
	data.forms["ill_pl"].rare = {params.base .. "ihin"}
end

inflections["maa"] = function(args, data)
	data.title = "Kotus typ 18, vzor maa, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru maa")
	
	local params = get_params(args, 2)
	local nom_sg = args["nom_sg"]; if nom_sg == "" then nom_sg = nil end
	
	local pl_stem = mw.ustring.sub(params.base, 1, -2)
	
	local stems = {}
	stems["nom_sg"]  = {nom_sg or params.base}
	stems["sg"]      = {params.base}
	stems["par_sg"]  = {params.base .. "t"}
	stems["pl"]      = {pl_stem .. "i"}
	stems["par_pl"]  = {pl_stem .. "it"}
	
	process_stems(data, stems, params.a)
end

inflections["suo"] = function(args, data)
	data.title = "Kotus typ 19, vzor suo, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru suo")
	
	local params = get_params(args, 2)
	local final = mw.ustring.sub(params.base, -1)
	local plural = mw.ustring.sub(params.base, 1, -3) .. final
	
	local stems = {}
	stems["sg"]      = {params.base}
	stems["par_sg"]  = {params.base .. "t"}
	stems["ill_sg"]  = {params.base .. "h"}
	stems["pl"]      = {plural .. "i"}
	stems["par_pl"]  = {plural .. "it"}
	
	process_stems(data, stems, params.a)
end

inflections["filee"] = function(args, data)
	data.title = "Kotus typ 20, vzor filee, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru filee")
	
	local params = get_params(args, 2)
	local pl_stem = mw.ustring.sub(params.base, 1, -2)
	
	local stems = {}
	stems["sg"]      = {params.base}
	stems["par_sg"]  = {params.base .. "t"}
	stems["ill_sg"]  = {params.base .. "h", params.base .. "se"}
	stems["pl"]      = {pl_stem .. "i"}
	stems["par_pl"]  = {pl_stem .. "it"}
	stems["ill_pl"]  = {pl_stem .. "ih", pl_stem .. "isi"}
	
	process_stems(data, stems, params.a)
end

inflections["rosé"] = function(args, data)
	data.title = "Kotus typ 21, vzor rosé, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru rosé")
	
	local params = get_params(args, 2)
	local ill_sg_vowel = args["ill_sg_vowel"]; if ill_sg_vowel == "" then error("Parameter \"ill_sg_vowel=\" cannot be empty.") end
	local ill_sg_vowel2 = args["ill_sg_vowel2"]; if ill_sg_vowel2 == "" then error("Parameter \"ill_sg_vowel2=\" cannot be empty.") end
	
	local stems = {}
	stems["sg"]      = {params.base}
	stems["par_sg"]  = {params.base .. "t"}
	stems["ill_sg"]  = {params.base .. "h"}
	stems["pl"]      = {params.base .. "i"}
	stems["par_pl"]  = {params.base .. "it"}
	stems["ill_pl"]  = {params.base .. "ih"}
	
	process_stems(data, stems, params.a)
	
	if ill_sg_vowel then
		data.forms["ill_sg"] = {params.base .. "h" .. ill_sg_vowel .. "n"}
	end
	
	if ill_sg_vowel2 then
		table.insert(data.forms["ill_sg"], params.base .. "h" .. ill_sg_vowel2 .. "n")
	end
end

inflections["parfait"] = function(args, data)
	data.title = "Kotus typ 22, vzor parfait, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru parfait")
	
	local params = get_params(args, 2)
	local ill_sg_vowel = args["ill_sg_vowel"] or (mw.title.getCurrentTitle().nsText == "Šablona" and "e"); if not ill_sg_vowel or ill_sg_vowel == "" then error("Parameter \"ill_sg_vowel=\" is missing.") end
	local ill_sg_vowel2 = args["ill_sg_vowel2"]; if ill_sg_vowel2 == "" then error("Parameter \"ill_sg_vowel2=\" cannot be empty.") end
	
	local stems = {}
	stems["nom_sg"]  = {params.base}
	stems["sg"]      = {params.base .. "'"}
	stems["par_sg"]  = {params.base .. "'t"}
	stems["pl"]      = {params.base .. "'i"}
	stems["par_pl"]  = {params.base .. "'it"}
	stems["ill_pl"]  = {params.base .. "'ih"}
	
	process_stems(data, stems, params.a)
	
	data.forms["ill_sg"] = {params.base .. "'h" .. ill_sg_vowel .. "n"}
	
	if ill_sg_vowel2 then
		table.insert(data.forms["ill_sg"], params.base .. "h" .. ill_sg_vowel2 .. "n")
	end
end

inflections["tiili"] = function(args, data)
	data.title = "Kotus typ 23, vzor tiili, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru tiili")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "i"}
	stems["sg"]      = {params.base .. "e"}
	stems["par_sg"]  = {params.base .. "t"}
	stems["pl"]      = {params.base .. "i"}
	
	process_stems(data, stems, params.a)
end

inflections["uni"] = function(args, data)
	data.title = "Kotus typ 24, vzor uni, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru uni")
	
	local params = get_params(args, 2)
	local par_sg_a = args["par_sg_a"]; if par_sg_a and par_sg_a ~= "a" and par_sg_a ~= "ä" then error("Parameter \"par_sg_a=\" must be \"a\" or \"ä\".") end
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "i"}
	stems["sg"]      = {params.base .. "e"}
	stems["par_sg"]  = {params.base .. "t"}
	stems["pl"]      = {params.base .. "i"}
	stems["gen_pl"]  = {params.base .. "i", params.base .. "t"}
	
	process_stems(data, stems, params.a)
	
	if par_sg_a then
		data.forms["par_sg"] = {}
		
		for _, stem in ipairs(stems["par_sg"]) do
			table.insert(data.forms["par_sg"], stem .. par_sg_a)
		end
	end
end

inflections["toimi"] = function(args, data)
	data.title = "Kotus typ 25, vzor toimi, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru toimi")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "mi"}
	stems["sg"]      = {params.base .. "me"}
	stems["par_sg"]  = {params.base .. "nt", params.base .. "me"}
	stems["pl"]      = {params.base .. "mi"}
	stems["gen_pl"]  = {params.base .. "mi", params.base .. "nt"}
	
	process_stems(data, stems, params.a)
end

inflections["pieni"] = function(args, data)
	data.title = "Kotus typ 26, vzor pieni, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru pieni")
	
	local params = get_params(args, 2)
	local par_sg_a = args["par_sg_a"]; if par_sg_a and par_sg_a ~= "a" and par_sg_a ~= "ä" then error("Parameter \"par_sg_a=\" must be \"a\" or \"ä\".") end
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "i"}
	stems["sg"]      = {params.base .. "e"}
	stems["par_sg"]  = {params.base .. "t"}
	stems["pl"]      = {params.base .. "i"}
	stems["gen_pl"]  = {params.base .. "t", params.base .. "i"}
	
	process_stems(data, stems, params.a)
	
	if par_sg_a then
		data.forms["par_sg"] = {}
		
		for _, stem in ipairs(stems["par_sg"]) do
			table.insert(data.forms["par_sg"], stem .. par_sg_a)
		end
	end
end

inflections["käsi"] = function(args, data)
	data.title = "Kotus typ 27, vzor käsi, ''t-d'' stupňování"
	table.insert(data.categories, "Finská slova vzoru käsi")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "si"}
	stems["sg"]      = {params.base .. "te"}
	stems["sg_weak"] = {params.base .. "de"}
	stems["par_sg"]  = {params.base .. "tt"}
	stems["pl"]      = {params.base .. "si"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. "tten"}
end

inflections["kynsi"] = function(args, data)
	data.title = "Kotus typ 28, vzor kynsi"
	table.insert(data.categories, "Finská slova vzoru kynsi")
	
	local params = get_params(args, 2, false, "n")
	local cons = mw.ustring.match(params.base, "([lnr]?)$")
	
	if mw.title.getCurrentTitle().nsText ~= "Šablona" and cons == "" then
		error("Stem must end in \"l\", \"n\" or \"r\".")
	end
	
	data.title = data.title .. ", ''" .. cons .. "t-" .. cons .. cons .. "'' stupňování"
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "si"}
	stems["sg"]      = {params.base .. "te"}
	stems["sg_weak"] = {params.base .. cons .. "e"}
	stems["par_sg"]  = {params.base .. "tt"}
	stems["pl"]      = {params.base .. "si"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. "tten"}
end

inflections["lapsi"] = function(args, data)
	data.title = "Kotus typ 29, vzor lapsi, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru lapsi")
	
	local params = get_params(args, 2, false, "p")
	local syncopated_stem, cons = mw.ustring.match(params.base, "^(.-)([kp]?)$")
	
	if mw.title.getCurrentTitle().nsText ~= "Šablona" and cons == "" then
		error("Kmen musí končit na \"k\" nebo \"p\".")
	end
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "si"}
	stems["sg"]      = {params.base .. "se"}
	stems["par_sg"]  = {syncopated_stem .. "st"}
	stems["pl"]      = {params.base .. "si"}
	stems["gen_pl"]  = {params.base .. "si", syncopated_stem .. "st"}
	
	process_stems(data, stems, params.a)
end

inflections["veitsi"] = function(args, data)
	data.title = "Kotus typ 30, vzor veitsi, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru veitsi")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "tsi"}
	stems["sg"]      = {params.base .. "tse"}
	stems["par_sg"]  = {params.base .. "st"}
	stems["pl"]      = {params.base .. "tsi"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. "sten"}
end

inflections["kaksi"] = function(args, data)
	data.title = "Kotus typ 31, vzor kaksi, stupňování ''t-d''"
	table.insert(data.categories, "Finská slova vzoru kaksi")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "ksi"}
	stems["sg"]      = {params.base .. "hte"}
	stems["sg_weak"] = {params.base .. "hde"}
	stems["par_sg"]  = {params.base .. "ht"}
	stems["pl"]      = {params.base .. "ksi"}
	
	process_stems(data, stems, params.a)
end

inflections["sisar"] = function(args, data)
	data.title = "Kotus typ 32, vzor sisar"
	table.insert(data.categories, "Finská slova vzoru sisar")
	
	local params = get_params(args, 5, true)
	local nom_sg = args["nom_sg"]; if nom_sg == "" then nom_sg = nil end
	
	make_weak(params.base, params.strong, params.final, params.weak)
	
	if params.strong == params.weak then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local stems = {}
	stems["nom_sg"]  = {nom_sg or params.base .. params.weak .. params.final}
	stems["sg"]      = {params.base .. params.strong .. params.final .. "e"}
	stems["par_sg"]  = {params.base .. params.weak .. params.final .. "t"}
	stems["pl"]      = {params.base .. params.strong .. params.final .. "i"}
	stems["gen_pl"]  = {params.base .. params.strong .. params.final .. "i", params.base .. params.weak .. params.final .. "t"}
	
	process_stems(data, stems, params.a)
end

inflections["kytkin"] = function(args, data)
	data.title = "Kotus typ 33, vzor kytkin"
	table.insert(data.categories, "Finská slova vzoru kytkin")
	
	local params = get_params(args, 5, true)
	
	make_weak(params.base, params.strong, params.final, params.weak)
	
	if params.weak == params.strong then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. params.weak .. params.final .. "n"}
	stems["sg"]      = {params.base .. params.strong .. params.final .. "me"}
	stems["par_sg"]  = {params.base .. params.weak .. params.final .. "nt"}
	stems["pl"]      = {params.base .. params.strong .. params.final .. "mi"}
	stems["gen_pl"]  = {params.base .. params.strong .. params.final .. "mi", params.base .. params.weak .. params.final .. "nt"}
	
	process_stems(data, stems, params.a)
end

inflections["onneton"] = function(args, data)
	data.title = "Kotus typ 34, vzor onneton, ''tt-t'' stupňování"
	table.insert(data.categories, "Finská slova vzoru onneton")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "t" .. params.o .. "n"}
	stems["sg"]      = {params.base .. "tt" .. params.o .. "m" .. params.a}
	stems["par_sg"]  = {params.base .. "t" .. params.o .. "nt"}
	stems["pl"]      = {params.base .. "tt" .. params.o .. "mi"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. "t" .. params.o .. "nten"}
end

inflections["lämmin"] = function(args, data)
	data.title = "Kotus typ 35, vzor lämmin, ''mp-mm'' stupňování"
	table.insert(data.categories, "Finská slova vzoru lämmin")
	
	local params = get_params(args, 1)
	params.base = params.base .. "lä"
	params.a = "ä"
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "mmin"}
	stems["sg"]      = {params.base .. "mpim" .. params.a}
	stems["par_sg"]  = {params.base .. "mmint"}
	stems["pl"]      = {params.base .. "mpimi"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. "mpim" .. params.a .. "in"}
end

inflections["sisin"] = function(args, data)
	data.title = "Kotus typ 36, vzor sisin, ''mp-mm'' stupňování"
	table.insert(data.categories, "Finská slova vzoru sisin")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "in"}
	stems["sg"]      = {params.base .. "imp" .. params.a}
	stems["sg_weak"] = {params.base .. "imm" .. params.a}
	stems["par_sg"]  = {params.base .. "int"}
	stems["pl"]      = {params.base .. "impi"}
	stems["pl_weak"] = {params.base .. "immi"}
	stems["gen_pl"]  = {params.base .. "impi", params.base .. "int"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. "imp" .. params.a .. "in"}
end

inflections["vasen"] = function(args, data)
	data.title = "Kotus typ 37, vzor vasen, ''mp-mm'' stupňování"
	table.insert(data.categories, "Finská slova vzoru vasen")
	
	local params = get_params(args, 1)
	params.base = params.base .. "vase"
	params.a = "a"
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "n"}
	stems["sg"]      = {params.base .. "mp" .. params.a}
	stems["sg_weak"] = {params.base .. "mm" .. params.a}
	stems["par_sg"]  = {params.base .. "nt", params.base .. "mp" .. params.a}
	stems["pl"]      = {params.base .. "mpi"}
	stems["pl_weak"] = {params.base .. "mmi"}
	stems["gen_pl"]  = {params.base .. "mpi", params.base .. "nt"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. "mp" .. params.a .. "in"}
end

inflections["nainen"] = function(args, data)
	data.title = "Kotus typ 38, vzor nainen, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru nainen")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "nen"}
	stems["sg"]      = {params.base .. "se"}
	stems["par_sg"]  = {params.base .. "st"}
	stems["pl"]      = {params.base .. "si"}
	stems["gen_pl"]  = {params.base .. "st", params.base .. "si"}
	
	process_stems(data, stems, params.a)
end

inflections["vastaus"] = function(args, data)
	data.title = "Kotus typ 39, vzor vastaus, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru vastaus")
	
	local params = get_params(args, 2)
	local nom_sg = args["nom_sg"]; if nom_sg == "" then nom_sg = nil end
	
	local stems = {}
	stems["nom_sg"]  = {nom_sg or params.base .. "s"}
	stems["sg"]      = {params.base .. "kse"}
	stems["par_sg"]  = {params.base .. "st"}
	stems["pl"]      = {params.base .. "ksi"}
	stems["gen_pl"]  = {params.base .. "st", params.base .. "ksi"}
	
	process_stems(data, stems, params.a)
end

inflections["kalleus"] = function(args, data)
	data.title = "Kotus typ 40, vzor kalleus, ''t-d'' stupňování"
	table.insert(data.categories, "Finská slova vzoru kalleus")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "s"}
	stems["sg"]      = {params.base .. "te"}
	stems["sg_weak"] = {params.base .. "de"}
	stems["par_sg"]  = {params.base .. "tt"}
	stems["pl"]      = {params.base .. "ksi"}
	
	process_stems(data, stems, params.a)
end

inflections["vieras"] = function(args, data)
	data.title = "Kotus typ 41, vzor vieras"
	table.insert(data.categories, "Finská slova vzoru vieras")
	
	local params = get_params(args, 5, true)
	
	make_weak(params.base, params.strong, params.final, params.weak)
	
	if params.weak == params.strong then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. params.weak .. params.final .. "s"}
	stems["sg"]      = {params.base .. params.strong .. params.final .. params.final}
	stems["par_sg"]  = {params.base .. params.weak .. params.final .. "st"}
	stems["ill_sg"]  = {params.base .. params.strong .. params.final .. params.final .. "se"}
	stems["pl"]      = {params.base .. params.strong .. params.final .. "i"}
	stems["par_pl"]  = {params.base .. params.strong .. params.final .. "it"}
	stems["ill_pl"]  = {params.base .. params.strong .. params.final .. "isi"}
	
	process_stems(data, stems, params.a)
	
	data.forms["ill_pl"].rare = {params.base .. params.strong .. params.final .. "ihin"}
end

inflections["mies"] = function(args, data)
	data.title = "Kotus typ 42, vzor mies, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru mies")
	
	local params = get_params(args, 1)
	params.base = params.base .. "mie"
	params.a = "ä"
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "s"}
	stems["sg"]      = {params.base .. "he"}
	stems["par_sg"]  = {params.base .. "st"}
	stems["pl"]      = {params.base .. "hi"}
	stems["gen_pl"]  = {params.base .. "st", params.base .. "hi"}
	
	process_stems(data, stems, params.a)
end

inflections["ohut"] = function(args, data)
	data.title = "Kotus typ 43, vzor ohut"
	table.insert(data.categories, "Finská slova vzoru ohut")
	
	local params = get_params(args, 5, true)
	
	make_weak(params.base, params.strong, params.final, params.weak)
	
	if params.weak == params.strong then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. params.weak .. params.final .. "t"}
	stems["sg"]      = {params.base .. params.strong .. params.final .. "e"}
	stems["par_sg"]  = {params.base .. params.weak .. params.final .. "tt"}
	stems["pl"]      = {params.base .. params.strong .. params.final .. "i"}
	stems["par_pl"]  = {params.base .. params.strong .. params.final .. "it"}
	stems["ill_pl"]  = {params.base .. params.strong .. params.final .. "isi", params.base .. params.strong .. params.final .. "ih"}
	
	process_stems(data, stems, params.a)
end

inflections["kevät"] = function(args, data)
	data.title = "Kotus typ 44, vzor kevät, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru kevät")
	
	local params = get_params(args, 2)
	local vowel = mw.ustring.sub(params.base, -1)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "t"}
	stems["sg"]      = {params.base .. vowel}
	stems["par_sg"]  = {params.base .. "tt"}
	stems["ill_sg"]  = {params.base .. vowel .. "se"}
	stems["pl"]      = {params.base .. "i"}
	stems["par_pl"]  = {params.base .. "it"}
	stems["ill_pl"]  = {params.base .. "isi"}
	
	process_stems(data, stems, params.a)
	
	data.forms["ill_pl"].rare = {params.base .. "ihin"}
end

inflections["kahdeksas"] = function(args, data)
	data.title = "Kotus typ 45, vzor kahdeksas, ''nt-nn'' stupňování"
	table.insert(data.categories, "Finská slova vzoru kahdeksas")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "s"}
	stems["sg"]      = {params.base .. "nte"}
	stems["sg_weak"] = {params.base .. "nne"}
	stems["par_sg"]  = {params.base .. "tt"}
	stems["pl"]      = {params.base .. "nsi"}
	
	process_stems(data, stems, params.a)
end

inflections["tuhat"] = function(args, data)
	data.title = "Kotus typ 46, vzor tuhat, ''nt-nn'' stupňování"
	table.insert(data.categories, "Finská slova vzoru tuhat")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. "t"}
	stems["sg"]      = {params.base .. "nte"}
	stems["sg_weak"] = {params.base .. "nne"}
	stems["par_sg"]  = {params.base .. "tt"}
	stems["pl"]      = {params.base .. "nsi"}
	
	process_stems(data, stems, params.a)
	
	data.forms["gen_pl"].rare = {params.base .. "nten"}
end

inflections["kuollut"] = function(args, data)
	data.title = "Kotus typ 47, vzor kuollut, bez stupňování"
	table.insert(data.categories, "Finská slova vzoru kuollut")
	
	local params = get_params(args, 2)
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. params.u .. "t"}
	stems["sg"]      = {params.base .. "ee"}
	stems["par_sg"]  = {params.base .. params.u .. "tt"}
	stems["ill_sg"]  = {params.base .. "eese"}
	stems["pl"]      = {params.base .. "ei"}
	stems["par_pl"]  = {params.base .. "eit"}
	stems["ill_pl"]  = {params.base .. "eisi", params.base .. "eih"}
	
	process_stems(data, stems, params.a)
end

inflections["hame"] = function(args, data)
	data.title = "Kotus typ 48, vzor hame"
	table.insert(data.categories, "Finská slova vzoru hame")
	
	local params = get_params(args, 4, true)
	
	make_weak(params.base, params.strong, "e", params.weak)
	
	if params.weak == params.strong then
		data.title = data.title .. ", bez stupňování"
	else
		data.title = data.title .. ", ''" .. params.strong .. "-" .. params.weak .. "'' stupňování"
	end
	
	local stems = {}
	stems["nom_sg"]  = {params.base .. params.weak .. "eˣ"}
	stems["sg"]      = {params.base .. params.strong .. "ee"}
	stems["par_sg"]  = {params.base .. params.weak .. "ett"}
	stems["ill_sg"]  = {params.base .. params.strong .. "eese"}
	stems["pl"]      = {params.base .. params.strong .. "ei"}
	stems["par_pl"]  = {params.base .. params.strong .. "eit"}
	stems["ill_pl"]  = {params.base .. params.strong .. "eisi", params.base .. params.strong .. "eih"}
	
	process_stems(data, stems, params.a)
end


-- Helper functions

function postprocess(args, data)
	local pos = args["pos"]; if not pos or pos == "" then pos = "noun" end
	local nosg = args["nosg"]; if nosg == "" then nosg = nil end
	local nopl = args["nopl"]; if nopl == "" then nopl = nil end
	local n = args["n"]; if n == "" then n = nil end
	local suffix = args["suffix"]; if suffix == "" then suffix = nil end
	local appendix = args["appendix"]; if appendix == "" then appendix = nil end
	local has_ins_sg = args["has_ins_sg"]; if has_ins_sg == "" then has_ins_sg = nil end
	
	-- Add the possessive suffix to the comitative plural, if the word is a noun
	if pos == "noun" and data.forms["com_pl"] then
		for key, subform in ipairs(data.forms["com_pl"]) do
			data.forms["com_pl"][key] = subform .. "en"
		end
	end
	
	if nosg or n == "pl" then
		table.insert(data.categories, "Finnish pluralia tantum")
	end
	
	-- TODO: This says "nouns", but this module is also used for adjectives!
	if nopl or n == "sg" then
		table.insert(data.categories, "Finnish uncountable nouns")
	end
	
	if not has_ins_sg then
		data.forms["ins_sg"] = nil
	end
	
	for key, form in pairs(data.forms) do
		-- Add suffix to forms
		for i, subform in ipairs(form) do
			subform = subform .. (suffix or "")
			form[i] = subform
		end
		
		if form.rare then
			for i, subform in ipairs(form.rare) do
				subform = subform .. (suffix or "")
				form.rare[i] = subform
			end
		end
		
		-- Do not show singular or plural forms for nominals that don't have them
		if ((nosg or n == "pl") and key:find("_sg$")) or ((nopl 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 not appendix and lang:makeEntryName(data.forms[(nosg or n == "pl") and "nom_pl" or "nom_sg"][1]) ~= mw.title.getCurrentTitle().text then
		table.insert(data.categories, "Finnish entries with inflection not matching pagename")
	end
end


-- Make the table
function make_table(data)
	local function show_form(form, no_rare)
		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(subform, nil, lang, nil, nil, nil, {}, false))
		end
		
		if not no_rare and form.rare then
			for key, subform in ipairs(form.rare) do
				table.insert(ret, m_links.full_link(subform, nil, lang, nil, nil, nil, {}, false) .. "<sup>řídce</sup>")
			end
		end
		
		return table.concat(ret, "<br/>")
	end
	
	local function repl(param)
		if param == "lemma" then
			return m_links.full_link(nil, mw.title.getCurrentTitle().text, lang, nil, "term", nil, {}, false)
		elseif param == "info" then
			return data.title and " (" .. data.title .. ")" or ""
		else
			local param2 = mw.ustring.match(param, "^(.-):c$")
			
			if param2 then
				return show_form(data.forms[param2], true)
			else
				return show_form(data.forms[param])
			end
		end
	end
	
	local wikicode = [=[
{| class="inflection-table vsSwitcher vsToggleCategory-inflection" style="border: solid 1px #CCCCFF; text-align:left;" cellspacing="1" cellpadding="2"
|- style="background: #CCCCFF; vertical-align: top;"
! class="vsToggleElement" colspan="4" | Ohýbání slova {{{lemma}}}{{{info}}}
|- class="vsShow" style="background: #F2F2FF; vertical-align: top;"
! style="min-width: 10em; background: #CCCCFF;" colspan="2" | nominativ
| style="min-width: 12em;" | {{{nom_sg:c}}}
| style="min-width: 12em;" | {{{nom_pl:c}}}
|- class="vsShow" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | genitiv
| {{{gen_sg:c}}}
| {{{gen_pl:c}}}
|- class="vsShow" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | partitiv
| {{{par_sg:c}}}
| {{{par_pl:c}}}
|- class="vsShow" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | illativ
| {{{ill_sg:c}}}
| {{{ill_pl:c}}}
|- class="vsHide" style="background: #CCCCFF; vertical-align: top;"
! style="min-width: 10em;" colspan="2" |
! style="min-width: 12em;" | jedn. č.
! style="min-width: 12em;" | mn. č.
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | nominativ
| {{{nom_sg}}}
| {{{nom_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" rowspan="2" | akkusativ
! style="background: #CCCCFF;" | nom.<sup style="border-bottom: 1px dotted black; cursor: help;" title="Nominativní akkusativ se používá například jako předmět některých pasivů a imperativů.">?</sup>
| {{{nom_sg}}}
| rowspan="2" | {{{nom_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" | gen.
| {{{gen_sg}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | genitiv
| {{{gen_sg}}}
| {{{gen_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | partitive
| {{{par_sg}}}
| {{{par_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | inessiv
| {{{ine_sg}}}
| {{{ine_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | elativ
| {{{ela_sg}}}
| {{{ela_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | illativ
| {{{ill_sg}}}
| {{{ill_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | adessiv
| {{{ade_sg}}}
| {{{ade_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | ablativ
| {{{abl_sg}}}
| {{{abl_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | allativ
| {{{all_sg}}}
| {{{all_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | essiv
| {{{ess_sg}}}
| {{{ess_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | translativ
| {{{tra_sg}}}
| {{{tra_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | instruktiv
| {{{ins_sg}}}
| {{{ins_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | abessiv
| {{{abe_sg}}}
| {{{abe_pl}}}
|- class="vsHide" style="background: #F2F2FF; vertical-align: top;"
! style="background: #CCCCFF;" colspan="2" | komitativ
| {{{com_sg}}}
| {{{com_pl}}}
|}]=]
	return mw.ustring.gsub(wikicode, "{{{([a-z0-9_:]+)}}}", repl)
end

return export