モジュール:se-adjectives

出典: フリー多機能辞典『ウィクショナリー日本語版(Wiktionary)』
ナビゲーションに移動 検索に移動

このモジュールについての説明文ページを モジュール:se-adjectives/doc に作成できます

local m_utilities = require("モジュール:utilities")
local m_links = require("モジュール:links")
local m_common = require("モジュール:se-common")

local lang = require("モジュール:languages").getByCode("se")

local export = {}

-- Functions that do the actual inflecting by creating the forms of a basic term.
local inflections = {}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local infl_type = frame.args[1] or error("活用形が指定されていません。パラメータ1をモジュールの呼び出しに渡して下さい。")
	local args = frame:getParent().args
	
	if not inflections[infl_type] then
		error("不明な活用形 '" .. infl_type .. "'")
	end
	
	local data = {forms = {}, title = nil, categories = {}}
	
	-- Generate the forms
	inflections[infl_type](args, data)
	
	-- Postprocess
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


local vowel_select = {
	["a"] = {
		normal = "a", s_normal = "normal",
		diph = "a", s_diph = "normal",
		diph_ill = "i", s_diph_ill = "simp",
	},
	
	["á"] = {
		normal = "á", s_normal = "normal",
		diph = "á", s_diph = "normal",
		diph_ill = "á", s_diph_ill = "normal",
	},
	
	["e"] = {
		normal = "e", s_normal = "normal",
		diph = "i", s_diph = "normal",
		diph_ill = "i", s_diph_ill = "normal",
	},
	
	["i"] = {
		normal = "i", s_normal = "normal",
		diph = "i", s_diph = "simp",
		diph_ill = "á", s_diph_ill = "normal",
	},
	
	["o"] = {
		normal = "o", s_normal = "normal",
		diph = "o", s_diph = "normal",
		diph_ill = "o", s_diph_ill = "normal",
	},
	
	["u"] = {
		normal = "u", s_normal = "normal",
		diph = "u", s_diph = "normal",
		diph_ill = "u", s_diph_ill = "simp",
	},
	
	["{{{4}}}"] = {
		normal = "{{{4}}}", s_normal = "normal",
		diph = "{{{4}}}", s_diph = "normal",
		diph_ill = "{{{4}}}", s_diph_ill = "normal",
	},
}


-- Inflection functions

