モジュール:se-nouns
このモジュールについての説明文ページを モジュール:se-nouns/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",
low = "a", s_low = "normal",
diph = "a", s_diph = "normal",
diph_ill = "i", s_diph_ill = "simp",
},
["á"] = {
normal = "á", s_normal = "normal",
low = "á", s_low = "normal",
diph = "á", s_diph = "normal",
diph_ill = "á", s_diph_ill = "normal",
},
["e"] = {
normal = "e", s_normal = "normal",
low = "e", s_low = "normal",
diph = "i", s_diph = "normal",
diph_ill = "i", s_diph_ill = "normal",
},
["i"] = {
normal = "i", s_normal = "normal",
low = "e", s_low = "normal",
diph = "i", s_diph = "simp",
diph_ill = "á", s_diph_ill = "normal",
},
["o"] = {
normal = "o", s_normal = "normal",
low = "o", s_low = "normal",
diph = "o", s_diph = "normal",
diph_ill = "o", s_diph_ill = "normal",
},
["u"] = {
normal = "u", s_normal = "normal",
low = "o", s_low = "normal",
diph = "u", s_diph = "normal",
diph_ill = "u", s_diph_ill = "simp",
},
["{{{4}}}"] = {
normal = "{{{4}}}", s_normal = "normal",
low = "{{{4}}}", s_low = "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() .. " nouns 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 == "e" 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, á, e, i, o, u.")
end
table.insert(data.categories, lang:getCanonicalName() .. " nouns 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"}
if stems.weak[vs.s_normal] ~= stems.weak[vs.s_low] or vs.normal ~= vs.low then
table.insert(data.forms["gen_sg"], stems.weak[vs.s_low] .. vs.low)
end
end
inflections["odd"] = function(args, data)
data.title = "odd"
table.insert(data.categories, lang:getCanonicalName() .. " nouns 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"}
end
inflections["contr"] = function(args, data)
data.title = "contracted"
table.insert(data.categories, lang:getCanonicalName() .. " nouns 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() .. " nouns with contracted inflection in -á")
elseif vowel == "e" then
table.insert(data.categories, lang:getCanonicalName() .. " nouns with contracted inflection in -e")
elseif vowel == "o" then
table.insert(data.categories, lang:getCanonicalName() .. " nouns 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
end
function postprocess(args, data)
local n = args["n"]; if n == "" then n = nil end
if n == "pl" then
table.insert(data.categories, lang:getCanonicalName() .. " 絶対複数")
elseif n == "sg" then
table.insert(data.categories, lang:getCanonicalName() .. " 不可算名詞")
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 data.forms["nom_" .. (n or "sg")] and lang:makeEntryName(data.forms["nom_" .. (n or "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, "<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
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" | {{{nom_sg}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 属格
| colspan="2" | {{{gen_sg}}}
|- 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;" | 対格
| {{{acc_sg}}}
| {{{acc_pl}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | 属格
| {{{gen_sg}}}
| {{{gen_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