Module:zu-headword

د ويکيسيند لخوا
Jump to navigation Jump to search

Documentation for this module may be created at Module:zu-headword/لاسوند

local export = {}
local pos_functions = {}

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

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local args = frame:getParent().args
	PAGENAME = mw.title.getCurrentTitle().text
	NAMESPACE = mw.title.getCurrentTitle().nsText
	
	local head = args["head"]; if head == "" then head = nil end
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	
	local classes = {}
	local inflections = {}
	local categories = {}
	local ctemp = {}
	
	local sort_key = nil
	
	if pos_functions[poscat] then
		local head2
		head2, sort_key = pos_functions[poscat](args, classes, inflections, categories)
		head = head or head2
	end
	
	if #categories < 1 then
		table.insert(categories, "Zulu " .. poscat)
	end
	
	return require("Module:headword").full_headword(lang, nil, head, nil, classes, inflections, categories, sort_key)
end

-- A list of valid noun classes
-- The value is the corresponding plural class.
-- True means the class is uncountable.
local singular_classes = {
	["1"] = "2",
	["1a"] = "2a",
	["3"] = "4",
	["3a"] = "4a",
	["5"] = "6",
	["7"] = "8",
	["9"] = "10",
	["11"] = "10",
	["14"] = true,
	["15"] = true,
	["17"] = true}

local plural_classes = {
	["2"] = true,
	["2a"] = true,
	["4"] = true,
	["4a"] = true,
	["6"] = true,
	["8"] = true,
	["10"] = true}

-- Display information for a noun's class
-- This is separate so that it can also be used for proper nouns
function noun_class(args, classes, inflections, categories)
	local class1 = args[1]; if class1 == "" then class1 = nil end
	local class2 = args[2]; if class2 == "" then class2 = nil end
	
	-- Process the class numbers themselves.
	local plurale_tantum = class2 == "-"
	
	-- Does this noun have no plural?
	if plural_classes[class1] or singular_classes[class1] == true or class2 ==  "-" then
		table.insert(classes, class1)
	-- It does have a plural, is it a valid singular class?
	elseif singular_classes[class1] then
		-- Is the second class a valid plural class?
		if plural_classes[class2] then
			table.insert(classes, class1)
			table.insert(classes, class2)
		else
			table.insert(classes, class1)
			table.insert(classes, "c?")
		end
	else
		table.insert(classes, "c?")
		table.insert(classes, "c?")
	end
	
	-- Categorize based on the classes
	
	-- Don't put plural classes in the main noun category.
	if plural_classes[classes[1]] and not plurale_tantum then
		table.insert(categories, "Zulu noun forms")
	else
		table.insert(categories, "Zulu nouns")
	end
	
	-- Is this noun uncountable, or does it have a regular or missing plural?
	-- Classes 14, 15 and 17 are always uncountable.
	if classes[1] ~= "c?" then
		if not classes[2] or classes[2] == "c?" or plural_classes[classes[1]] or classes[2] == singular_classes[classes[1]] then
			table.insert(categories, "Zulu class " .. classes[1] .. " nouns")
		else
			table.insert(categories, "Zulu class " .. classes[1] .. "/" .. class2 .. " nouns")
		end
	end
	
	if classes[1] == "c?" or classes[2] == "c?" then
		table.insert(categories, "Zulu nouns needing inflection")
	end
end

-- Display information for a noun
pos_functions["nouns"] = function(args, classes, inflections, categories)
	noun_class(args, classes, inflections, categories)
	
	-- Is there no plural?
	if not classes[2] then
		if not plural_classes[classes[1]] then
			table.insert(inflections, {label = "[[Appendix:Glossary#uncountable|uncountable]]"})
			table.insert(categories, "Zulu uncountable nouns")
		elseif args[2] == "-" then
			table.insert(inflections, {label = "[[Appendix:Glossary#plurale tantum|plurale tantum]]"})
			table.insert(categories, "Zulu pluralia tantum")
		end
	else
		local plural = args[3]; if plural == "" or classes[2] == "c?" then plural = nil end
		
		table.insert(inflections, {label = "plural", request = true, plural})
	end
	
	return nil, remove_prefix(PAGENAME, classes[1])
end

pos_functions["adjectives"] = function(args, classes, inflections, categories)
	table.insert(categories, "Zulu adjectives")
	return "-" .. PAGENAME:gsub("^-", ""), nil
end

pos_functions["relatives"] = function(args, classes, inflections, categories)
	table.insert(categories, "Zulu relatives")
	return "-" .. PAGENAME:gsub("^-", ""), nil
end

pos_functions["verbs"] = function(args, classes, inflections, categories)
	table.insert(categories, "Zulu verbs")
	return "-" .. PAGENAME:gsub("^-", ""), nil
end

local prefixes = {
	["1"] = {"umu([^aeiou])", "um(.)", "u(n)"},
	["1a"] = {"u([^aeiou])"},
	["2"] = {"aba([^aeiou])", "abe([^aeiou])"},
	["2a"] = {"o([^aeiou])"},
	["3"] = {"umu([^aeiou])", "um(.)", "u(n)"},
	["3a"] = {"u([^aeiou])"},
	["4"] = {"imi([^aeiou])", "im([aeiou])"},
	["4a"] = {"imi([^aeiou])", "im([aeiou])"},
	["5"] = {"ili([^aeiou])", "i([^aeiou])"},
	["6"] = {"ama([^aeiou])", "am([aeiou])"},
	["7"] = {"isi([^aeiou])", "is([aeiou])"},
	["8"] = {"izi([^aeiou])", "iz([aeiou])"},
	["9"] = {"in([^aeiou])", "im([^aeiou])", "i([mn][aeiou])"},
	["10"] = {"izin([^aeiou])", "izim([^aeiou])", "izi([^aeiou])", "iz([aeiou])"},
	["11"] = {"ulu([^aeiou])", "u([^aeiou])"},
	["14"] = {"ubu([^aeiou])", "utshw(a)", "utsh(a)"},
	["15"] = {"uku([^aeiou])", "ukw([aeiou])"},
	["17"] = {"uku([^aeiou])", "ukw([aeiou])"} }

function remove_prefix(word, class)
	if not prefixes[class] then
		return nil
	end
	
	-- If there is a capital letter in the word,
	-- assume that it's the first letter of the stem and remove everything before it
	if word:find("[A-Z]") then
		return word:gsub("^[a-z]+", "")
	else
		for key, prefix in ipairs(prefixes[class]) do
			word = word:gsub("^" .. prefix, "%1")
		end
		return word:gsub("^-", "")
	end
end

return export