inflections["even"] = function(args, data)
	data.title = "even"
	table.insert(data.categories, lang:getCanonicalName() .. " adjectives with even inflection")
	
	local base = args[1] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{1}}}") or ""; if base == "" then error("Parameter 1 (base stem) may not be empty.") end
	local strong_grade = args[2] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{2}}}") or ""
	local weak_grade = args[3] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{3}}}") or ""
	local suff = args[4] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{4}}}") or ""
	local nofinal = args["nofinal"]; if not final or final == "" then final = false else final = true end
	
	local stems, vowel = m_common.make_stems(base, strong_grade, weak_grade, nil, suff)
	
	if not (vowel == "a" or vowel == "á" or vowel == "i" or vowel == "o" or vowel == "u") and not (vowel == "{{{4}}}" and mw.title.getCurrentTitle().nsText == "テンプレート") then
		error("The final vowel(s) of the stem must be one of a, á, i, o, u.")
	end
	
	table.insert(data.categories, lang:getCanonicalName() .. " adjectives with even inflection in -" .. vowel)
	
	if stems.strong.cons == stems.weak.cons then
		data.title = data.title .. ", no gradation"
	elseif mw.title.getCurrentTitle().nsText == "テンプレート" then
		data.title = data.title .. ", " .. m_links.full_link(nil, "{{{2}}}", lang, nil, "term", nil, {}, false) .. "-" .. m_links.full_link(nil, "{{{3}}}", lang, nil, "term", nil, {}, false) .. " gradation"
	else
		data.title = data.title .. ", " .. m_links.full_link(nil, stems.strong.cons, lang, nil, "term", nil, {}, false) .. "-" .. m_links.full_link(nil, stems.weak.cons, lang, nil, "term", nil, {}, false) .. " gradation"
	end
	
	local vs = vowel_select[vowel]
	
	data.forms["nom_sg"] = {nofinal and m_common.make_final(stems.strong[vs.s_normal]) or stems.strong[vs.s_normal] .. vs.normal}
	data.forms["acc_sg"] = {stems.weak[vs.s_normal] .. vs.normal}
	data.forms["gen_sg"] = {stems.weak[vs.s_normal] .. vs.normal}
	data.forms["ill_sg"] = {stems.strong[vs.s_diph_ill] .. vs.diph_ill .. "i"}
	data.forms["loc_sg"] = {stems.weak[vs.s_normal] .. vs.normal .. "s"}
	data.forms["com_sg"] = {stems.weak[vs.s_diph] .. vs.diph .. "in"}
	
	data.forms["nom_pl"] = {stems.weak[vs.s_normal] .. vs.normal .. "t"}
	data.forms["acc_pl"] = {stems.weak[vs.s_diph] .. vs.diph .. "id"}
	data.forms["gen_pl"] = {stems.weak[vs.s_diph] .. vs.diph .. "id"}
	data.forms["ill_pl"] = {stems.weak[vs.s_diph] .. vs.diph .. "ide"}
	data.forms["loc_pl"] = {stems.weak[vs.s_diph] .. vs.diph .. "in"}
	data.forms["com_pl"] = {stems.weak[vs.s_diph] .. vs.diph .. "iguin"}
	
	data.forms["ess"] = {stems.strong[vs.s_normal] .. vs.normal .. "n"}
	
	local attr = args["attr"]; if not attr or attr == "" then attr = nil end
	
	if attr ~= "-" then
		data.forms["attr"] = attr and {attr} or mw.clone(data.forms["nom_sg"])
		
		attr = args["attr2"]; if not attr or attr == "" then attr = nil end
		table.insert(data.forms["attr"], attr)
		
		attr = args["attr3"]; if not attr or attr == "" then attr = nil end
		table.insert(data.forms["attr"], attr)
	end
end


inflections["odd"] = function(args, data)
	data.title = "odd"
	table.insert(data.categories, lang:getCanonicalName() .. " adjectives with odd inflection")
	
	local base = args[1] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{1}}}") or ""; if base == "" then error("Parameter 1 (base stem) may not be empty.") end
	local strong_grade = args[2] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{2}}}") or ""
	local weak_grade = args[3] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{3}}}") or ""
	local suff = args[4] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{4}}}") or ""
	local final = args["final"]; if not final or final == "" then final = nil end
	
	local stem_strong, vowel = m_common.make_stem(base .. strong_grade .. suff, true)
	local stem_weak = m_common.make_stem(base .. weak_grade .. suff)
	
	if vowel ~= "" then
		error("The strong-grade stem must end in a consonant.")
	end
	
	local stem_final = m_common.make_final(stem_weak, final)
	
	if stem_strong == stem_weak then
		data.title = data.title .. ", no gradation"
	elseif mw.title.getCurrentTitle().nsText == "テンプレート" then
		data.title = data.title .. ", " .. m_links.full_link(nil, "{{{2}}}", lang, nil, "term", nil, {}, false) .. "-" .. m_links.full_link(nil, "{{{3}}}", lang, nil, "term", nil, {}, false) .. " gradation"
	else
		local strong_cons = m_common.get_final_consonants(stem_strong, -2)
		local weak_cons = m_common.get_final_consonants(stem_weak, -2)
		
		if strong_cons == weak_cons then
			data.title = data.title .. ", no gradation"
		else
			data.title = data.title .. ", " .. m_links.full_link(nil, strong_cons, lang, nil, "term", nil, {}, false) .. "-" .. m_links.full_link(nil, weak_cons, lang, nil, "term", nil, {}, false) .. " gradation"
		end
	end
	
	data.forms["nom_sg"] = {stem_final}
	data.forms["acc_sg"] = {stem_strong .. "a"}
	data.forms["gen_sg"] = {stem_strong .. "a"}
	data.forms["ill_sg"] = {stem_strong .. "ii"}
	data.forms["loc_sg"] = {stem_strong .. "is"}
	data.forms["com_sg"] = {stem_strong .. "iin"}
	
	data.forms["nom_pl"] = {stem_strong .. "at"}
	data.forms["acc_pl"] = {stem_strong .. "iid"}
	data.forms["gen_pl"] = {stem_strong .. "iid"}
	data.forms["ill_pl"] = {stem_strong .. "iidda"}
	data.forms["loc_pl"] = {stem_strong .. "iin"}
	data.forms["com_pl"] = {stem_strong .. "iiguin"}
	
	data.forms["ess"] = {stem_weak .. (m_common.get_final_consonants(stem_weak, -1) == "" and "" or "i") .. "n"}
	
	local attr = args["attr"]; if not attr or attr == "" then attr = nil end
	
	if attr ~= "-" then
		data.forms["attr"] = attr and {attr} or mw.clone(data.forms["nom_sg"])
		
		attr = args["attr2"]; if not attr or attr == "" then attr = nil end
		table.insert(data.forms["attr"], attr)
		
		attr = args["attr3"]; if not attr or attr == "" then attr = nil end
		table.insert(data.forms["attr"], attr)
	end
