local m_links = require("Module:links")
local m_utils = require("Module:utilities")
local lang = require("Module:languages").getByCode("sw")
PAGENAME = mw.title.getCurrentTitle().text or ''
local export = {}
local irreg_kw_inf = {
= true,
= true,
= true,
}
local subj_list = {
"1s", "2s", "3s", "1p", "2p", "3p",
"3c", "4c", "5c", "6c", "7c", "8c", "9c", "10c", "11c", "15c", "16c", "18c",
}
local subjects = {
= {
= {"ni"},
= {"u"},
= {"a"},
= {"tu"},
= {"m"},
= {"wa"},
= {"u"},
= {"i"},
= {"li"},
= {"ya"},
= {"ki"},
= {"vi"},
= {"i"},
= {"zi"},
= {"u"},
= {"ku"},
= {"pa"},
= {"mu"},
},
= {
= {"si"},
= {"hu"},
= {"ha"},
= {"hatu"},
= {"ham"},
= {"hawa"},
= {"hau"},
= {"hai"},
= {"hali"},
= {"haya"},
= {"haki"},
= {"havi"},
= {"hai"},
= {"hazi"},
= {"hau"},
= {"haku"},
= {"hapa"},
= {"hamu"},
},
= {
= {"n"},
= {"w"},
= {""},
= {"tw"},
= {"mw"},
= {"w"},
= {"w"},
= {"y"},
= {"l"},
= {"y"},
= {"ch"},
= {"vy"},
= {"y"},
= {"z"},
= {"w"},
= {"kw"},
= {"p"},
= {"mw"},
},
}
subjects.r = subjects.p
local tam = {
= {
= {{
"li",
alt = {
= {"ni", "na"},
= {"u", "wa"},
= {"tu", "twa"},
= {"m", "mwa"}
},
mono = true,
}},
= {{
"lio",
alt = {
= {"ni", "na"},
= {"u", "wa"},
= {"tu", "twa"},
= {"m", "mwa"}
},
mono = true,
}},
= {{"ku"}},
},
= {
= {{
"na",
alt = {
= {"ni", ""}
},
mono = true,
}},
= {{
"nao",
alt = {
= {"ni", ""}
},
mono = true,
}},
= {{
"",
final = "i",
mono = true,
}},
},
= {
= {{
"ta",
mono = true,
}},
= {{
"takao",
mono = true,
}},
= {{
"ta",
mono = true,
}},
},
= {
= {{
"nge",
mono = true,
}},
= {
{
"singe",
alt = subjects.p,
mono = true,
},
{
"nge",
alt = subjects.n,
mono = true,
}
}
},
= {
= {{
"ngali",
mono = true,
}},
= {
{
"singali",
alt = subjects.p,
mono = true,
},
{
"ngali",
alt = subjects.n,
mono = true,
}
}
},
= {
= {{
"ngeli",
mono = true,
}},
},
= {
= {{
"me",
mono = true,
}},
},
= {
= {{
"mesha",
mono = true,
}},
},
= {
= {{"ki"}},
},
= {
= {{"ka"}},
},
= {
= {{
"a",
alt = subjects.cont,
}},
},
= {
= {{"ja"}},
},
= {
= {{
"sipo",
alt = subjects.p,
mono = true,
}},
},
= {
= {{
"",
final = "e"
}},
= {{
"si",
final = "e",
alt = subjects.p,
}},
},
= {
= {{
"",
final = "ao",
}},
= {{
"sio",
alt = subjects.p,
mono = true,
}},
},
}
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
local function get_stem(lemma, args)
if not mw.ustring.match(lemma, "a$") then
-- Arabic verb
return lemma, true, false, {"Swahili verbs in the Arabic conjugation"}
elseif mw.ustring.match(lemma, "^+a$") or args.mono ~= nil then
-- Monosyllabic
return mw.ustring.gsub(lemma, "^(.*)a$", "%1"), false, true, {"Swahili verbs in the monosyllabic conjugation"}
else
-- Normal verbs
return mw.ustring.gsub(lemma, "^(.*)a$", "%1"), false, false, {}
end
end
local function link(term)
return m_links.full_link({lang = lang, term = term, allowSelfLink = false})
end
local function user_specified(text)
if text == '-' then
return '—'
else
local temp = {}
for i, term in ipairs(mw.text.split(text, '/')) do
table.insert(temp, link(term))
end
return table.concat(temp, '<br/>')
end
end
local function make_forms(args, lemma, stem, arabic, monosyllabic)
local tag, temp, form, subjs
local forms = {}
local inf, inf_stem = table.concat{'ku', lemma}, table.concat{'ku', stem}
if args.inf then
forms.inf = user_specified(args.inf)
elseif irreg_kw_inf then
inf, inf_stem = table.concat{'kw', lemma}, table.concat{'kw', stem}
forms.inf = link(inf)
else
forms.inf = link(inf)
end
if args.inf_n then
forms.inf_n = user_specified(args.inf_n)
elseif monosyllabic then
forms.inf_n = link(table.concat{'kuto', inf})
else
forms.inf_n = link(table.concat{'kuto', lemma})
end
if args.hab then
forms.hab = user_specified(args.hab)
else
forms.hab = link(table.concat{'hu', lemma})
end
if args.imp_s then
forms.imp_s = user_specified(args.imp_s)
elseif arabic then
forms.imp_s = link(lemma)
elseif monosyllabic then
forms.imp_s = link(inf)
else
forms.imp_s = link(lemma)
end
if args.imp_p then
forms.imp_p = user_specified(args.imp_p)
elseif arabic then
forms.imp_p = link(table.concat{lemma, 'ni'})
elseif monosyllabic then
forms.imp_p = link(table.concat{inf_stem, 'eni'})
else
forms.imp_p = link(table.concat{stem, 'eni'})
end
forms.title = table.concat{"''-", lemma, "''"}
for tam, tam_val in pairs(tam) do
for pol, pols in pairs(tam_val) do
for _, subj_name in ipairs(subj_list) do
tag = table.concat({tam, pol, subj_name}, '_')
temp = {}
if args ~= nil then -- user specified
forms = user_specified(args)
else
for _, pol_val in ipairs(pols) do
if pol_val.alt and pol_val.alt then
subjs = pol_val.alt
else
subjs = subjects
end
for _, subj in ipairs(subjs) do
form = {}
-- subject marker
table.insert(form, subj)
-- tam
table.insert(form, pol_val)
-- stem
if monosyllabic and pol_val.mono then
table.insert(form, inf_stem)
else
table.insert(form, stem)
end
-- suffix
if arabic then
table.insert(form, "")
elseif pol_val.final then
table.insert(form, pol_val.final)
else
table.insert(form, "a")
end
table.insert(temp, link(table.concat(form)))
end
end
forms = table.concat(temp, "<br/>")
end
end
end
end
return forms
end
function export.show(frame)
if
mw.title.getCurrentTitle().nsText == "Template" and
tablelength(frame:getParent().args) == 0
then
return frame:expandTemplate{title= 'sw-conj/table', args = {}}
end
local args = frame:getParent().args or {}
local lemma = args or PAGENAME
local stem, arabic, monosyllabic, cat = get_stem(lemma, args)
return frame:expandTemplate{
title= 'sw-conj/table',
args = make_forms(args, lemma, stem, arabic, monosyllabic)
} .. m_utils.format_categories(cat, lang)
end
function export.show_pres_prn(frame)
if
mw.title.getCurrentTitle().nsText == "Template" and
tablelength(frame:getParent().args) == 0
then
return frame:expandTemplate{title= 'sw-conj/table-pres-prn', args = {}}
end
local args = frame:getParent().args or {}
local lemma = args or PAGENAME
local stem, arabic, monosyllabic, cat = get_stem(lemma, args)
return frame:expandTemplate{
title= 'sw-conj/table-pres-prn',
args = make_forms(args, lemma, stem, arabic, monosyllabic)
} .. m_utils.format_categories(cat, lang)
end
function export.show_pres_pn(frame)
if
mw.title.getCurrentTitle().nsText == "Template" and
tablelength(frame:getParent().args) == 0
then
return frame:expandTemplate{title= 'sw-conj/table-pres-pn', args = {}}
end
local args = frame:getParent().args or {}
local lemma = args or PAGENAME
local stem, arabic, monosyllabic, cat = get_stem(lemma, args)
return frame:expandTemplate{
title= 'sw-conj/table-pres-pn',
args = make_forms(args, lemma, stem, arabic, monosyllabic)
} .. m_utils.format_categories(cat, lang)
end
function export.show_pres_p(frame)
if
mw.title.getCurrentTitle().nsText == "Template" and
tablelength(frame:getParent().args) == 0
then
return frame:expandTemplate{title= 'sw-conj/table-pres-p', args = {}}
end
local args = frame:getParent().args or {}
local lemma = args or PAGENAME
local stem, arabic, monosyllabic, cat = get_stem(lemma, args)
return frame:expandTemplate{
title= 'sw-conj/table-pres-p',
args = make_forms(args, lemma, stem, arabic, monosyllabic)
} .. m_utils.format_categories(cat, lang)
end
return export