Module:User:Habst/sw-conj

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 = { ['isha'] = true, ['enda'] = true, ['anza'] = true, }

local subj_list = { "1s", "2s", "3s", "1p", "2p", "3p", "3c", "4c", "5c", "6c", "7c", "8c", "9c", "10c", "11c", "15c", "16c", "18c", }

local subjects = { ["p"] = { ["1s"] = {"ni"}, ["2s"] = {"u"}, ["3s"] = {"a"}, ["1p"] = {"tu"}, ["2p"] = {"m"}, ["3p"] = {"wa"}, ["3c"] = {"u"}, ["4c"] = {"i"}, ["5c"] = {"li"}, ["6c"] = {"ya"}, ["7c"] = {"ki"}, ["8c"] = {"vi"}, ["9c"] = {"i"}, ["10c"] = {"zi"}, ["11c"] = {"u"}, ["15c"] = {"ku"}, ["16c"] = {"pa"}, ["18c"] = {"mu"}, },	["n"] = { ["1s"] = {"si"}, ["2s"] = {"hu"}, ["3s"] = {"ha"}, ["1p"] = {"hatu"}, ["2p"] = {"ham"}, ["3p"] = {"hawa"}, ["3c"] = {"hau"}, ["4c"] = {"hai"}, ["5c"] = {"hali"}, ["6c"] = {"haya"}, ["7c"] = {"haki"}, ["8c"] = {"havi"}, ["9c"] = {"hai"}, ["10c"] = {"hazi"}, ["11c"] = {"hau"}, ["15c"] = {"haku"}, ["16c"] = {"hapa"}, ["18c"] = {"hamu"}, },	["cont"] = { ["1s"] = {"n"}, ["2s"] = {"w"}, ["3s"] = {""}, ["1p"] = {"tw"}, ["2p"] = {"mw"}, ["3p"] = {"w"}, ["3c"] = {"w"}, ["4c"] = {"y"}, ["5c"] = {"l"}, ["6c"] = {"y"}, ["7c"] = {"ch"}, ["8c"] = {"vy"}, ["9c"] = {"y"}, ["10c"] = {"z"}, ["11c"] = {"w"}, ["15c"] = {"kw"}, ["16c"] = {"p"}, ["18c"] = {"mw"}, }, } subjects.r = subjects.p

local tam = { ["past"] = { ["p"] = , ["r"] = , ["n"] = , },	["pres"] = { ["p"] = , ["r"] = , ["n"] = , },	["fut"] = { ["p"] = , ["r"] = , ["n"] = , },	["cond_pres"] = { ["p"] = , ["n"] = { {				"singe", alt = subjects.p,				mono = true, },			{				"nge", alt = subjects.n,				mono = true, }		}	},	["cond_past"] = { ["p"] = , ["n"] = { {				"singali", alt = subjects.p,				mono = true, },			{				"ngali", alt = subjects.n,				mono = true, }		}	},	["cond_cont"] = { ["p"] = , },	["perf"] = { ["p"] = , },	["alr"] = { ["p"] = , },	["ifw"] = { ["p"] = , },	["cons"] = { ["p"] = , },	["gnom"] = { ["p"] = , },	["ny"] = { ["n"] = , },	["ifn"] = { ["n"] = , },	["subj"] = { ["p"] = , ["n"] = , },	["rel"] = { ["p"] = , ["n"] = , }, }

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, "^[^aeiou]+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, ' ') 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[lemma] 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[tag] ~= nil then -- user specified forms[tag] = user_specified(args[tag]) else for _, pol_val in ipairs(pols) do						if pol_val.alt and pol_val.alt[subj_name] then subjs = pol_val.alt[subj_name] else subjs = subjects[pol][subj_name] end for _, subj in ipairs(subjs) do							form = {} -- subject marker table.insert(form, subj) -- tam table.insert(form, pol_val[1]) -- 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[tag] = table.concat(temp, " ") 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[1] 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[1] 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[1] 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[1] 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