[go: nahoru, domu]

Module:zu-verbs

Archived revision by Rua (talk | contribs) as of 01:57, 11 December 2016.

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local m_utilities = require("Module:utilities")
local m_links = require("Module:links")
local m_common = require("Module:zu-common")

local lang = require("Module:languages").getByCode("zu")

local export = {}


function export.verb(frame)
	local params = {
		[1] = {},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {forms = {}, info = "", categories = {}}
	
	if args[1] == "L" or args[1] == "H" then
		data.info = "tone class " .. args[1]
		table.insert(data.categories, lang:getCanonicalName() .. " verbs with tone class " .. args[1])
	elseif args[1] then
		error("The tone class must be \"L\" or \"H\".")
	else
		table.insert(data.categories, lang:getCanonicalName() .. " verbs needing tone class")
	end
	
	local base = mw.ustring.gsub(mw.title.getCurrentTitle().subpageText, "a$", "")
	
	local syllables = m_common.split_syllables(mw.title.getCurrentTitle().subpageText)
	
	local a = "a"
	local e = "e"
	local i = "i"
	local u = "u"
	local u2 = "u"
	
	local yi = ""
	local ku = ""
	
	if mw.ustring.find(syllables[1], "^[aeiou]") then
		local vowel = syllables[1]
		table.remove(syllables, 1)
		base = mw.ustring.gsub(base, "^[aeiou]", "")
		
		if vowel == "a" or vowel == "e" or vowel == "o" then
			a = vowel
			e = vowel
			i = vowel
			u = vowel
			u2 = "w" .. vowel
		end
		
		ku = "k" .. u2
		yi = "y" .. i
	elseif #syllables == 1 then
		ku = "k" .. u2
		yi = "y" .. i
	end
	
	-- Infinitive
	data.forms["inf"] = {"uk" .. u2 .. base .. "a"}
	
	-- Imperative
	data.forms["impr_sg"]     = {yi .. base .. "a"}
	data.forms["impr_pl"]     = {yi .. base .. "ani"}
	data.forms["impr_obj_sg"] = {yi .. base .. "e"}
	data.forms["impr_obj_pl"] = {yi .. base .. "eni"}
	
	-- Present tense
	data.forms["pres_1sg"] = {"ngiy" .. a .. base .. "a", "ng" .. i  .. base .. "a"}
	data.forms["pres_2sg"] = {  "uy" .. a .. base .. "a",         u2 .. base .. "a"}
	data.forms["pres_1pl"] = { "siy" .. a .. base .. "a",  "s" .. i  .. base .. "a"}
	data.forms["pres_2pl"] = { "niy" .. a .. base .. "a",  "n" .. i  .. base .. "a"}
	data.forms["pres_c1"]  = {  "uy" .. a .. base .. "a",         u2 .. base .. "a"}
	data.forms["pres_c2"]  = { "bay" .. a .. base .. "a",  "b" .. a  .. base .. "a"}
	data.forms["pres_c3"]  = {  "uy" .. a .. base .. "a",         u2 .. base .. "a"}
	data.forms["pres_c4"]  = {  "iy" .. a .. base .. "a",         i  .. base .. "a"}
	data.forms["pres_c5"]  = { "liy" .. a .. base .. "a",  "l" .. i  .. base .. "a"}
	data.forms["pres_c6"]  = {  "ay" .. a .. base .. "a",         a  .. base .. "a"}
	data.forms["pres_c7"]  = { "siy" .. a .. base .. "a",  "s" .. i  .. base .. "a"}
	data.forms["pres_c8"]  = { "ziy" .. a .. base .. "a",  "i" .. i  .. base .. "a"}
	data.forms["pres_c9"]  = {  "iy" .. a .. base .. "a",         i  .. base .. "a"}
	data.forms["pres_c10"] = { "ziy" .. a .. base .. "a",  "z" .. i  .. base .. "a"}
	data.forms["pres_c11"] = { "luy" .. a .. base .. "a",  "l" .. u  .. base .. "a"}
	data.forms["pres_c14"] = { "buy" .. a .. base .. "a",  "b" .. u  .. base .. "a"}
	data.forms["pres_c15"] = { "kuy" .. a .. base .. "a",  "k" .. u2 .. base .. "a"}
	data.forms["pres_c17"] = { "kuy" .. a .. base .. "a",  "k" .. u2 .. base .. "a"}
	
	data.forms["part_1sg"] = {"ng" .. i  .. base .. "a"}
	data.forms["part_2sg"] = {        u2 .. base .. "a"}
	data.forms["part_1pl"] = { "s" .. i  .. base .. "a"}
	data.forms["part_2pl"] = { "n" .. i  .. base .. "a"}
	data.forms["part_c1"]  = {        e  .. base .. "a"}
	data.forms["part_c2"]  = { "b" .. e  .. base .. "a"}
	data.forms["part_c3"]  = {        u2 .. base .. "a"}
	data.forms["part_c4"]  = {        i  .. base .. "a"}
	data.forms["part_c5"]  = { "l" .. i  .. base .. "a"}
	data.forms["part_c6"]  = {        e  .. base .. "a"}
	data.forms["part_c7"]  = { "s" .. i  .. base .. "a"}
	data.forms["part_c8"]  = { "i" .. i  .. base .. "a"}
	data.forms["part_c9"]  = {        i  .. base .. "a"}
	data.forms["part_c10"] = { "z" .. i  .. base .. "a"}
	data.forms["part_c11"] = { "l" .. u  .. base .. "a"}
	data.forms["part_c14"] = { "b" .. u  .. base .. "a"}
	data.forms["part_c15"] = { "k" .. u2 .. base .. "a"}
	data.forms["part_c17"] = { "k" .. u2 .. base .. "a"}
	
	data.forms["subj_1sg"] = {"ng" .. i  .. base .. "e"}
	data.forms["subj_2sg"] = {        u2 .. base .. "e"}
	data.forms["subj_1pl"] = { "s" .. i  .. base .. "e"}
	data.forms["subj_2pl"] = { "n" .. i  .. base .. "e"}
	data.forms["subj_c1"]  = {        a  .. base .. "e"}
	data.forms["subj_c2"]  = { "b" .. a  .. base .. "e"}
	data.forms["subj_c3"]  = {        u2 .. base .. "e"}
	data.forms["subj_c4"]  = {        i  .. base .. "e"}
	data.forms["subj_c5"]  = { "l" .. i  .. base .. "e"}
	data.forms["subj_c6"]  = {        a  .. base .. "e"}
	data.forms["subj_c7"]  = { "s" .. i  .. base .. "e"}
	data.forms["subj_c8"]  = { "i" .. i  .. base .. "e"}
	data.forms["subj_c9"]  = {        i  .. base .. "e"}
	data.forms["subj_c10"] = { "z" .. i  .. base .. "e"}
	data.forms["subj_c11"] = { "l" .. u2 .. base .. "e"}
	data.forms["subj_c14"] = { "b" .. u  .. base .. "e"}
	data.forms["subj_c15"] = { "k" .. u2 .. base .. "e"}
	data.forms["subj_c17"] = { "k" .. u2 .. base .. "e"}
	
	-- Recent past tense
	if #syllables > 2 and mw.ustring.find(base, "[ae][lmns]$") then
		local base2 = mw.ustring.gsub(base, "a([^aeiou]+)$", "e%1")
		
		data.forms["recp_1sg"] = {"ng" .. i  .. base2 .. "e"}
		data.forms["recp_2sg"] = {        u2 .. base2 .. "e"}
		data.forms["recp_1pl"] = { "s" .. i  .. base2 .. "e"}
		data.forms["recp_2pl"] = { "n" .. i  .. base2 .. "e"}
		data.forms["recp_c1"]  = {        u2 .. base2 .. "e"}
		data.forms["recp_c2"]  = { "b" .. a  .. base2 .. "e"}
		data.forms["recp_c3"]  = {        u2 .. base2 .. "e"}
		data.forms["recp_c4"]  = {        i  .. base2 .. "e"}
		data.forms["recp_c5"]  = { "l" .. i  .. base2 .. "e"}
		data.forms["recp_c6"]  = {        a  .. base2 .. "e"}
		data.forms["recp_c7"]  = { "s" .. i  .. base2 .. "e"}
		data.forms["recp_c8"]  = { "i" .. i  .. base2 .. "e"}
		data.forms["recp_c9"]  = {        i  .. base2 .. "e"}
		data.forms["recp_c10"] = { "z" .. i  .. base2 .. "e"}
		data.forms["recp_c11"] = { "l" .. u2 .. base2 .. "e"}
		data.forms["recp_c14"] = { "b" .. u  .. base2 .. "e"}
		data.forms["recp_c15"] = { "k" .. u2 .. base2 .. "e"}
		data.forms["recp_c17"] = { "k" .. u2 .. base2 .. "e"}
	else
		data.forms["recp_1sg"] = {"ng" .. i  .. base .. "ile", "ng" .. i  .. base .. "e"}
		data.forms["recp_2sg"] = {        u2 .. base .. "ile",         u2 .. base .. "e"}
		data.forms["recp_1pl"] = { "s" .. i  .. base .. "ile",  "s" .. i  .. base .. "e"}
		data.forms["recp_2pl"] = { "n" .. i  .. base .. "ile",  "n" .. i  .. base .. "e"}
		data.forms["recp_c1"]  = {        u2 .. base .. "ile",         u2 .. base .. "e"}
		data.forms["recp_c2"]  = { "b" .. a  .. base .. "ile",  "b" .. a  .. base .. "e"}
		data.forms["recp_c3"]  = {        u2 .. base .. "ile",         u2 .. base .. "e"}
		data.forms["recp_c4"]  = {        i  .. base .. "ile",         i  .. base .. "e"}
		data.forms["recp_c5"]  = { "l" .. i  .. base .. "ile",  "l" .. i  .. base .. "e"}
		data.forms["recp_c6"]  = {        a  .. base .. "ile",         a  .. base .. "e"}
		data.forms["recp_c7"]  = { "s" .. i  .. base .. "ile",  "s" .. i  .. base .. "e"}
		data.forms["recp_c8"]  = { "i" .. i  .. base .. "ile",  "i" .. i  .. base .. "e"}
		data.forms["recp_c9"]  = {        i  .. base .. "ile",         i  .. base .. "e"}
		data.forms["recp_c10"] = { "z" .. i  .. base .. "ile",  "z" .. i  .. base .. "e"}
		data.forms["recp_c11"] = { "l" .. u2 .. base .. "ile",  "l" .. u2 .. base .. "e"}
		data.forms["recp_c14"] = { "b" .. u  .. base .. "ile",  "b" .. u  .. base .. "e"}
		data.forms["recp_c15"] = { "k" .. u2 .. base .. "ile",  "k" .. u2 .. base .. "e"}
		data.forms["recp_c17"] = { "k" .. u2 .. base .. "ile",  "k" .. u2 .. base .. "e"}
	end
	
	data.forms["recp_cont_1sg"] = {"beng" .. i  .. base .. "a"}
	data.forms["recp_cont_2sg"] = {  "ub" .. e  .. base .. "a"}
	data.forms["recp_cont_1pl"] = { "sib" .. e  .. base .. "a"}
	data.forms["recp_cont_2pl"] = { "nib" .. e  .. base .. "a"}
	data.forms["recp_cont_c1"]  = {  "ub" .. e  .. base .. "a"}
	data.forms["recp_cont_c2"]  = { "beb" .. e  .. base .. "a"}
	data.forms["recp_cont_c3"]  = { "bew" .. u  .. base .. "a"}
	data.forms["recp_cont_c4"]  = { "bey" .. i  .. base .. "a"}
	data.forms["recp_cont_c5"]  = { "bel" .. i  .. base .. "a"}
	data.forms["recp_cont_c6"]  = {  "ab" .. e  .. base .. "a"}
	data.forms["recp_cont_c7"]  = { "bes" .. i  .. base .. "a"}
	data.forms["recp_cont_c8"]  = { "bez" .. i  .. base .. "a"}
	data.forms["recp_cont_c9"]  = { "bey" .. i  .. base .. "a"}
	data.forms["recp_cont_c10"] = { "bez" .. i  .. base .. "a"}
	data.forms["recp_cont_c11"] = { "bel" .. u2 .. base .. "a"}
	data.forms["recp_cont_c14"] = { "beb" .. u  .. base .. "a"}
	data.forms["recp_cont_c15"] = { "bek" .. u2 .. base .. "a"}
	data.forms["recp_cont_c17"] = { "bek" .. u2 .. base .. "a"}
	
	-- Remote past tense
	data.forms["remp_1sg"] = {"ng" .. a .. base .. "a"}
	data.forms["remp_2sg"] = { "w" .. a .. base .. "a"}
	data.forms["remp_1pl"] = { "s" .. a .. base .. "a"}
	data.forms["remp_2pl"] = { "n" .. a .. base .. "a"}
	data.forms["remp_c1"]  = { "w" .. a .. base .. "a"}
	data.forms["remp_c2"]  = { "b" .. a .. base .. "a"}
	data.forms["remp_c3"]  = { "w" .. a .. base .. "a"}
	data.forms["remp_c4"]  = { "y" .. a .. base .. "a"}
	data.forms["remp_c5"]  = { "l" .. a .. base .. "a"}
	data.forms["remp_c6"]  = {        a .. base .. "a"}
	data.forms["remp_c7"]  = { "s" .. a .. base .. "a"}
	data.forms["remp_c8"]  = { "z" .. a .. base .. "a"}
	data.forms["remp_c9"]  = { "y" .. a .. base .. "a"}
	data.forms["remp_c10"] = { "z" .. a .. base .. "a"}
	data.forms["remp_c11"] = {"lw" .. a .. base .. "a"}
	data.forms["remp_c14"] = { "b" .. a .. base .. "a"}
	data.forms["remp_c15"] = {"kw" .. a .. base .. "a"}
	data.forms["remp_c17"] = {"kw" .. a .. base .. "a"}
	
	data.forms["remp_cont_1sg"] = {"ngang" .. i  .. base .. "a"}
	data.forms["remp_cont_2sg"] = {  "waw" .. u  .. base .. "a"}
	data.forms["remp_cont_1pl"] = {  "sas" .. i  .. base .. "a"}
	data.forms["remp_cont_2pl"] = {  "nan" .. i  .. base .. "a"}
	data.forms["remp_cont_c1"]  = {  "way" .. e  .. base .. "a"}
	data.forms["remp_cont_c2"]  = {  "bab" .. e  .. base .. "a"}
	data.forms["remp_cont_c3"]  = {  "waw" .. u  .. base .. "a"}
	data.forms["remp_cont_c4"]  = {  "yay" .. i  .. base .. "a"}
	data.forms["remp_cont_c5"]  = {  "lal" .. i  .. base .. "a"}
	data.forms["remp_cont_c6"]  = {   "ay" .. e  .. base .. "a"}
	data.forms["remp_cont_c7"]  = {  "sas" .. i  .. base .. "a"}
	data.forms["remp_cont_c8"]  = {  "zaz" .. i  .. base .. "a"}
	data.forms["remp_cont_c9"]  = {  "yay" .. i  .. base .. "a"}
	data.forms["remp_cont_c10"] = {  "zaz" .. i  .. base .. "a"}
	data.forms["remp_cont_c11"] = { "lwal" .. u2 .. base .. "a"}
	data.forms["remp_cont_c14"] = {  "bab" .. u  .. base .. "a"}
	data.forms["remp_cont_c15"] = { "kwak" .. u2 .. base .. "a"}
	data.forms["remp_cont_c17"] = { "kwak" .. u2 .. base .. "a"}
	
	-- Future tense
	data.forms["futr_1sg"] = {"ngizo" .. ku .. base .. "a"}
	data.forms["futr_2sg"] = {  "uzo" .. ku .. base .. "a"}
	data.forms["futr_1pl"] = { "sizo" .. ku .. base .. "a"}
	data.forms["futr_2pl"] = { "nizo" .. ku .. base .. "a"}
	data.forms["futr_c1"]  = {  "uzo" .. ku .. base .. "a"}
	data.forms["futr_c2"]  = { "bazo" .. ku .. base .. "a"}
	data.forms["futr_c3"]  = {  "uzo" .. ku .. base .. "a"}
	data.forms["futr_c4"]  = {  "izo" .. ku .. base .. "a"}
	data.forms["futr_c5"]  = { "lizo" .. ku .. base .. "a"}
	data.forms["futr_c6"]  = {  "azo" .. ku .. base .. "a"}
	data.forms["futr_c7"]  = { "sizo" .. ku .. base .. "a"}
	data.forms["futr_c8"]  = { "zizo" .. ku .. base .. "a"}
	data.forms["futr_c9"]  = {  "izo" .. ku .. base .. "a"}
	data.forms["futr_c10"] = { "zizo" .. ku .. base .. "a"}
	data.forms["futr_c11"] = { "luzo" .. ku .. base .. "a"}
	data.forms["futr_c14"] = { "buzo" .. ku .. base .. "a"}
	data.forms["futr_c15"] = { "kuzo" .. ku .. base .. "a"}
	data.forms["futr_c17"] = { "kuzo" .. ku .. base .. "a"}
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


-- Make the table
function make_table(data)
	local function repl(param)
		if param == "info" then
			return mw.getContentLanguage():ucfirst(data.info or "")
		end
		
		local form = data.forms[param]
		
		if not form or #form == 0 then
			return "—"
		end
		
		local ret = {}
		
		for key, subform in ipairs(form) do
			table.insert(ret, m_links.full_link({lang = lang, term = subform}))
		end
		
		return table.concat(ret, ", ")
	end
	
	local names = {
		["impr"] = "imperative",
		["impr_obj"] = "imperative<br/>+ object prefix",
		
		["pres"] = "present",
		["part"] = "participial",
		["subj"] = "subjunctive",
		
		["recp"] = "recent past",
		["recp_cont"] = "recent past<br/>continuous",
		["recp_perf"] = "recent past<br/>perfect",
		
		["remp"] = "remote past",
		["remp_cont"] = "remote past<br/>continuous",
		["remp_perf"] = "remote past<br/>perfect",
		
		["futr"] = "future",
		["futr_cont"] = "future<br/>continuous",
		["futr_perf"] = "future<br/>perfect",
		
		["sg"] = "singular",
		["1sg"] = "1st singular",
		["2sg"] = "2nd singular",
		["pl"] = "plural",
		["1pl"] = "1st plural",
		["2pl"] = "2nd plural",
		
		["c1"] = "class 1",
		["c2"] = "class 2",
		["c3"] = "class 3",
		["c4"] = "class 4",
		["c5"] = "class 5",
		["c6"] = "class 6",
		["c7"] = "class 7",
		["c8"] = "class 8",
		["c9"] = "class 9",
		["c10"] = "class 10",
		["c11"] = "class 11",
		["c14"] = "class 14",
		["c15"] = "class 15",
		["c17"] = "class 17",
	}
	
	local classes = {"1sg", "2sg", "1pl", "2pl", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c14", "c15", "c17"}
	local numbers = {"sg", "pl"}
	local rows = {{"impr", "impr_obj"}, {"pres", "part", "subj"}, {"recp", "recp_cont"}, {"remp", "remp_cont"}, {"futr"}}
	
	local maxcols = 0
	
	for _, row in ipairs(rows) do
		maxcols = math.max(maxcols, #row)
	end
	
	local wikicode = {}
	
	table.insert(wikicode, "{| class=\"wikitable inflection-table vsSwitcher vsToggleCategory-inflection\" style=\"border-style: double; border-width: 3px; margin: 0;\"")
	table.insert(wikicode, "|-")
	table.insert(wikicode, "! class=\"vsToggleElement\" style=\"background: #CCC; min-width: 20em; text-align: left;\" colspan=\"" .. tostring(maxcols + 1) .. "\" | {{{info}}}")
	
	table.insert(wikicode, "|- class=\"vsHide\"")
	table.insert(wikicode, "! Infinitive")
	table.insert(wikicode, "| {{{inf}}}")
	table.insert(wikicode, "! colspan=\"" .. tostring(maxcols - 1) .. "\" |")
	
	for i, row in ipairs(rows) do
		table.insert(wikicode, "|- class=\"vsHide\"")
		table.insert(wikicode, "| style=\"min-width: 8em;\" |")
		
		for j, col in ipairs(row) do
			table.insert(wikicode, "! style=\"min-width: 12em;\" | " .. mw.getContentLanguage():ucfirst(names[col]))
		end
		
		if #row < maxcols then
			table.insert(wikicode, "! colspan=\"" .. tostring(maxcols - #row) .. "\" rowspan=\"" .. (#(i == 1 and numbers or classes) + 1) .. "\" |")
		end
		
		for _, class in ipairs(i == 1 and numbers or classes) do
			table.insert(wikicode, "|- class=\"vsHide\"")
			table.insert(wikicode, "! " .. mw.getContentLanguage():ucfirst(names[class]))
			
			for _, col in ipairs(row) do
				table.insert(wikicode, "| {{{" .. col .. "_" .. class .. "}}}")
			end
		end
	end
	
	table.insert(wikicode, "|}")
	
	wikicode = table.concat(wikicode, "\n")
	
	return mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)
end


return export