Module:odt-decl-adj
Appearance
- This module lacks a documentation subpage. Please create it.
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
local m_links = require("Module:links")
local m_utils = require("Module:utilities")
local lang = require("Module:languages").getByCode("odt")
local decl_data = {}
--
local function devoice(stem)
stem = mw.ustring.gsub(stem, "ng$", "nc")
stem = mw.ustring.gsub(stem, "d$", "t")
stem = mw.ustring.gsub(stem, "b$", "p")
stem = mw.ustring.gsub(stem, "v$", "f")
stem = mw.ustring.gsub(stem, "z$", "s")
return stem
end
local function C_to_K(stem)
stem = mw.ustring.gsub(stem, "cc$", "ck")
stem = mw.ustring.gsub(stem, "c$", "k")
return stem
end
local function K_to_C(stem)
stem = mw.ustring.gsub(stem, "ck$", "cc")
stem = mw.ustring.gsub(stem, "k$", "c")
return stem
end
local function degeminate(stem)
stem = mw.ustring.gsub(stem, "([bcdfghjklmnprstvwzþ])%1$", "%1")
stem = mw.ustring.gsub(stem, "ck$", "k")
return stem
end
--
decl_data["n"] = {
params = {
[1] = {},
["contract"] = {},
},
}
setmetatable(decl_data["n"], {__call = function(self, args, data)
data.decl_type = "n-stem"
stem = args[1]
stem_K_to_C = K_to_C(stem)
stem_C_to_K = C_to_K(stem)
stem_devoiced = degeminate(devoice(stem_K_to_C))
stem_contr = " "
data.forms["nom_sing_m_wk"] = {stem_K_to_C .. "o"}
data.forms["nom_sing_f_wk"] = {stem_K_to_C .. "a"}
data.forms["nom_sing_n_wk"] = {stem_K_to_C .. "a"}
data.forms["nom_plur_wk"] = {stem_K_to_C .. "on"}
data.forms["acc_sing_m_wk"] = {stem_K_to_C .. "on"}
data.forms["acc_sing_f_wk"] = {stem_K_to_C .. "on"}
data.forms["acc_sing_n_wk"] = {stem_K_to_C .. "a"}
data.forms["acc_plur_wk"] = {stem_K_to_C .. "on"}
data.forms["gen_sing_m_wk"] = {stem_C_to_K .. "in"}
data.forms["gen_sing_f_wk"] = {stem_K_to_C .. "on"}
data.forms["gen_sing_n_wk"] = {stem_C_to_K .. "in"}
data.forms["gen_plur_wk"] = {stem_K_to_C .. "ono"}
data.forms["dat_sing_m_wk"] = {stem_C_to_K .. "in"}
data.forms["dat_sing_f_wk"] = {stem_K_to_C .. "on"}
data.forms["dat_sing_n_wk"] = {stem_C_to_K .. "in"}
data.forms["dat_plur_wk"] = {stem_K_to_C .. "on"}
if args.contract then
if string.find(stem, "h$") then
stem_contr = mw.ustring.gsub(stem, "h$", "")
end
data.decl_type = "n-stem"
data.forms["nom_sing_m_wk"] = {stem_contr .. "o"}
data.forms["nom_sing_f_wk"] = {stem_contr .. "a"}
data.forms["nom_sing_n_wk"] = {stem_contr .. "a"}
data.forms["nom_plur_wk"] = {stem_contr .. "n"}
data.forms["acc_sing_m_wk"] = {stem_contr .. "n"}
data.forms["acc_sing_f_wk"] = {stem_contr .. "n"}
data.forms["acc_sing_n_wk"] = {stem_contr .. "a"}
data.forms["acc_plur_wk"] = {stem_contr .. "n"}
data.forms["gen_sing_m_wk"] = {stem_contr .. "n"}
data.forms["gen_sing_f_wk"] = {stem_contr .. "n"}
data.forms["gen_sing_n_wk"] = {stem_contr .. "n"}
data.forms["gen_plur_wk"] = {stem_contr .. "no"}
data.forms["dat_sing_m_wk"] = {stem_contr .. "n"}
data.forms["dat_sing_f_wk"] = {stem_contr .. "n"}
data.forms["dat_sing_n_wk"] = {stem_contr .. "n"}
data.forms["dat_plur_wk"] = {stem_contr .. "n"}
end
end
})
decl_data["a"] = {
params = {
[1] = {},
["contract"] = {},
},
}
setmetatable(decl_data["a"], {__call = function(self, args, data)
decl_data["n"](args, data)
data.decl_type = "a-stem"
data.forms["nom_sing_m_st"] = {stem_devoiced}
data.forms["nom_sing_f_st"] = {stem_devoiced}
data.forms["nom_sing_n_st"] = {stem_devoiced}
data.forms["nom_plur_st"] = {stem_K_to_C .. "a", stem_C_to_K .. "e"}
data.forms["acc_sing_m_st"] = {stem_K_to_C .. "an", stem_C_to_K .. "en"}
data.forms["acc_sing_f_st"] = {stem_K_to_C .. "a"}
data.forms["acc_sing_n_st"] = {stem_devoiced}
data.forms["acc_plur_st"] = {stem_K_to_C .. "a", stem_C_to_K .. "e"}
data.forms["gen_sing_m_st"] = {stem_C_to_K .. "es"}
data.forms["gen_sing_f_st"] = {stem_C_to_K .. "ero"}
data.forms["gen_sing_n_st"] = {stem_C_to_K .. "es"}
data.forms["gen_plur_st"] = {stem_C_to_K .. "ero"}
data.forms["dat_sing_m_st"] = {stem_C_to_K .. "in", stem_C_to_K .. "emo"}
data.forms["dat_sing_f_st"] = {stem_C_to_K .. "ero"}
data.forms["dat_sing_n_st"] = {stem_C_to_K .. "in", stem_C_to_K .. "emo"}
data.forms["dat_plur_st"] = {stem_K_to_C .. "on"}
if args.contract then
data.decl_type = "a-stem contracted"
data.forms["nom_plur_st"] = {stem_contr .. "a", stem_contr.. "e"}
data.forms["acc_sing_m_st"] = {stem_contr .. "n"}
data.forms["acc_sing_f_st"] = {stem_contr .. "a"}
data.forms["acc_plur_st"] = {stem_contr .. "a", stem_contr.. "e"}
data.forms["gen_sing_m_st"] = {stem_contr .. "s"}
data.forms["gen_sing_f_st"] = {stem_contr .. "ro"}
data.forms["gen_sing_n_st"] = {stem_contr .. "s"}
data.forms["gen_plur_st"] = {stem_contr .. "ro"}
data.forms["dat_sing_m_st"] = {stem_contr .. "n", stem_contr .. "mo"}
data.forms["dat_sing_f_st"] = {stem_contr .. "ro"}
data.forms["dat_sing_n_st"] = {stem_contr .. "n", stem_contr .. "mo"}
data.forms["dat_plur_st"] = {stem_contr .. "n"}
end
end
})
decl_data["ja"] = {
params = {
[1] = {},
},
}
setmetatable(decl_data["ja"], {__call = function(self, args, data)
decl_data["a"](args, data)
data.decl_type = "ja-stem"
data.forms["nom_sing_m_st"] = {stem_C_to_K .. "i"}
data.forms["nom_sing_f_st"] = {stem_C_to_K .. "i"}
data.forms["nom_sing_n_st"] = {stem_C_to_K .. "i"}
data.forms["acc_sing_m_st"] = {stem_C_to_K .. "en"}
data.forms["acc_sing_n_st"] = {stem_C_to_K .. "i"}
end
})
decl_data["wa"] = {
params = {
[1] = {},
},
}
setmetatable(decl_data["wa"], {__call = function(self, args, data)
decl_data["a"](args, data)
data.decl_type = "wa-stem"
stem_o = stem_K_to_C
if string.find(stem_o, "([aw])$") then
stem_o = mw.ustring.gsub(stem_o, "aw$", "ō")
else
stem_o = mw.ustring.gsub(stem_o, "w$", "o")
end
data.forms["nom_sing_m_st"] = {stem_o}
data.forms["nom_sing_f_st"] = {stem_o}
data.forms["nom_sing_n_st"] = {stem_o}
data.forms["acc_sing_n_st"] = {stem_o}
end
})
local function add_asterisks(forms, data)
for _, form in ipairs(forms) do
for i, subform in ipairs(data.forms[form]) do
data.forms[form][i] = "*" .. subform
end
end
end
function export.show(frame)
local parent_args = frame:getParent().args
local decl_type = frame.args["decl"]
if not decl_data[decl_type] then
error("Unknown declension '" .. decl_type .. "'")
end
local data = {forms = {}, categories = {}}
data.head = parent_args["head"] or nil
local args = require("Module:parameters").process(parent_args, decl_data[decl_type].params, true)
-- Override for templates
if not args[1] then
setmetatable(args, {__index = function(self, key)
return "{{{" .. key .. "}}}"
end
})
end
-- Generate the forms
decl_data[decl_type](args, data)
if decl_type == "a" then
table.insert(data.categories, "Old Dutch a-stem adjectives")
return make_table(data)
elseif decl_type == "ja" then
table.insert(data.categories, "Old Dutch ja-stem adjectives")
return make_table(data)
elseif decl_type == "wa" then
table.insert(data.categories, "Old Dutch wa-stem adjectives")
return make_table(data)
elseif decl_type == "n" then
table.insert(data.categories, "Old Dutch n-stem adjectives")
return make_table_n(data)
end
end
function make_table(data)
local function show_form(form)
if not form then
return "—"
end
local ret = {}
for key, subform in ipairs(form) do
if mw.title.getCurrentTitle().nsText == "Reconstruction" and subform ~= "—" then
subform = "*" .. subform
end
table.insert(ret, m_links.full_link({lang = lang, term = subform}))
end
return table.concat(ret, ", ")
end
local function repl(param)
if param == "decl_type" then
return data.decl_type
else
return show_form(data.forms[param])
end
end
local wikicode = [=[
<div class="NavFrame" style="width: 42em">
<div class="NavHead" style="">Declension of {{{nom_sing_m_st}}} ({{{decl_type}}})</div>
<div class="NavContent">
{| style="background:#f9f4e9; text-align:center; width:100%" cellpadding="0" cellspacing="1" class="inflection-table"
|-
|-
! style="background-color:#c6bec0" colspan="7" | strong declension
|-
! style="width: 10%; background:#dbdbdc" colspan="1" | '''case'''
! style="width: 20%; background:#eeeede" colspan="1" | masculine
! style="width: 20%; background:#eeeede" colspan="1" | feminine
! style="width: 20%; background:#eeeede" colspan="1" | neuter
! style="width: 20%; background:#eeeede" colspan="1" | plural
|-
|
|-
! style="background:#eeeeee" | nominative
| style="background-color:#fffffc;" | {{{nom_sing_m_st}}}
| style="background-color:#fffffc;" | {{{nom_sing_f_st}}}
| style="background-color:#fffffc;" | {{{nom_sing_n_st}}}
| style="background-color:#fffffc;" | {{{nom_plur_st}}}
|-
! style="background:#eeeeee" | accusative
| style="background-color:#fffffc;" | {{{acc_sing_m_st}}}
| style="background-color:#fffffc;" | {{{acc_sing_f_st}}}
| style="background-color:#fffffc;" | {{{acc_sing_n_st}}}
| style="background-color:#fffffc;" | {{{acc_plur_st}}}
|-
! style="background:#eeeeee" | genitive
| style="background-color:#fffffc;" | {{{gen_sing_m_st}}}
| style="background-color:#fffffc;" | {{{gen_sing_f_st}}}
| style="background-color:#fffffc;" | {{{gen_sing_n_st}}}
| style="background-color:#fffffc;" | {{{gen_plur_st}}}
|-
! style="background:#eeeeee" | dative
| style="background-color:#fffffc;" | {{{dat_sing_m_st}}}
| style="background-color:#fffffc;" | {{{dat_sing_f_st}}}
| style="background-color:#fffffc;" | {{{dat_sing_n_st}}}
| style="background-color:#fffffc;" | {{{dat_plur_st}}}
|-
! style="background-color:#c6bec0" colspan="7" | weak declension
|-
! style="width: 10%; background:#dbdbdc" colspan="1" | '''case'''
! style="width: 20%; background:#eeeede" colspan="1" | masculine
! style="width: 20%; background:#eeeede" colspan="1" | feminine
! style="width: 20%; background:#eeeede" colspan="1" | neuter
! style="width: 20%; background:#eeeede" colspan="1" | plural
|-
|
|-
! style="background:#eeeeee" | nominative
| style="background-color:#fffffc;" | {{{nom_sing_m_wk}}}
| style="background-color:#fffffc;" | {{{nom_sing_f_wk}}}
| style="background-color:#fffffc;" | {{{nom_sing_n_wk}}}
| style="background-color:#fffffc;" | {{{nom_plur_wk}}}
|-
! style="background:#eeeeee" | accusative
| style="background-color:#fffffc;" | {{{acc_sing_m_wk}}}
| style="background-color:#fffffc;" | {{{acc_sing_f_wk}}}
| style="background-color:#fffffc;" | {{{acc_sing_n_wk}}}
| style="background-color:#fffffc;" | {{{acc_plur_wk}}}
|-
! style="background:#eeeeee" | genitive
| style="background-color:#fffffc;" | {{{gen_sing_m_wk}}}
| style="background-color:#fffffc;" | {{{gen_sing_f_wk}}}
| style="background-color:#fffffc;" | {{{gen_sing_n_wk}}}
| style="background-color:#fffffc;" | {{{gen_plur_wk}}}
|-
! style="background:#eeeeee" | dative
| style="background-color:#fffffc;" | {{{dat_sing_m_wk}}}
| style="background-color:#fffffc;" | {{{dat_sing_f_wk}}}
| style="background-color:#fffffc;" | {{{dat_sing_n_wk}}}
| style="background-color:#fffffc;" | {{{dat_plur_wk}}}
|}</div></div>]=]
return (mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. m_utils.format_categories(data.categories, lang)
end
function make_table_n(data)
local function show_form(form)
if not form then
return "—"
end
local ret = {}
for key, subform in ipairs(form) do
if mw.title.getCurrentTitle().nsText == "Reconstruction" and subform ~= "—" then
subform = "*" .. subform
end
table.insert(ret, m_links.full_link({lang = lang, term = subform}))
end
return table.concat(ret, ", ")
end
local function repl(param)
if param == "decl_type" then
return data.decl_type
else
return show_form(data.forms[param])
end
end
local wikicode = [=[
<div class="NavFrame" style="width: 42em">
<div class="NavHead" style="">Declension of {{{nom_sing_m_wk}}} ({{{decl_type}}})</div>
<div class="NavContent">
{| style="background:#f9f4e9; text-align:center; width:100%" cellpadding="0" cellspacing="1" class="inflection-table"
|-
! style="background-color:#c6bec0" colspan="7" | weak declension
|-
! style="width: 10%; background:#dbdbdc" colspan="1" | '''case'''
! style="width: 20%; background:#eeeede" colspan="1" | masculine
! style="width: 20%; background:#eeeede" colspan="1" | feminine
! style="width: 20%; background:#eeeede" colspan="1" | neuter
! style="width: 20%; background:#eeeede" colspan="1" | plural
|-
|
|-
! style="background:#eeeeee" | nominative
| style="background-color:#fffffc;" | {{{nom_sing_m_wk}}}
| style="background-color:#fffffc;" | {{{nom_sing_f_wk}}}
| style="background-color:#fffffc;" | {{{nom_sing_n_wk}}}
| style="background-color:#fffffc;" | {{{nom_plur_wk}}}
|-
! style="background:#eeeeee" | accusative
| style="background-color:#fffffc;" | {{{acc_sing_m_wk}}}
| style="background-color:#fffffc;" | {{{acc_sing_f_wk}}}
| style="background-color:#fffffc;" | {{{acc_sing_n_wk}}}
| style="background-color:#fffffc;" | {{{acc_plur_wk}}}
|-
!style="background:#eeeeee" | genitive
| style="background-color:#fffffc;" | {{{gen_sing_m_wk}}}
| style="background-color:#fffffc;" | {{{gen_sing_f_wk}}}
| style="background-color:#fffffc;" | {{{gen_sing_n_wk}}}
| style="background-color:#fffffc;" | {{{gen_plur_wk}}}
|-
! style="background:#eeeeee" | dative
| style="background-color:#fffffc;" | {{{dat_sing_m_wk}}}
| style="background-color:#fffffc;" | {{{dat_sing_f_wk}}}
| style="background-color:#fffffc;" | {{{dat_sing_n_wk}}}
| style="background-color:#fffffc;" | {{{dat_plur_wk}}}
|}</div></div>]=]
return (mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. m_utils.format_categories(data.categories, lang)
end
return export