For use in {{sw-conj}}
.
local m_links = require("Module:links")
local m_utils = require("Module:utilities")
local lang = require("Module:languages").getByCode("sw")
local export = {}
local irreg_kw_inf = {
= true,
= true,
= true,
}
local irreg_imp_s = {
= "nenda",
= "njoo",
= "lete",
}
local irreg_imp_p = {
= "nendeni",
= "njooni",
}
local obligatory_obj = {
= true,
= true,
= true,
}
local subjects = {
= {
= "ni",
= "u",
= "a", = "a",
= "tu",
= "m",
= "wa", = "wa",
= "u",
= "i",
= "li",
= "ya",
= "ki",
= "vi",
= "i",
= "zi",
= "u",
= "ku",
= "pa",
= "mu",
},
= {
= "si",
= "hu",
= "ha", = "ha",
= "hatu",
= "ham",
= "hawa", = "hawa",
= "hau",
= "hai",
= "hali",
= "haya",
= "haki",
= "havi",
= "hai",
= "hazi",
= "hau",
= "haku",
= "hapa",
= "hamu",
},
= {
= "n",
= "w",
= "", = "",
= "tw",
= "mw",
= "w", = "w",
= "w",
= "y",
= "l",
= "y",
= "ch",
= "vy",
= "y",
= "z",
= "w",
= "kw",
= "p",
= "mw",
},
}
local objects = {
= "ni",
= "ku",
= "m",
= "m",
= "tu",
= "wa",
= "wa",
= "wa",
= "u",
= "i",
= "li",
= "ya",
= "ki",
= "vi",
= "i",
= "zi",
= "u",
= "ku",
= "pa",
= "mu",
= "ji",
}
local oref = {
= "ye",
= "ye",
= "ye",
= "ye",
= "o",
= "o",
= "o",
= "o",
= "o",
= "yo",
= "lo",
= "yo",
= "cho",
= "vyo",
= "yo",
= "zo",
= "o",
= "ko",
= "po",
= "mo",
}
local ind_tami = {
= "ku",
= "a",
= "ja",
= "ki",
= "ka",
}
local inf_tami = {
= "li",
= "na",
= "ta",
= "ta",
= "nge",
= "singe",
= "ngali",
= "singali",
= "me",
= "mesha",
= "sipo",
}
local subj_tami = {
= "si",
= "ka",
}
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end -- needed?
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, accel_optional)
if accel_optional then
return m_links.full_link({ lang = lang, term = term, allowSelfLink = false, accel = { form = accel_optional } })
else
return m_links.full_link({ lang = lang, term = term, allowSelfLink = false })
end
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 setDefault(t, d)
local mt = { __index = function() return d end }
setmetatable(t, mt)
end
local output_subj_accel = {
= "m-mi|singular",
= "m-mi|plural",
= "ji-ma|singular",
= "ji-ma|plural",
= "ki-vi|singular",
= "ki-vi|plural",
= "n-n|singular",
= "n-n|plural",
= "u-n|singular",
= "ku",
= "pa",
= "mu",
}
setDefault(output_subj_accel, "")
local addition_accel = {
= "m-wa|singular",
= "m-wa|plural",
= "u-n|plural",
= "ku-loc",
}
setDefault(addition_accel, "")
local tampol_accel = {
= "|present",
= "|present|negative",
= "|perfect",
= "|gnomic",
= "|subjunctive",
= "|subjunctive|negative",
= "|past",
= "|past|negative",
= "|future",
= "|future|negative",
= "|consecutive",
= "|conditional",
= "|situational",
}
setDefault(tampol_accel, "")
local function make_accel(subj_name, tam, pol)
output_subj = output_subj_accel
output_subj = output_subj ~= "" and output_subj or subj_name
addition = addition_accel
tampol = tampol_accel
accel_keywords = nil
if tampol ~= "" then
accel_keywords = "verb:|" .. output_subj .. tampol
if addition ~= "" then
accel_keywords = accel_keywords .. "|;|" .. addition .. tampol
end
end
return accel_keywords
end
local function get_subj(args, lemma, arabic)
if args.subj then
return user_specified(args.subj)
elseif arabic then
return lemma
elseif lemma == "wako" or lemma == "wapo" or lemma == "wamo" then
return "we"
elseif lemma == "wa na" then
return "we na"
else
return table.concat { get_stem(lemma, args), 'e' }
end
end -- some
local function get_neg(args, lemma, arabic)
if args.neg then
return user_specified(args.neg)
elseif arabic then
return lemma
else
return table.concat { get_stem(lemma, args), 'i' }
end
end -- somi
local function modfix_before_stem(affix, stem)
if string.match(string.sub(affix, -1), "m") and string.match(string.sub(stem, 1, 1), "") then
affix = affix .. "w"
end
if string.match(string.sub(affix, -1), "m") and string.match(string.sub(stem, 1, 1), "") then
affix = affix .. "u"
end
return affix
end -- subject or object prefix in case it goes right in front of the stem etc.
local function get_inf_stem(lemma, monosyllabic)
if monosyllabic then
return "ku" .. lemma
elseif irreg_kw_inf then
return "kw" .. lemma
else
return lemma
end
end -- soma / kula
local function make_forms(args, lemma, stem, arabic, monosyllabic)
local forms = {}
local loc_suf = ""
local is_loc = false
if lemma == "wa" or lemma == "wako" or lemma == "wapo" or lemma == "wamo" then
args.intr = "yes"
end
if lemma == "wako" or lemma == "wapo" or lemma == "wamo" then
loc_suf = mw.text.truncate(lemma, -2, "")
is_loc = true
end
forms.ip = lemma -- soma
forms.subj = "-" .. link(get_subj(args, lemma, arabic) .. loc_suf) -- -some
if lemma == "wa na" then
forms.subj = "-" .. link("we") .. " na"
end
forms.neg = "-" .. link(get_neg(args, lemma, arabic)) -- -somi
if is_loc then
forms.neg = "-" .. link(loc_suf)
end
if lemma == "wa na" then
forms.neg = "-" .. link("na")
end
for person, infix in pairs(objects) do
term = "-" .. infix .. "-"
actualfix = modfix_before_stem(infix, lemma)
forms = m_links.full_link({ lang = lang, term = term, alt = actualfix, allowSelfLink = false })
end -- -ki- etc.
for person, infix in pairs(objects) do
term = "-" .. infix .. "-"
actualfix = modfix_before_stem(infix, lemma)
eniform = get_subj(args, lemma, arabic) .. "ni"
forms = "-" ..
m_links.full_link({ lang = lang, term = term, alt = actualfix, allowSelfLink = false }) .. lemma
if person == "2p" then
forms.obj_2p_ip = forms.obj_2p_ip ..
"/" ..
"-" ..
m_links.full_link({ lang = lang, term = "-ku-", alt = "ku", allowSelfLink = false }) ..
eniform ..
"/" ..
"-" .. m_links.full_link({ lang = lang, term = term, alt = actualfix, allowSelfLink = false }) .. eniform
end
end -- -kisoma etc.
if lemma == "wa na" then
for person, suffix in pairs(oref) do
local na_obj = "na" .. suffix
forms = link(na_obj)
end
forms.obj_1s_ip = link("nami") .. "/na " .. link("mimi")
forms.obj_2s_ip = link("nawe") .. "/na " .. link("wewe")
forms.obj_3s_ip = link("naye") .. "/na " .. link("yeye")
forms.obj_1p_ip = link("nasi") .. "/na " .. link("sisi")
forms.obj_2p_ip = link("nanyi") .. "/na " .. link("ninyi")
forms.obj_3p_ip = link("nao") .. "/na " .. link("wao")
end
for person, infix in pairs(objects) do
term = "-" .. infix .. "-"
actualfix = modfix_before_stem(infix, lemma)
forms = "-" ..
m_links.full_link({ lang = lang, term = term, alt = actualfix, allowSelfLink = false }) ..
get_subj(args, lemma, arabic)
end -- -kisome etc.
for person, infix in pairs(objects) do
term = "-" .. infix .. "-"
actualfix = modfix_before_stem(infix, lemma)
forms = "-" ..
m_links.full_link({ lang = lang, term = term, alt = actualfix, allowSelfLink = false }) ..
get_neg(args, lemma, arabic)
end -- -kisomi etc.
if lemma == "wa" or lemma == "wako" or lemma == "wapo" or lemma == "wamo" or lemma == "wa na" then
oref_gen_stem = "li"
else
oref_gen_stem = lemma
end
if lemma == "wa na" then
for class, suffix in pairs(oref) do
term = "-" .. suffix
forms = "-" ..
oref_gen_stem ..
m_links.full_link({ lang = lang, term = term, alt = suffix, allowSelfLink = false }) .. " na"
end
else
for class, suffix in pairs(oref) do
term = "-" .. suffix
forms = "-" ..
oref_gen_stem ..
m_links.full_link({ lang = lang, term = term, alt = suffix, allowSelfLink = false }) .. loc_suf
end -- -soma] etc.
end
if lemma == "wa" or lemma == "wako" or lemma == "wapo" or lemma == "wamo" then
for person, prefix in pairs(subjects.p) do
suffix = oref
sufterm = "-" .. suffix
forms = "-" ..
"si" .. m_links.full_link({ lang = lang, term = sufterm, alt = suffix, allowSelfLink = false }) ..
loc_suf
end -- si] etc.
end
if lemma == "wa na" then
for person, prefix in pairs(subjects.p) do
suffix = oref
sufterm = "-" .. suffix
forms = "-" ..
"si" .. m_links.full_link({ lang = lang, term = sufterm, alt = suffix, allowSelfLink = false }) ..
" na"
end
end
if is_loc then
forms.oref_other_stem = get_inf_stem(lemma, true) .. "/-kuwa"
else
forms.oref_other_stem = get_inf_stem(lemma, monosyllabic)
end
for class, infix in pairs(oref) do
term = "-" .. infix .. "-"
if is_loc then
forms = "-" ..
m_links.full_link({ lang = lang, term = term, alt = infix, allowSelfLink = false }) ..
get_inf_stem(lemma, true) ..
"/-" .. m_links.full_link({ lang = lang, term = term, alt = infix, allowSelfLink = false }) .. "kuwa"
else
forms = "-" ..
m_links.full_link({ lang = lang, term = term, alt = infix, allowSelfLink = false }) ..
get_inf_stem(lemma, monosyllabic)
end
end -- -]soma etc.
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)
elseif lemma == "wa na" then
forms.inf = link("kuwa") .. " na"
else
forms.inf = link(inf)
end -- kusoma
if args.inf_n then
forms.inf_n = user_specified(args.inf_n)
elseif monosyllabic or irreg_kw_inf then
forms.inf_n = link(table.concat { 'kuto', inf })
elseif lemma == "wa na" then
forms.inf_n = link(kutokuwa) .. " na"
else
forms.inf_n = link(table.concat { 'kuto', lemma })
end -- kutosoma
if args.hab then
forms.hab = user_specified(args.hab)
elseif is_loc then
forms.hab = link("hu" .. lemma) .. "/" .. link("huwa")
elseif lemma == "wa na" then
forms.hab = link("huwa") .. " na"
else
forms.hab = link(table.concat { 'hu', lemma })
end -- husoma
if args.imp_s then
forms.imp_s = user_specified(args.imp_s)
elseif lemma == "wa na" then
forms.imp_s = link("kuwa") .. " na"
elseif irreg_imp_s ~= nil then
forms.imp_s = link(irreg_imp_s)
elseif arabic then
forms.imp_s = link(lemma)
elseif monosyllabic or irreg_kw_inf then
forms.imp_s = link(inf)
else
forms.imp_s = link(lemma)
end -- soma
if args.imp_p then
forms.imp_p = user_specified(args.imp_p)
elseif lemma == "wa na" then
forms.imp_p = link("kuweni") .. " na"
elseif irreg_imp_p ~= nil then
forms.imp_p = link(irreg_imp_p)
elseif arabic then
forms.imp_p = link(table.concat { lemma, 'ni' })
elseif monosyllabic or irreg_kw_inf then
forms.imp_p = link(table.concat { inf_stem, 'eni' })
else
forms.imp_p = link(table.concat { stem, 'eni' })
end -- someni
forms.title = table.concat { "''-", lemma, "''" } -- ''-soma''
if is_loc then
forms.tele = link("ka" .. lemma) .. "/" .. link("kawa")
elseif lemma == "wa na" then
forms.tele = link("kawa") .. " na"
else
forms.tele = link(table.concat { 'ka', lemma }) -- kasoma
end
for tam, infix in pairs(ind_tami) do
term = "-" .. infix .. "-"
if is_loc then
forms = "-" ..
m_links.full_link({ lang = lang, term = term, alt = infix, allowSelfLink = false }) ..
lemma ..
"/-" .. m_links.full_link({ lang = lang, term = term, alt = infix, allowSelfLink = false }) .. "wa"
else
forms = "-" ..
m_links.full_link({ lang = lang, term = term, alt = infix, allowSelfLink = false }) .. lemma
end
end -- -]soma etc.
for tam, infix in pairs(inf_tami) do
term = "-" .. infix .. "-"
if is_loc then
forms = "-" ..
m_links.full_link({ lang = lang, term = term, alt = infix, allowSelfLink = false }) ..
get_inf_stem(lemma, true) ..
"/-" .. m_links.full_link({ lang = lang, term = term, alt = infix, allowSelfLink = false }) .. "kuwa"
else
forms = "-" ..
m_links.full_link({ lang = lang, term = term, alt = infix, allowSelfLink = false }) ..
get_inf_stem(lemma, monosyllabic)
end
end -- -]soma etc.
if is_loc then
forms.pres_p = "-" .. link(loc_suf)
end
if lemma == "wa na" then
forms.pres_p = "-" .. link("na")
end
for tam, infix in pairs(subj_tami) do
term = "-" .. infix .. "-"
forms = "-" ..
m_links.full_link({ lang = lang, term = term, alt = infix, allowSelfLink = false }) ..
get_subj(args, lemma, arabic) .. loc_suf
end -- -]some etc.
if is_loc then
for person, prefix in pairs(subjects.p) do
if prefix == "a" then prefix = "yu" end
term = prefix .. "-"
forms = m_links.full_link({
lang = lang,
term = term,
alt = prefix,
allowSelfLink = false
}) .. loc_suf
end
elseif lemma == "wa na" then
for person, prefix in pairs(subjects.p) do
term = prefix .. "na"
forms = link(term)
end
else
for person, prefix in pairs(subjects.p) do
term = prefix .. "-"
forms = m_links.full_link({
lang = lang,
term = term,
alt = prefix,
allowSelfLink = false
}) .. "na" .. get_inf_stem(lemma, monosyllabic)
if person == "1s" then
forms = forms ..
"/" ..
m_links.full_link({ lang = lang, term = "na-", alt = "na", allowSelfLink = false }) ..
get_inf_stem(lemma, monosyllabic)
end
end
end -- ]nasoma etc.
if is_loc then
for person, prefix in pairs(subjects.n) do
if prefix == "ha" then prefix = "hayu" end
term = prefix .. "-"
forms = m_links.full_link({
lang = lang,
term = term,
alt = prefix,
allowSelfLink = false
}) .. loc_suf
end
elseif lemma == "wa na" then
for person, prefix in pairs(subjects.n) do
term = prefix .. "na"
forms = link(term)
end
else
for person, prefix in pairs(subjects.n) do
term = prefix .. "-"
actualprefix = modfix_before_stem(prefix, lemma)
forms = m_links.full_link({
lang = lang,
term = term,
alt = actualprefix,
allowSelfLink = false
}) .. get_neg(args, lemma, arabic)
end -- ]somi etc.
end
for person, prefix in pairs(subjects.p) do
term = prefix .. "-"
actualprefix = modfix_before_stem(prefix, lemma)
forms = m_links.full_link({
lang = lang,
term = term,
alt = actualprefix,
allowSelfLink = false
}) .. get_subj(args, lemma, arabic) .. loc_suf
end -- ]some etc.
if lemma == "enda" then
forms = m_links.full_link({ lang = lang, term = "tu-", alt = "tw", allowSelfLink = false }) ..
"ende/" .. forms
end
for person, sprefix in pairs(subjects.cont) do
actualprefix = sprefix .. "a"
term = sprefix .. "a-"
forms = m_links.full_link({
lang = lang,
term = term,
alt = actualprefix,
allowSelfLink = false
}) .. lemma
end -- ]soma etc.
return forms
end
function export.show(frame)
if
mw.title.getCurrentTitle().nsText == "Template" and
tablelength(frame:getParent().args) == 0
then
return frame:expandTemplate { title = 'Template:sw-conj/table-trans', args = {} }
end
local args = frame:getParent().args or {}
local lemma = args or mw.title.getCurrentTitle().text or ''
local stem, arabic, monosyllabic, cat = get_stem(lemma, args)
if obligatory_obj then
return frame:expandTemplate {
title = 'Template:sw-conj/table-oblobj',
args = make_forms(args, lemma, stem, arabic, monosyllabic)
} .. m_utils.format_categories(cat, lang)
elseif lemma == "wa" then
return frame:expandTemplate {
title = 'Template:sw-conj/table-wa',
args = make_forms(args, lemma, stem, false, true)
} .. m_utils.format_categories(cat, lang)
elseif lemma == "wa na" then
return frame:expandTemplate {
title = 'Template:sw-conj/table-wa-na',
args = make_forms(args, lemma, "wa", false, true)
} .. m_utils.format_categories(cat, lang)
elseif lemma == "wako" or lemma == "wapo" or lemma == "wamo" then
return frame:expandTemplate {
title = 'Template:sw-conj/table-loc',
args = make_forms(args, lemma, "wa", false, true)
} .. m_utils.format_categories(cat, lang)
elseif args then
return frame:expandTemplate {
title = 'Template:sw-conj/table-intrans',
args = make_forms(args, lemma, stem, arabic, monosyllabic)
} .. m_utils.format_categories(cat, lang)
else
return frame:expandTemplate {
title = 'Template:sw-conj/table-trans',
args = make_forms(args, lemma, stem, arabic, monosyllabic)
} .. m_utils.format_categories(cat, lang)
end
end
return export