モジュール:sl-adjective

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

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

local export = {}

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

-- Within this module, inflections are the functions that do the actual inflecting
-- by creating the forms of an adjective. They are defined further down.
local inflections = {}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	PAGENAME = mw.title.getCurrentTitle().text
	FULLPAGENAME = mw.title.getCurrentTitle().prefixedText
	NAMESPACE = mw.title.getCurrentTitle().nsText
	local infl_type = frame.args[1] or error("活用形が指定されていません。")
	local args = frame:getParent().args
	
	local data = {forms = {}, info = nil, categories = {}}
	
	if inflections[infl_type] then
		inflections[infl_type](args, data)
	else
		error("不明な活用形 '" .. infl_type .. "'")
	end
	
	return make_table(data)
end

-- Hard stem adjective
inflections["regular"] = function(args, data)
	local stem = args[1]; if not stem or stem == "" then if NAMESPACE == "テンプレート" then stem = "-" else error("第1パラメータ(語幹)が指定されていません。") end end
	local final = args[2]; if final == "" then final = nil end
	local def = args["def"]
	
	-- Create the full stem, which is used when endings are added
	local full_stem = stem
	
	if final then
		full_stem = full_stem .. final
	else
		full_stem = make_long(full_stem)
	end
	
	-- If the given stem doesn't contain any accent marks, flag the entry for attention
	if not require("モジュール:sl-common").has_accents(full_stem) then
		table.insert(data.categories, "スロヴェニア語 形容詞 アクセント未記載")
	end

	-- Is this a hard stem or a soft stem?
	local oe = "o"
	data.info = "硬変化"
	
	if require("モジュール:sl-common").is_soft(full_stem) then
		oe = "e"
		data.info = "軟変化"
	end
	
	-- Masculine singular
	if def == "1" then
		data.forms["nom_sg_m"] = {full_stem .. "i"}
	elseif def == "0" then
		data.forms["nom_sg_m"] = {stem .. (final and "e" .. final or "")}
	else
		data.forms["nom_sg_m"] = {stem .. (final and "e" .. final or "")}
		data.forms["nom_sg_m_def"] = {full_stem .. "i"}
	end
	-- acc_sg_m depends on animacy
	data.forms["gen_sg_m"] = {full_stem .. "ega"}
	data.forms["dat_sg_m"] = {full_stem .. "emu"}
	data.forms["loc_sg_m"] = {full_stem .. "em"}
	data.forms["ins_sg_m"] = {full_stem .. "im"}
	
	-- Feminine singular
	data.forms["nom_sg_f"] = {full_stem .. "a"}
	data.forms["acc_sg_f"] = {full_stem .. "o"}
	data.forms["gen_sg_f"] = {full_stem .. "e"}
	data.forms["dat_sg_f"] = {full_stem .. "i"}
	data.forms["loc_sg_f"] = {full_stem .. "i"}
	data.forms["ins_sg_f"] = {full_stem .. "o"}
	
	-- Neuter singular
	data.forms["nom_sg_n"] = {full_stem .. oe}
	data.forms["acc_sg_n"] = {full_stem .. oe}
	data.forms["gen_sg_n"] = {full_stem .. "ega"}
	data.forms["dat_sg_n"] = {full_stem .. "emu"}
	data.forms["loc_sg_n"] = {full_stem .. "em"}
	data.forms["ins_sg_n"] = {full_stem .. "im"}
	
	-- Masculine dual
	data.forms["nom_du_m"] = {full_stem .. "a"}
	data.forms["acc_du_m"] = {full_stem .. "a"}
	data.forms["gen_du_m"] = {full_stem .. "ih"}
	data.forms["dat_du_m"] = {full_stem .. "ima"}
	data.forms["loc_du_m"] = {full_stem .. "ih"}
	data.forms["ins_du_m"] = {full_stem .. "ima"}
	
	-- Feminine dual
	data.forms["nom_du_f"] = {full_stem .. "i"}
	data.forms["acc_du_f"] = {full_stem .. "i"}
	data.forms["gen_du_f"] = {full_stem .. "ih"}
	data.forms["dat_du_f"] = {full_stem .. "ima"}
	data.forms["loc_du_f"] = {full_stem .. "ih"}
	data.forms["ins_du_f"] = {full_stem .. "ima"}
	
	-- Neuter dual
	data.forms["nom_du_n"] = {full_stem .. "i"}
	data.forms["acc_du_n"] = {full_stem .. "i"}
	data.forms["gen_du_n"] = {full_stem .. "ih"}
	data.forms["dat_du_n"] = {full_stem .. "ima"}
	data.forms["loc_du_n"] = {full_stem .. "ih"}
	data.forms["ins_du_n"] = {full_stem .. "ima"}
	
	-- Masculine plural
	data.forms["nom_pl_m"] = {full_stem .. "i"}
	data.forms["acc_pl_m"] = {full_stem .. "e"}
	data.forms["gen_pl_m"] = {full_stem .. "ih"}
	data.forms["dat_pl_m"] = {full_stem .. "im"}
	data.forms["loc_pl_m"] = {full_stem .. "ih"}
	data.forms["ins_pl_m"] = {full_stem .. "imi"}
	
	-- Feminine plural
	data.forms["nom_pl_f"] = {full_stem .. "e"}
	data.forms["acc_pl_f"] = {full_stem .. "e"}
	data.forms["gen_pl_f"] = {full_stem .. "ih"}
	data.forms["dat_pl_f"] = {full_stem .. "im"}
	data.forms["loc_pl_f"] = {full_stem .. "ih"}
	data.forms["ins_pl_f"] = {full_stem .. "imi"}
	
	-- Neuter plural
	data.forms["nom_pl_n"] = {full_stem .. "a"}
	data.forms["acc_pl_n"] = {full_stem .. "a"}
	data.forms["gen_pl_n"] = {full_stem .. "ih"}
	data.forms["dat_pl_n"] = {full_stem .. "im"}
	data.forms["loc_pl_n"] = {full_stem .. "ih"}
	data.forms["ins_pl_n"] = {full_stem .. "imi"}