end


inflections["contr"] = function(args, data)
	data.title = "contracted"
	table.insert(data.categories, lang:getCanonicalName() .. " adjectives with contracted inflection")
	
	local base = args[1] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{1}}}") or ""; if base == "" then error("Parameter 1 (base stem) may not be empty.") end
	local strong_grade = args[2] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{2}}}") or ""
	local weak_grade = args[3] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{3}}}") or ""
	local suff = args[4] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{4}}}") or ""
	local final = args["final"]; if not final or final == "" then final = nil end
	
	local stem_strong, vowel = m_common.make_stem(base .. strong_grade .. suff, true)
	local stem_weak = m_common.make_stem(base .. weak_grade .. suff)
	local stem_strong_simp = m_common.simplify_diphthongs(stem_strong, -1)
	
	if not (vowel == "á" or vowel == "o") and not (vowel == "" and mw.title.getCurrentTitle().nsText == "テンプレート") then
		error("The final vowel(s) of the strong grade stem must be one of á, o.")
	end
	
	local stem_final = m_common.make_final(stem_weak, final)
	
	if stem_strong == stem_weak then
		data.title = data.title .. ", no gradation"
	elseif mw.title.getCurrentTitle().nsText == "テンプレート" then
		data.title = data.title .. ", " .. m_links.full_link(nil, "{{{2}}}", lang, nil, "term", nil, {}, false) .. "-" .. m_links.full_link(nil, "{{{3}}}", lang, nil, "term", nil, {}, false) .. " gradation"
	else
		local strong_cons = m_common.get_final_consonants(stem_strong, -1)
		local weak_cons = m_common.get_final_consonants(stem_weak, -2)
		
		if strong_cons == weak_cons then
			data.title = data.title .. ", no gradation"
		else
			data.title = data.title .. ", " .. m_links.full_link(nil, strong_cons, lang, nil, "term", nil, {}, false) .. "-" .. m_links.full_link(nil, weak_cons, lang, nil, "term", nil, {}, false) .. " gradation"
		end
	end
	
	data.forms["nom_sg"] = {stem_final}
	data.forms["acc_sg"] = {stem_strong .. vowel}
	data.forms["gen_sg"] = {stem_strong .. vowel}
	data.forms["ill_sg"] = {stem_strong .. vowel .. "i"}
	data.forms["loc_sg"] = {stem_strong .. vowel .. "s"}
	data.forms["com_sg"] = {stem_strong .. vowel .. "in"}
	
	data.forms["nom_pl"] = {stem_strong .. vowel .. "t"}
	data.forms["acc_pl"] = {stem_strong .. vowel .. "id"}
	data.forms["gen_pl"] = {stem_strong .. vowel .. "id"}
	data.forms["ill_pl"] = {stem_strong .. vowel .. "ide"}
	data.forms["loc_pl"] = {stem_strong .. vowel .. "in"}
	data.forms["com_pl"] = {stem_strong .. vowel .. "iguin"}
	
	data.forms["ess"] = {stem_weak .. (m_common.get_final_consonants(stem_weak, -1) == "" and "" or "i") .. "n"}
	
	if vowel == "á" then
		table.insert(data.categories, lang:getCanonicalName() .. " adjectives with contracted inflection in -á")
	elseif vowel == "o" then
		table.insert(data.categories, lang:getCanonicalName() .. " adjectives with contracted inflection in -o")
		
		data.forms["acc_sg"] = {stem_strong_simp .. "o"}
		data.forms["gen_sg"] = {stem_strong_simp .. "o"}
		data.forms["ill_sg"] = {stem_strong_simp .. "ui"}
		data.forms["loc_sg"] = {stem_strong_simp .. "os"}
		data.forms["com_sg"] = {stem_strong_simp .. "uin"}
		
		data.forms["nom_pl"] = {stem_strong_simp .. "ot"}
		data.forms["acc_pl"] = {stem_strong_simp .. "uid"}
		data.forms["gen_pl"] = {stem_strong_simp .. "uid"}
		data.forms["ill_pl"] = {stem_strong_simp .. "uide"}
		data.forms["loc_pl"] = {stem_strong_simp .. "uin"}
		data.forms["com_pl"] = {stem_strong_simp .. "uiguin"}
	end
	
	local attr = args["attr"]; if not attr or attr == "" then attr = nil end
	
	if attr ~= "-" then
		data.forms["attr"] = attr and {attr} or mw.clone(data.forms["nom_sg"])
		
		attr = args["attr2"]; if not attr or attr == "" then attr = nil end
		table.insert(data.forms["attr"], attr)
		
		attr = args["attr3"]; if not attr or attr == "" then attr = nil end
		table.insert(data.forms["attr"], attr)
	end
