Module:Zu-adjectives

local m_utilities = require("Module:utilities")
local m_links = require("Module:links")

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

local export = {}


function export.adjective(frame)
	local params = {
		[1] = {},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {forms = {}, info = "adjective concord", categories = {}}
	
	if args[1] == "L" or args[1] == "H" or args[1] == "LH" or args[1] == "HH" or args[1] == "HHH" then
		data.info = data.info .. ", tone class " .. args[1]
		table.insert(data.categories, lang:getCanonicalName() .. " adjectives with tone class " .. args[1])
	elseif args[1] then
		error("The tone class must be \"L\", \"H\", \"LH\", \"HH\" or \"HHH\".")
	else
		table.insert(data.categories, lang:getCanonicalName() .. " adjectives needing tone")
	end
	
	local base = mw.title.getCurrentTitle().subpageText
	
	data.forms["mod_1sg_pos"] = {"engim" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["mod_2sg_pos"] = {"om" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["mod_1pl_pos"] = {"esiba" .. base}
	data.forms["mod_2pl_pos"] = {"eniba" .. base}
	data.forms["mod_c1_pos"]  = {"om" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["mod_c2_pos"]  = {"aba" .. base}
	data.forms["mod_c3_pos"]  = {"om" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["mod_c4_pos"]  = {"emi" .. base}
	data.forms["mod_c5_pos"]  = {"eli" .. base}
	data.forms["mod_c6_pos"]  = {"ama" .. base}
	data.forms["mod_c7_pos"]  = {"esi" .. base}
	data.forms["mod_c8_pos"]  = {"ezi" .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)}
	data.forms["mod_c9_pos"]  = {"e"   .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)}
	data.forms["mod_c10_pos"] = {"ezi" .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)}
	data.forms["mod_c11_pos"] = {"olu" .. base}
	data.forms["mod_c14_pos"] = {"obu" .. base}
	data.forms["mod_c15_pos"] = {"oku" .. base}
	data.forms["mod_c17_pos"] = {"oku" .. base}
	
	data.forms["mod_1sg_neg"] = {"engingem" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["mod_2sg_neg"] = {"ongem" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["mod_1pl_neg"] = {"esingeba" .. base}
	data.forms["mod_2pl_neg"] = {"eningeba" .. base}
	data.forms["mod_c1_neg"]  = {"ongem" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["mod_c2_neg"]  = {"abangeba" .. base}
	data.forms["mod_c3_neg"]  = {"ongem" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["mod_c4_neg"]  = {"engemi" .. base}
	data.forms["mod_c5_neg"]  = {"elingeli" .. base}
	data.forms["mod_c6_neg"]  = {"angema" .. base}
	data.forms["mod_c7_neg"]  = {"esingesi" .. base}
	data.forms["mod_c8_neg"]  = {"ezingezi" .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)}
	data.forms["mod_c9_neg"]  = {"enge"   .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base),
							     "engeyi"   .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)
								}
	data.forms["mod_c10_neg"] = {"ezingezi" .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)}
	data.forms["mod_c11_neg"] = {"olungelu" .. base}
	data.forms["mod_c14_neg"] = {"obungebu" .. base}
	data.forms["mod_c15_neg"] = {"okungeku" .. base}
	data.forms["mod_c17_neg"] = {"okungeku" .. base}
	
	data.forms["cop_1sg_pos"] = {"ngim" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["cop_2sg_pos"] = {"um" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["cop_1pl_pos"] = {"siba" .. base}
	data.forms["cop_2pl_pos"] = {"niba" .. base}
	data.forms["cop_c1_pos"]  = {"m" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["cop_c2_pos"]  = {"ba" .. base}
	data.forms["cop_c3_pos"]  = {"m" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["cop_c4_pos"]  = {"mi" .. base}
	data.forms["cop_c5_pos"]  = {"li" .. base}
	data.forms["cop_c6_pos"]  = {"ma" .. base}
	data.forms["cop_c7_pos"]  = {"si" .. base}
	data.forms["cop_c8_pos"]  = {"zi" .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)}
	data.forms["cop_c9_pos"]  = {"i"  .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base),
								"yi"  .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)
	}
	data.forms["cop_c10_pos"] = {"zi" .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)}
	data.forms["cop_c11_pos"] = {"lu" .. base}
	data.forms["cop_c14_pos"] = {"bu" .. base}
	data.forms["cop_c15_pos"] = {"ku" .. base}
	data.forms["cop_c17_pos"] = {"ku" .. base}
	
	data.forms["cop_1sg_neg"] = {"angim" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["cop_2sg_neg"] = {"awum" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["cop_1pl_neg"] = {"asiba" .. base}
	data.forms["cop_2pl_neg"] = {"aniba" .. base}
	data.forms["cop_c1_neg"]  = {"akam" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["cop_c2_neg"]  = {"ababa" .. base}
	data.forms["cop_c3_neg"]  = {"awum" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["cop_c4_neg"]  = {"ayimi" .. base}
	data.forms["cop_c5_neg"]  = {"alili" .. base}
	data.forms["cop_c6_neg"]  = {"awama" .. base}
	data.forms["cop_c7_neg"]  = {"asisi" .. base}
	data.forms["cop_c8_neg"]  = {"azizi" .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)}
	data.forms["cop_c9_neg"]  = {"ayiyi"  .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)}
	data.forms["cop_c10_neg"] = {"azizi" .. (mw.ustring.find(base, "^[bfp]") and "m" or mw.ustring.find(base, "^n") and "" or "n") .. (mw.ustring.find(base, "^[ptk]h") and mw.ustring.gsub(base, "^([ptk])h", "%1") or mw.ustring.find(base, "^sh") and mw.ustring.gsub(base, "^sh", "tsh") or base)}
	data.forms["cop_c11_neg"] = {"alulu" .. base}
	data.forms["cop_c14_neg"] = {"abubu" .. base}
	data.forms["cop_c15_neg"] = {"akuku" .. base}
	data.forms["cop_c17_neg"] = {"akuku" .. base}
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


function export.enumerative(frame)
	local params = {
		[1] = {},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {forms = {}, info = "enumerative concord", categories = {}}
	data.simple = true
	
	if args[1] == "L" or args[1] == "H" or args[1] == "LH" or args[1] == "HH" or args[1] == "HHH" then
		data.info = data.info .. ", tone class " .. args[1]
		table.insert(data.categories, lang:getCanonicalName() .. " adjectives with tone class " .. args[1])
	elseif args[1] then
		error("The tone class must be \"L\", \"H\", \"LH\", \"HH\" or \"HHH\".")
	else
		table.insert(data.categories, lang:getCanonicalName() .. " enumeratives needing tone")
	end
	
	local base = mw.title.getCurrentTitle().subpageText
	
	data.forms["mod_c1"]  = {"m" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["mod_c2"]  = {"ba" .. base}
	data.forms["mod_c3"]  = {"m" .. (mw.ustring.find(base, "^[^aeiou]+[aeiou]$") and "u" or "") .. base}
	data.forms["mod_c4"]  = {"mi" .. base}
	data.forms["mod_c5"]  = {"li" .. base}
	data.forms["mod_c6"]  = {"ma" .. base}
	data.forms["mod_c7"]  = {"si" .. base}
	data.forms["mod_c8"]  = {"zi" .. base}
	data.forms["mod_c9"]  = {"yi" .. base}
	data.forms["mod_c10"] = {"zi" .. base}
	data.forms["mod_c11"] = {"lu" .. base}
	data.forms["mod_c14"] = {"bu" .. base}
	data.forms["mod_c15"] = {"ku" .. base}
	data.forms["mod_c17"] = {"ku" .. base}
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


function export.relative(frame)
	local params = {
		[1] = {},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {forms = {}, info = "relative concord", categories = {}}
	
	if args[1] == "L" or args[1] == "H" or args[1] == "LH" or args[1] == "HH" or args[1] == "HHH" then
		data.info = data.info .. ", tone class " .. args[1]
		table.insert(data.categories, lang:getCanonicalName() .. " adjectives with tone class " .. args[1])
	elseif args[1] then
		error("The tone class must be \"L\", \"H\", \"LH\", \"HH\" or \"HHH\".")
	else
		table.insert(data.categories, lang:getCanonicalName() .. " relatives needing tone")
	end
	
	local base = mw.title.getCurrentTitle().subpageText
	
	data.forms["mod_1sg_pos"] = {"engi" .. base}
	data.forms["mod_2sg_pos"] = {"o" .. base}
	data.forms["mod_1pl_pos"] = {"esi" .. base}
	data.forms["mod_2pl_pos"] = {"eni" .. base}
	data.forms["mod_c1_pos"]  = {"o" .. base}
	data.forms["mod_c2_pos"]  = {"aba" .. base}
	data.forms["mod_c3_pos"]  = {"o" .. base}
	data.forms["mod_c4_pos"]  = {"e" .. base}
	data.forms["mod_c5_pos"]  = {"eli" .. base}
	data.forms["mod_c6_pos"]  = {"a" .. base}
	data.forms["mod_c7_pos"]  = {"esi" .. base}
	data.forms["mod_c8_pos"]  = {"ezi" .. base}
	data.forms["mod_c9_pos"]  = {"e" .. base}
	data.forms["mod_c10_pos"] = {"ezi" .. base}
	data.forms["mod_c11_pos"] = {"olu" .. base}
	data.forms["mod_c14_pos"] = {"obu" .. base}
	data.forms["mod_c15_pos"] = {"oku" .. base}
	data.forms["mod_c17_pos"] = {"oku" .. base}
	
	data.forms["mod_1sg_neg"] = {"enginge" .. base}
	data.forms["mod_2sg_neg"] = {"onge" .. base}
	data.forms["mod_1pl_neg"] = {"esinge" .. base}
	data.forms["mod_2pl_neg"] = {"eninge" .. base}
	data.forms["mod_c1_neg"]  = {"onge" .. base}
	data.forms["mod_c2_neg"]  = {"abange" .. base}
	data.forms["mod_c3_neg"]  = {"onge" .. base}
	data.forms["mod_c4_neg"]  = {"enge" .. base}
	data.forms["mod_c5_neg"]  = {"elinge" .. base}
	data.forms["mod_c6_neg"]  = {"ange" .. base}
	data.forms["mod_c7_neg"]  = {"esinge" .. base}
	data.forms["mod_c8_neg"]  = {"ezinge" .. base}
	data.forms["mod_c9_neg"]  = {"enge" .. base}
	data.forms["mod_c10_neg"] = {"ezinge" .. base}
	data.forms["mod_c11_neg"] = {"olunge" .. base}
	data.forms["mod_c14_neg"] = {"obunge" .. base}
	data.forms["mod_c15_neg"] = {"okunge" .. base}
	data.forms["mod_c17_neg"] = {"okunge" .. base}
	
	data.forms["cop_1sg_pos"] = {"ngi" .. base}
	data.forms["cop_2sg_pos"] = {"u" .. base}
	data.forms["cop_1pl_pos"] = {"si" .. base}
	data.forms["cop_2pl_pos"] = {"ni" .. base}
	data.forms["cop_c1_pos"]  = {"u" .. base}
	data.forms["cop_c2_pos"]  = {"ba" .. base}
	data.forms["cop_c3_pos"]  = {"u" .. base}
	data.forms["cop_c4_pos"]  = {"i" .. base}
	data.forms["cop_c5_pos"]  = {"li" .. base}
	data.forms["cop_c6_pos"]  = {"a" .. base}
	data.forms["cop_c7_pos"]  = {"si" .. base}
	data.forms["cop_c8_pos"]  = {"zi" .. base}
	data.forms["cop_c9_pos"]  = {"i" .. base}
	data.forms["cop_c10_pos"] = {"zi" .. base}
	data.forms["cop_c11_pos"] = {"lu" .. base}
	data.forms["cop_c14_pos"] = {"bu" .. base}
	data.forms["cop_c15_pos"] = {"ku" .. base}
	data.forms["cop_c17_pos"] = {"ku" .. base}
	
	data.forms["cop_1sg_neg"] = {"angi" .. base}
	data.forms["cop_2sg_neg"] = {"awu" .. base}
	data.forms["cop_1pl_neg"] = {"asi" .. base}
	data.forms["cop_2pl_neg"] = {"ani" .. base}
	data.forms["cop_c1_neg"]  = {"aka" .. base}
	data.forms["cop_c2_neg"]  = {"aba" .. base}
	data.forms["cop_c3_neg"]  = {"awu" .. base}
	data.forms["cop_c4_neg"]  = {"ayi" .. base}
	data.forms["cop_c5_neg"]  = {"ali" .. base}
	data.forms["cop_c6_neg"]  = {"awa" .. base}
	data.forms["cop_c7_neg"]  = {"asi" .. base}
	data.forms["cop_c8_neg"]  = {"azi" .. base}
	data.forms["cop_c9_neg"]  = {"ayi" .. base}
	data.forms["cop_c10_neg"] = {"azi" .. base}
	data.forms["cop_c11_neg"] = {"alu" .. base}
	data.forms["cop_c14_neg"] = {"abu" .. base}
	data.forms["cop_c15_neg"] = {"aku" .. base}
	data.forms["cop_c17_neg"] = {"aku" .. base}
	
	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 = {
		["mod"] = "modifier",
		["cop"] = "copulative",
		["pos"] = "positive",
		["neg"] = "negative",
		
		["1sg"] = "1st singular",
		["2sg"] = "2nd singular",
		["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 = {"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c14", "c15", "c17"}
	local columns = {"mod"}
	local columns2 = {}
	
	if not data.simple then
		table.insert(classes, 1, "1sg")
		table.insert(classes, 2, "2sg")
		table.insert(classes, 3, "1pl")
		table.insert(classes, 4, "2pl")
		
		table.insert(columns, "cop")
		table.insert(columns2, "pos")
		table.insert(columns2, "neg")
	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=\"5\" | {{{info}}}")
	
	table.insert(wikicode, "|- class=\"vsHide\"")
	table.insert(wikicode, "| style=\"min-width: 8em;\" |")
	
	for _, col in ipairs(columns) do
		table.insert(wikicode, "! style=\"min-width: 12em;\", colspan=\"2\" | " .. mw.getContentLanguage():ucfirst(names[col]))
	end
	
	if not data.simple then
		table.insert(wikicode, "|- class=\"vsHide\"")
		table.insert(wikicode, "! !! " .. names["pos"])
		table.insert(wikicode, "! " .. names["neg"])
		table.insert(wikicode, "! " .. names["pos"])
		table.insert(wikicode, "! " .. names["neg"])
	end
	
	for _, class in ipairs(classes) do
		table.insert(wikicode, "|- class=\"vsHide\"")
		table.insert(wikicode, "! " .. mw.getContentLanguage():ucfirst(names[class]))
		
		for _, col in ipairs(columns) do
			if not data.simple then
				for _, col2 in ipairs(columns2) do
					table.insert(wikicode, "| {{{" .. col .. "_" .. class .. "_" .. col2 .. "}}}")
				end
			else
				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