end

function make_long(stem)
	local vowel_repl = {
		["à"] = "á",
		["è"] = "ê",
		["ì"] = "í",
		["ò"] = "ô",
		["ù"] = "ú"}
	
	function repl(vowel, rest)
		return (vowel_repl[vowel] or vowel) .. rest
	end
	
	return mw.ustring.gsub(stem, "([àèìòù])([^aeiouàèìòùáéíóúêô]+)$", repl)
end

function make_table(data)
	local function repl(param)
		local accel = false  -- Temporary
		local no_store = false
		
		if param == "info" then
			return mw.getContentLanguage():ucfirst(data.info or "")
		elseif string.sub(param, 1, 1) == "!" then
			no_store = true
			param = string.sub(param, 2)
		elseif string.sub(param, 1, 1) == "#" then
			accel = false
			param = string.sub(param, 2)
		end
		
		local forms = data.forms[param]
		
		if not forms then
			return "—"
		end
		
		local ret = {}
		
		for key, subform in ipairs(forms) do
			table.insert(ret, require("モジュール:links").full_link({lang = lang, term = subform, accel = accel and {form = param, no_store = no_store} or nil}))
		end
		
		return table.concat(ret, "<br/>")
	end
	
	local wikicode = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="background: #F9F9F9; border: 1px solid #aaaaaa;"