end


inflections["comp-even"] = function(args, data)
	data.title = "even, " .. m_links.full_link(nil, "bb", lang, nil, "term", nil, {}, false) .. "-" .. m_links.full_link(nil, "pp", lang, nil, "term", nil, {}, false) .. " gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " adjectives with even inflection")
	table.insert(data.categories, lang:getCanonicalName() .. " adjectives with even inflection in -o")
	
	local base = args[1] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{1}}}") or ""; if base == "" then error("Parameter 1 (base stem) may not be empty.") end
	
	data.forms["nom_sg"] = {base .. "it", base .. "et", base .. "eabbo"}
	data.forms["acc_sg"] = {base .. "eappo"}
	data.forms["gen_sg"] = {base .. "eappo"}
	data.forms["ill_sg"] = {base .. "ebbui"}
	data.forms["loc_sg"] = {base .. "eappos"}
	data.forms["com_sg"] = {base .. "eappuin"}
	
	data.forms["nom_pl"] = {base .. "eappot"}
	data.forms["acc_pl"] = {base .. "eappuid"}
	data.forms["gen_pl"] = {base .. "eappuid"}
	data.forms["ill_pl"] = {base .. "eappuide"}
	data.forms["loc_pl"] = {base .. "eappuin"}
	data.forms["com_pl"] = {base .. "eappuiguin"}
	
	data.forms["ess"] = {base .. "eabbon"}
	
	local attr = args["attr"]; if not attr or attr == "" then attr = nil end
	
	if attr ~= "-" then
		data.forms["attr"] = {base .. "it", base .. "et"}
	end
end


inflections["comp-odd"] = function(args, data)
	data.title = "odd, no gradation"
	table.insert(data.categories, lang:getCanonicalName() .. " adjectives with odd inflection")
	
	local base = args[1] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{1}}}") or ""; if base == "" then error("Parameter 1 (base stem) may not be empty.") end
	
	data.forms["nom_sg"] = {base .. "t"}
	data.forms["acc_sg"] = {base .. "bu"}
	data.forms["gen_sg"] = {base .. "bu"}
	data.forms["ill_sg"] = {base .. "bui"}
	data.forms["loc_sg"] = {base .. "bus"}
	data.forms["com_sg"] = {base .. "buin"}
	
	data.forms["nom_pl"] = {base .. "but"}
	data.forms["acc_pl"] = {base .. "buid"}
	data.forms["gen_pl"] = {base .. "buid"}
	data.forms["ill_pl"] = {base .. "buidda"}
	data.forms["loc_pl"] = {base .. "buin"}
	data.forms["com_pl"] = {base .. "buiguin"}
	
	data.forms["ess"] = {base .. "bun"}
	
	local attr = args["attr"]; if not attr or attr == "" then attr = nil end
	
	if attr ~= "-" then
		data.forms["attr"] = {base .. "t"}
	end
