local m_utilities = require("Module:utilities")
local m_links = require("Module:links")
local m_common = require("Module:urj-fin-common")
local export = {}
local lang = require("Module:languages").getByCode("urj-fin-pro")
-- 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 args = frame:getParent().args
local data = {forms = {}, title = nil, categories = {}}
-- Generate the forms
inflect(args, data)
-- Apply gradation
for key, forms in pairs(data.forms) do
for i, form in ipairs(forms) do
forms[i] = m_common.apply_gradation(form)
end
end
-- 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().subpageText then
table.insert(data.categories, lang:getCanonicalName() .. " entries with inflection not matching pagename")
end
return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end
function inflect(args, data)
local prefix = args[1] or ""
local stem = args[2] or ""
if stem == "" then
stem = prefix
prefix = ""
end
if stem == "" then
if mw.title.getCurrentTitle().nsText == "Template" then
stem = "-"
else
error("Parameter 1 (stem) must be provided")
end
end
local vowels = m_common.detect_harmony(stem)
local stems = m_common.make_stems((mw.ustring.gsub(stem, "([aeiouäöü])nen$", "%1c")), true)
if mw.ustring.find(stem, "[aeiouäöü]nen$") then
stems.final = stem
end
make_forms(stems, vowels, data)
if mw.ustring.find(stem, "^[mc]inu$") then
data.forms["nom_sg"] = {(mw.ustring.gsub(stem, "u$", "ä"))}
data.forms["acc_sg"] = {stem .. "t"}
for key, form in pairs(data.forms) do
if key:find("_pl") then
data.forms[key] = nil
end
end
elseif mw.ustring.find(stem, "^[mt]e$") then
data.forms["nom_pl"] = {stem, (mw.ustring.gsub(stem, "e$", "öö"))}
data.forms["acc_pl"] = {stem .. "det", stem .. "idet"}
for key, form in pairs(data.forms) do
if key:find("_sg") then
data.forms[key] = nil
end
end
elseif stem == "hän" then
data.forms["nom_sg"] = {"hän"}
data.forms["acc_sg"] = {"hänet"}
for key, form in pairs(data.forms) do
if key:find("_pl") then
data.forms[key] = nil
end
end
end
for key, subforms in pairs(data.forms) do
for i, form in ipairs(subforms) do
subforms[i] = prefix .. form
end
end
for _, t in ipairs(stems.types) do
-- table.insert(data.categories, "Proto-Finnic nominals by type/" .. t)
end
end
function make_forms(stems, vowels, data)
data.forms["nom_sg"] = {stems.final}
data.forms["acc_sg"] = {stems.normal .. "n"}
data.forms["gen_sg"] = {stems.normal .. "n"}
data.forms["par_sg"] = {stems.t .. vowels.a}
data.forms["ine_sg"] = {stems.normal .. "ss" .. vowels.a}
data.forms["ela_sg"] = {stems.normal .. "st" .. vowels.a}
data.forms["ill_sg"] = {stems.normal .. "sen"}
data.forms["ade_sg"] = {stems.normal .. "ll" .. vowels.a}
data.forms["abl_sg"] = {stems.normal .. "lt" .. vowels.a}
data.forms["all_sg"] = {stems.normal .. "lek"}
data.forms["ess_sg"] = {stems.n .. vowels.a}
data.forms["tra_sg"] = {stems.normal .. "ksi"}
data.forms["com_sg"] = {stems.n .. "ek"}
data.forms["ins_sg"] = {stems.normal .. "n"}
data.forms["abe_sg"] = {stems.normal .. "kt" .. vowels.a}
data.forms["nom_pl"] = {stems.normal .. "t"}
data.forms["acc_pl"] = {stems.normal .. "t"}
data.forms["gen_pl"] = {stems.t .. "en", stems.i .. "ten"}
data.forms["par_pl"] = {stems.i .. "t" .. vowels.a}
data.forms["ine_pl"] = {stems.i .. "ss" .. vowels.a}
data.forms["ela_pl"] = {stems.i .. "st" .. vowels.a}
data.forms["ill_pl"] = {stems.i .. "sen"}
data.forms["ade_pl"] = {stems.i .. "ll" .. vowels.a}
data.forms["abl_pl"] = {stems.i .. "lt" .. vowels.a}
data.forms["all_pl"] = {stems.i .. "lek"}
data.forms["ess_pl"] = {stems.i .. "n" .. vowels.a}
data.forms["tra_pl"] = {stems.i .. "ksi"}
data.forms["com_pl"] = {stems.i .. "nek"}
data.forms["ins_pl"] = {stems.i .. "n"}
data.forms["abe_pl"] = {stems.i .. "kt" .. vowels.a}
end
-- Functions for generating the inflection table
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
table.insert(ret, m_links.full_link({lang = lang, alt = "*" .. subform}))
end
return table.concat(ret, "<br/>")
end
-- Make the table
function make_table(data)
return [=[<div class="NavFrame" style="width: 40%">
<div class="NavHead" style="background:rgb(80%,80%,100%);">]=] .. m_links.full_link({lang = lang, alt = "*" .. mw.title.getCurrentTitle().subpageText}, "term") .. (data.title and " (" .. data.title .. ")" or "") .."的變格" .. [=[</div>
<div class="NavContent">
{| class="inflection-table" style="width:100%; color:rgb(0%,0%,30%); border:solid 1px rgb(80%,80%,100%); text-align:left;" cellspacing="1" cellpadding="2"
|- style="background:rgb(80%,80%,100%);vertical-align:top;"
! style="width:33%;" colspan="2" |
! style="width:33%;" | 單數
! style="width:33%;" | 複數
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 主格
| ]=] .. show_form(data.forms["nom_sg"]) .. [=[
| ]=] .. show_form(data.forms["nom_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 賓格
| ]=] .. show_form(data.forms["acc_sg"]) .. [=[
| ]=] .. show_form(data.forms["acc_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 屬格
| ]=] .. show_form(data.forms["gen_sg"]) .. [=[
| ]=] .. show_form(data.forms["gen_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 部分格
| ]=] .. show_form(data.forms["par_sg"]) .. [=[
| ]=] .. show_form(data.forms["par_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 內格
| ]=] .. show_form(data.forms["ine_sg"]) .. [=[
| ]=] .. show_form(data.forms["ine_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 出格
| ]=] .. show_form(data.forms["ela_sg"]) .. [=[
| ]=] .. show_form(data.forms["ela_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 入格
| ]=] .. show_form(data.forms["ill_sg"]) .. [=[
| ]=] .. show_form(data.forms["ill_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 所格
| ]=] .. show_form(data.forms["ade_sg"]) .. [=[
| ]=] .. show_form(data.forms["ade_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 奪格
| ]=] .. show_form(data.forms["abl_sg"]) .. [=[
| ]=] .. show_form(data.forms["abl_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 向格
| ]=] .. show_form(data.forms["all_sg"]) .. [=[
| ]=] .. show_form(data.forms["all_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 樣格
| ]=] .. show_form(data.forms["ess_sg"]) .. [=[
| ]=] .. show_form(data.forms["ess_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 變格
| ]=] .. show_form(data.forms["tra_sg"]) .. [=[
| ]=] .. show_form(data.forms["tra_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 具格
| ]=] .. show_form(data.forms["ins_sg"]) .. [=[
| ]=] .. show_form(data.forms["ins_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 共格
| ]=] .. show_form(data.forms["com_sg"]) .. [=[
| ]=] .. show_form(data.forms["com_pl"]) .. [=[
|- style="background:rgb(95%,95%,100%);vertical-align:top;" |
! style="background:rgb(80%,80%,100%);" colspan="2" | 缺格
| ]=] .. show_form(data.forms["abe_sg"]) .. [=[
| ]=] .. show_form(data.forms["abe_pl"]) .. [=[
|}
</div>
</div>]=]
end
return export