|- style="background: #d9ebff; text-align: left;"
! class="vsToggleElement" colspan="4" | {{{info}}}
|- class="vsShow"
! style="background: #d9ebff; width: 9em;" | 
! style="background: #d9ebff; width: 10em;" | 男性
! style="background: #d9ebff; width: 10em;" | 女性
! style="background: #d9ebff; width: 10em;" | 中性
|- class="vsShow"
! style="width: 11em; background: #eff7ff;" | 単数主格
| style="width: 11em;" | {{{!nom_sg_m}}}
| style="width: 11em;" | {{{!nom_sg_f}}}
| style="width: 11em;" | {{{!nom_sg_n}}}
|- class="vsHide"
! colspan="4" style="background: #b3d7ff;" | 単数
|- class="vsHide"
! style="width: 11em; background: #d9ebff;" | 
! style="width: 11em; background: #d9ebff;" | 男性
! style="width: 11em; background: #d9ebff;" | 女性
! style="width: 11em; background: #d9ebff;" | 中性
|- class="vsHide"
! style="background: #eff7ff;" | 主格
| {{{nom_sg_m}}}]=] .. (data.forms["nom_sg_m_def"] and ' <sup style="cursor:help" title="indefinite">非限定</sup><br/>{{{nom_sg_m_def}}} <sup style="cursor:help" title="definite">限定</sup>' or "") .. [=[

| {{{nom_sg_f}}}
| {{{nom_sg_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 対格
| ''主格''<sup style="cursor:help" title="inanimate">不活動体</sup>'' 又は<br/>生格''<sup style="cursor:help" title="animate">活動体</sup>
| {{{acc_sg_f}}}
| {{{acc_sg_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 生格
| {{{gen_sg_m}}}
| {{{gen_sg_f}}}
| {{{gen_sg_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 与格
| {{{dat_sg_m}}}
| {{{dat_sg_f}}}
| {{{dat_sg_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 前置格
| {{{loc_sg_m}}}
| {{{loc_sg_f}}}
| {{{loc_sg_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 造格
| {{{ins_sg_m}}}
| {{{ins_sg_f}}}
| {{{ins_sg_n}}}
|- class="vsHide"
! colspan="4" style="background: #b3d7ff;" | 双数
|- class="vsHide"
! style="background: #d9ebff;" | 
! style="background: #d9ebff;" | 男性
! style="background: #d9ebff;" | 女性
! style="background: #d9ebff;" | 中性
|- class="vsHide"
! style="background: #eff7ff;" | 主格
| {{{nom_du_m}}}
| {{{nom_du_f}}}
| {{{nom_du_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 対格
| {{{acc_du_m}}}
| {{{acc_du_f}}}
| {{{acc_du_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 生格
| {{{gen_du_m}}}
| {{{gen_du_f}}}
| {{{gen_du_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 与格
| {{{dat_du_m}}}
| {{{dat_du_f}}}
| {{{dat_du_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 前置格
| {{{loc_du_m}}}
| {{{loc_du_f}}}
| {{{loc_du_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 造格
| {{{ins_du_m}}}
| {{{ins_du_f}}}
| {{{ins_du_n}}}
|- class="vsHide"
! colspan="4" style="background: #b3d7ff;" | 複数
|- class="vsHide"
! style="background: #d9ebff;" | 
! style="background: #d9ebff;" | 男性
! style="background: #d9ebff;" | 女性
! style="background: #d9ebff;" | 中性
|- class="vsHide"
! style="background: #eff7ff;" | 主格
| {{{nom_pl_m}}}
| {{{nom_pl_f}}}
| {{{nom_pl_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 対格
| {{{acc_pl_m}}}
| {{{acc_pl_f}}}
| {{{acc_pl_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 生格
| {{{gen_pl_m}}}
| {{{gen_pl_f}}}
| {{{gen_pl_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 与格
| {{{dat_pl_m}}}
| {{{dat_pl_f}}}
| {{{dat_pl_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 前置格
| {{{loc_pl_m}}}
| {{{loc_pl_f}}}
| {{{loc_pl_n}}}
|- class="vsHide"
! style="background: #eff7ff;" | 造格
| {{{ins_pl_m}}}
| {{{ins_pl_f}}}
| {{{ins_pl_n}}}
|}]=]
	
	return mw.ustring.gsub(wikicode, "{{{([^}]+)}}}", repl) .. require("モジュール:utilities").format_categories(data.categories, lang)
end

return export