end


inflections["buorre"] = function(args, data)
	data.title = "even, " .. m_links.full_link(nil, "rr", lang, nil, "term", nil, {}, false) .. "-" .. m_links.full_link(nil, "r", lang, nil, "term", nil, {}, false) .. " gradation, no attributive"
	table.insert(data.categories, lang:getCanonicalName() .. " adjectives with even inflection")
	table.insert(data.categories, lang:getCanonicalName() .. " adjectives with even inflection in -i")
	
	local base = args[1] or (mw.title.getCurrentTitle().nsText == "テンプレート" and "{{{1}}}") or ""
	
	data.forms["nom_sg"] = {base .. "buorre"}
	data.forms["acc_sg"] = {base .. "buori"}
	data.forms["gen_sg"] = {base .. "buori"}
	data.forms["ill_sg"] = {base .. "buorrái"}
	data.forms["loc_sg"] = {base .. "buoris"}
	data.forms["com_sg"] = {base .. "buriin"}
	
	data.forms["nom_pl"] = {base .. "buorit"}
	data.forms["acc_pl"] = {base .. "buriid"}
	data.forms["gen_pl"] = {base .. "buriid"}
	data.forms["ill_pl"] = {base .. "buriide"}
	data.forms["loc_pl"] = {base .. "buriin"}
	data.forms["com_pl"] = {base .. "buriiguin"}
	
	data.forms["ess"] = {base .. "buorrin"}
end


function postprocess(args, data)
	-- Check if the lemma form matches the page name
	if data.forms["nom_sg"] and lang:makeEntryName(data.forms["nom_sg"][1]) ~= mw.title.getCurrentTitle().text 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
			if subform:find("{{{") then
				table.insert(ret, m_links.full_link(nil, subform, lang, nil, nil, nil, {}, false))
			else
				table.insert(ret, m_links.full_link(subform, nil, lang, nil, nil, nil, {}, false))
			end
		end
		
		return table.concat(ret, ", ")
	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
			return show_form(data.forms[param])
		end
	end
	
	local wikicode = [=[
{| class="inflection-table vsSwitcher vsToggleCategory-inflection" style="border:solid 1px #CCCCFF; text-align: left;" cellspacing="1" cellpadding="2"
|- style="background: #E2F6E2; text-align: left;"
! class="vsToggleElement" colspan="3" | {{{lemma}}}{{{info}}}の活用
|- class="vsShow" style="background: #F2F2FF;"
! style="width: 10em; background: #E2F6E2;" | 限定用法
| style="width: 15em;" colspan="2" | {{{attr}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 主格
| colspan="2" | {{{nom_sg}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 属格
| colspan="2" | {{{gen_sg}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 限定用法
| colspan="2" | {{{attr}}}
|- class="vsHide"
! style="width: 10em; background:#c0e4c0" |
! style="width: 15em; background:#c0e4c0" | 単数
! style="width: 15em; background:#c0e4c0" | 複数
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 主格
| {{{nom_sg}}}
| {{{nom_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 属格
| {{{gen_sg}}}
| {{{gen_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 対格
| {{{acc_sg}}}
| {{{acc_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 入格
| {{{ill_sg}}}
| {{{ill_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 処格
| {{{loc_sg}}}
| {{{loc_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 共格
| {{{com_sg}}}
| {{{com_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 様格
| colspan="2" | {{{ess}}}
|}]=]

	return mw.ustring.gsub(wikicode, "{{{([a-z_]+)}}}", repl)
end

return export