此模組需要說明文件。
請在說明文件頁加上適當的描述(如其目的、使用方法等)。

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

local export = {}


function export.even(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {forms = {}, info = "偶", categories = {lang:getCanonicalName() .. "偶名詞"}}
	
	local umlaut_j = args[1]
	local umlaut_e = args[1]
	local umlaut_je = args[1]
	
	if mw.ustring.find(args[1], "[aeiouāēōë]$") then
		local vowel = mw.ustring.match(args[1], "[aeiouāēōë]+$")
		table.insert(data.categories, lang:getCanonicalName() .. "偶" .. vowel .. "-詞幹名詞")
		umlaut_j = mw.ustring.gsub(args[1], "ē$", "i")
		umlaut_je = mw.ustring.gsub(umlaut_j, "ō$", "u")
		umlaut_e = mw.ustring.gsub(umlaut_e, "ē$", "ā")
		umlaut_e = mw.ustring.gsub(umlaut_e, "ō$", "u")
	else
		table.insert(data.categories, lang:getCanonicalName() .. "偶輔音詞幹名詞")
	end
	
	data.forms["nom_sg"] = {args[1]}
	data.forms["acc_sg"] = {args[1] .. "m"}
	data.forms["par_sg"] = {args[1] .. "tē"}
	data.forms["gen_sg"] = {args[1] .. "n"}
	data.forms["ess_sg"] = {args[1] .. "nē"}
	data.forms["ine_sg"] = {args[1] .. "snē"}
	data.forms["ela_sg"] = {args[1] .. "stē"}
	data.forms["ill_sg"] = {umlaut_e .. "sën"}
	data.forms["com_sg"] = {umlaut_j .. "jnē", umlaut_je .. "jnë"}
	data.forms["abe_sg"] = {args[1] .. "ptākëk"}
	
	data.forms["nom_pl"] = {args[1] .. "k"}
	data.forms["acc_pl"] = {umlaut_j .. "jtē"}
	data.forms["gen_pl"] = {umlaut_j .. "j"}
	data.forms["ine_pl"] = {umlaut_j .. "jnē"}
	data.forms["ela_pl"] = {umlaut_j .. "jstē"}
	
	-- Apply gradation
	for key, forms in pairs(data.forms) do
		for i, form in ipairs(forms) do
			forms[i] = require("Module:smi-pro-common").apply_gradation(form)
		end
	end
	
	return make_table(data) .. require("Module:utilities").format_categories(data.categories, lang)
end


function export.odd(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {forms = {}, info = "奇", categories = {lang:getCanonicalName() .. "奇名詞"}}
	
	local xstem = args[1]
	local umlaut_j = args[1]
	local umlaut_e = args[1]
	
	if mw.ustring.find(args[1], "[aeiouāēōë]$") then
		local vowel = mw.ustring.match(args[1], "[aeiouāēōë]+$")
		table.insert(data.categories, lang:getCanonicalName() .. "奇" .. vowel .. "-詞幹名詞")
		umlaut_j = mw.ustring.gsub(args[1], "ē$", "i")
		umlaut_e = mw.ustring.gsub(umlaut_e, "ē$", "ā")
		umlaut_e = mw.ustring.gsub(umlaut_e, "ō$", "u")
	else
		table.insert(data.categories, lang:getCanonicalName() .. "奇輔音詞幹名詞")
		umlaut_e = mw.ustring.gsub(umlaut_e, "ē([^aeiouāēōë])$", "ā%1")
		umlaut_e = mw.ustring.gsub(umlaut_e, "ō([^aeiouāēōë])$", "u%1")
		xstem = umlaut_e .. "ë"
	end
	
	data.forms["nom_sg"] = {args[1]}
	data.forms["acc_sg"] = {xstem .. "m"}
	data.forms["par_sg"] = {args[1] .. "tē"}
	data.forms["gen_sg"] = {xstem .. "n"}
	data.forms["ess_sg"] = {args[1] .. "nē"}
	data.forms["ine_sg"] = {xstem .. "snē"}
	data.forms["ela_sg"] = {xstem .. "stē"}
	data.forms["ill_sg"] = {umlaut_e .. "sën"}
	data.forms["com_sg"] = {xstem .. "jnē", xstem .. "jnë"}
	data.forms["abe_sg"] = {xstem .. "ptākëk"}
	
	data.forms["nom_pl"] = {xstem .. "k"}
	data.forms["acc_pl"] = {xstem .. "jtē"}
	data.forms["gen_pl"] = {xstem .. "j"}
	data.forms["ine_pl"] = {xstem .. "jnē"}
	data.forms["ela_pl"] = {xstem .. "jstē"}
	
	-- Apply gradation
	for key, forms in pairs(data.forms) do
		for i, form in ipairs(forms) do
			forms[i] = require("Module:smi-pro-common").apply_gradation(form)
		end
	end
	
	return make_table(data) .. require("Module:utilities").format_categories(data.categories, lang)
end


-- Make the table
function make_table(data)
	local function repl(param)
		if param == "info" then
			return mw.getContentLanguage():ucfirst(data.info or "")
		end
		
		local form = data.forms[param]
		
		if not form then
			return "—"
		end
		
		local ret = {}
		
		for key, subform in ipairs(form) do
			table.insert(ret, require("Module:links").full_link({lang = lang, alt = "*" .. subform}))
		end
		
		return table.concat(ret, "<br/>")
	end
	
	local wikicode = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="屈折" style="border: solid 1px #CCCCFF; text-align: left;" cellspacing="1" cellpadding="2"
|- style="background: #E2F6E2; text-align: left;"
! class="vsToggleElement" colspan="3" | {{{info}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="min-width: 8em; background: #E2F6E2;" | 主格
| style="min-width: 12em;" | {{{nom_sg}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="min-width: 8em; background: #E2F6E2;" | 屬格
| style="min-width: 12em;" | {{{gen_sg}}}
|- class="vsHide"
! style="min-width: 8em; background:#c0e4c0" |
! style="min-width: 12em; background:#c0e4c0" | 單數
! style="min-width: 12em; background:#c0e4c0" | 複數
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 主格
| {{{nom_sg}}}
| {{{nom_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 賓格
| {{{acc_sg}}}
| rowspan="2" | {{{acc_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 部分格
| {{{par_sg}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 屬格
| {{{gen_sg}}}
| {{{gen_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 樣格
| {{{ess_sg}}}
| rowspan="2" | {{{ine_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 內格
| {{{ine_sg}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 出格
| {{{ela_sg}}}
| {{{ela_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 入格
| {{{ill_sg}}}
| {{{ill_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 共格
| {{{com_sg}}}
| {{{com_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 欠格
| {{{abe_sg}}}
| {{{abe_pl}}}
|}]=]
	
	return mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)
end

return export