local nom = require("Module:User:iwsfutcmd/gez-nominal")
local m_strutils = require("Module:string utilities")
local m_links = require("Module:links")
local lang = require("Module:languages").getByCode("gez")
local export = {}
local pronouns = {"1s", "2ms", "2fs", "3ms", "3fs", "1p", "2mp", "2fp", "3mp", "3fp"}
local numbers = {
= "singular",
= "plural"
}
local function infer_forms(forms)
for _, section in pairs(forms) do
local genders = (section and section) and {"m_", "f_"} or {""}
for _, gender in ipairs(genders) do
local is_plural = false
if section == "p" then
is_plural = true
end
if not section then
section = nom.accusative_form(section)
end
if not section then
section = nom.construct_form(section)
end
if not section then
section = nom.accusative_form(section)
end
local suf_base = section
if section then
suf_base = section
end
local acc_suf_base = suf_base
if section then
acc_suf_base = section
end
for _, pronoun in ipairs(pronouns) do
section = nom.with_pronominal_suffix(suf_base, pronoun, is_plural)
section = nom.with_pronominal_suffix(acc_suf_base, pronoun, is_plural, true)
end
end
end
end
local table_top = [===[<div><div class="NavFrame" style="display:inline-block;min-width:30em">
<div class="NavHead" align="left" style="min-width:30em">{title}</div>
<div class="NavContent" align="center" style="min-width:30em">
{| class="wikitable inflection-table" style="text-align:center;margin:0"
|-
! rowspan="2" | Number
! rowspan="2" colspan="2" | State
! colspan="2" | Case
|-
! nominative/genitive
! accusative
]===]
local table_top_gender = [===[<div><div class="NavFrame" style="display:inline-block;min-width:30em">
<div class="NavHead" align="left" style="min-width:30em">{title}</div>
<div class="NavContent" align="center" style="min-width:30em">
{| class="wikitable inflection-table" style="text-align:center;margin:0"
|-
! rowspan="4" | Number
! rowspan="4" colspan="2" | State
! colspan="4" | Gender
|-
! colspan="2" | masculine
! colspan="2" | feminine
|-
! colspan="2" | Case
! colspan="2" | Case
|-
! nominative/genitive
! accusative
! nominative/genitive
! accusative
]===]
local table_section_start = [===[|- style="border-block-start: 2px black solid;"
! rowspan="12" | {number}
! colspan="2" | absolute
| {abs}
|-
! colspan="2" | construct
| {con}
|-
! rowspan="10" style="writing-mode: vertical-rl" | With possessive pronouns
]===]
local table_section_start_gender = [===[|- style="border-block-start: 2px black solid;"
! rowspan="12" | {number}
! colspan="2" | absolute
| {m_abs}
| {f_abs}
|-
! colspan="2" | construct
| {m_con}
| {f_con}
|-
! rowspan="10" style="writing-mode: vertical-rl" | With possessive pronouns
]===]
local table_section_row = [===[! {header}
| {cell}
]===]
local table_section_row_gender = [===[! {header}
| {m_cell}
| {f_cell}
]===]
local table_bottom = [===[|}
</div></div></div>]===]
local table_cell_merged = ===]
local table_cell_separated = [===[{form_n}
| {form_a} ]===]
local function make_link(x)
if x == "-" then
return "—" -- m-dash
else
return m_links.full_link({
lang = lang,
term = x,
allow_self_link = false
})
end
end
local function make_cell(nom, acc)
if nom == acc then
return m_strutils.format(table_cell_merged, {
= nom
})
else
return m_strutils.format(table_cell_separated, {
= nom,
= acc
})
end
end
local function make_table(forms)
local gendered = forms and forms
local title = ""
if gendered then
title = "Declension of " .. make_link(forms) .. " / " .. make_link(forms)
else
title = "Declension of " .. make_link(forms)
end
local output = {}
table.insert(output, m_strutils.format(gendered and table_top_gender or table_top, {
= title
}))
for _, section in ipairs(forms) do
if gendered then
local section_start = {
= numbers],
= make_cell(make_link(section or "-"), make_link(section or "-")),
= make_cell(make_link(section or "-"), make_link(section or "-")),
= make_cell(make_link(section or "-"), make_link(section or "-")),
= make_cell(make_link(section or "-"), make_link(section or "-"))
}
table.insert(output, m_strutils.format(table_section_start_gender, section_start))
else
local section_start = {
= numbers],
= make_cell(make_link(section or "-"), make_link(section or "-")),
= make_cell(make_link(section or "-"), make_link(section or "-"))
}
table.insert(output, m_strutils.format(table_section_start, section_start))
end
local rows = {}
for _, pronoun in ipairs(pronouns) do
local row_data = {
= pronoun
}
for _, gender in ipairs(gendered and {"m_", "f_"} or {""}) do
local nom
local form_name = gender .. "n_" .. pronoun
if type(section) == "table" then
local links = {}
for _, form in ipairs(section) do
table.insert(links, make_link(form or "-"))
end
nom = table.concat(links, "; ")
else
nom = make_link(section or "-")
end
local acc
form_name = gender .. "a_" .. pronoun
if type(section) == "table" then
local links = {}
for _, form in ipairs(section) do
table.insert(links, make_link(form or "-"))
end
acc = table.concat(links, "; ")
else
acc = make_link(section or "-")
end
row_data = make_cell(nom, acc)
end
table.insert(rows, m_strutils.format(gendered and table_section_row_gender or table_section_row, row_data))
end
table.insert(output, table.concat(rows, "\n|-\n"))
end
table.insert(output, m_strutils.format(table_bottom, {}))
return table.concat(output)
end
local function process_args(args)
for key, val in pairs(args) do
val = mw.text.trim(val)
if val == "" then
val = nil
end
args = val
end
local forms = {}
local section = {
= "s"
}
local gendered = args and args
local genders = gendered and {"m_", "f_"} or {""}
for _, gender in ipairs(genders) do
local base_form = gendered and args or args
section = base_form
if args then
section = args
end
if args then
section = args
end
end
table.insert(forms, section)
for i = 1, 9 do
local section = {
= "p"
}
local plural_found = false
local n = (i == 1) and "" or tostring(i)
for _, gender in ipairs(genders) do
if args then
plural_found = true
local form
local base_form = gendered and args or args
if args == "smp" then
form = nom.external_plural(base_form, "m")
elseif args == "sfp" then
form = nom.external_plural(base_form, "f")
else
form = args
end
section = form
if args then
section = args
end
if args then
section = args
end
end
end
if plural_found then
table.insert(forms, section)
end
end
return forms
end
function export.show(frame)
local args = frame:getParent().args
PAGENAME = mw.title.getCurrentTitle().text
NAMESPACE = mw.title.getCurrentTitle().nsText
local forms = nil
forms = process_args(args)
infer_forms(forms)
return make_table(forms)
end
return export