Module:af-lemma

Vanuit Wiktionary, die vrye woordeboek.

Dokumentasie vir hierdie module kan geskep word by: Module:af-lemma/doc

local export = {}
local pos_functions = {}

local lang = require("Module:languages").getByCode("af")
local PAGENAME = mw.title.getCurrentTitle().text

local function glossary_link(entry, text)
	text = text or entry
	return "[[Hulp:Terminologie#" .. entry .. "|" .. text .. "]]"
end

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	
	local params = {
		["head"] = {list = true, default = ""},
		["suff"] = {type = "boolean"},
	}
	
	if pos_functions[poscat] then
		for key, val in pairs(pos_functions[poscat].params) do
			params[key] = val
		end
	end
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = poscat, categories = {}, heads = args["head"], inflections = {}}
	
	if args["suff"] then
		data.pos_category = "suffixes"
		
		if poscat == "adjectives" then
			table.insert(data.categories, lang:getCanonicalName() .. " adjective-forming suffixes")
		elseif poscat == "adverbs" then
			table.insert(data.categories, lang:getCanonicalName() .. " adverb-forming suffixes")
		elseif poscat == "nouns" then
			table.insert(data.categories, lang:getCanonicalName() .. " noun-forming suffixes")
		elseif poscat == "verbs" then
			table.insert(data.categories, lang:getCanonicalName() .. " verb-forming suffixes")
		else
			error("No category exists for suffixes forming " .. poscat .. ".")
		end
	end
	
	if pos_functions[poscat] then
		pos_functions[poscat].func(args, data)
	end
	
	return require("Module:lemma").full_headword(data)
end

-- Display additional inflection information for an adjective
pos_functions["adjectives"] = {
	params = {
		[1] = {},
		["attr2"] = {},
		
		[2] = {},
		["comp2"] = {},
		
		[3] = {},
		["sup2"] = {},
		},
	func = function(args, data)
		local attr = args[1]
		local comp = args[2]
		local sup = args[3]
		
		local attr2 = args["attr2"]
		local comp2 = args["comp2"]
		local sup2 = args["sup2"]
		
		-- Generate the missing forms
		if not attr then
			if PAGENAME:find("[^aeiou]u$") then
				attr = PAGENAME .. "we"
			elseif mw.ustring.find(PAGENAME, "[eë]$") then
				attr = PAGENAME
			else
				attr = PAGENAME .. "e"
			end
		end
		
		if not comp then
			if PAGENAME:find("r$") then
				comp = PAGENAME .. "der"
			elseif attr ~= "-" then
				if not attr:find("[eë]$") then
					comp = attr .. "er"
				else
					comp = attr .. "r"
				end
			else
				comp = PAGENAME .. "er"
			end
		end
		
		if not sup then
			if attr == PAGENAME:gsub("nk$", "ng") then
				sup = attr .. "ste"
			elseif PAGENAME:find("[^aeiou]u$") then
				sup = PAGENAME .. "uste"
			else
				sup = PAGENAME .. "ste"
			end
		end
		
		-- Attributive form
		if attr == "-" then
			table.insert(data.inflections, {label = "used only [[predicative]]ly"})
			table.insert(data.categories, "Afrikaans predicative-only adjectives")
		else
			local infl_parts = {label = "[[attributive]]", attr}
			
			if attr2 then
				table.insert(infl_parts, attr2)
		   	end
		   	
		   	table.insert(data.inflections, infl_parts)
		end
		
		-- Comparative and superlative forms
		if comp == "-" then
			table.insert(data.inflections, {label = "not [[Hulp:Terminologie#comparable|comparable]]"})
		else
			-- Comparative
			local infl_parts = {label = "[[Hulp:Terminologie#comparative|comparative]]", comp}
			
			if comp2 then
				table.insert(infl_parts, comp2)
			end
	 
			table.insert(data.inflections, infl_parts)
			
			-- Superlative
			infl_parts = {label = "[[Hulp:Terminologie#superlative|superlative]]", sup}
			
			if sup2 then
				table.insert(infl_parts, sup2)
			end
			
			table.insert(data.inflections, infl_parts)
		end
	end
}

pos_functions["selfstandige naamwoorde"] = {
	params = {
		[1] = {list = true, allow_holes = true},
		
		-- TODO: This should really be a list parameter too...
		["plqual"] = {},
		["pl2qual"] = {},
		["pl3qual"] = {},
		["pl4qual"] = {},
		["pl5qual"] = {},
		},
	func = function(args, data)
		-- Gather all the plural parameters from the numbered parameters.
		local plurals = {}
		
		for i = 1, args[1].maxindex do
			local pl = args[1][i]
			
			if pl then
				local qual = args["pl" .. (i == 1 and "" or i) .. "qual"]
				
				if qual then
					table.insert(plurals, {term = pl, qualifiers = {qual}})
				else
					table.insert(plurals, pl)
				end
			end
		end
		
		-- Decide what to do next...
		local mode = nil
		
		if plurals[1] == "?" or plurals[1] == "!" or plurals[1] == "-" or plurals[1] == "~" then
			mode = plurals[1]
			table.remove(plurals, 1)  -- Remove the mode parameter
		end
		
		-- Plural is unknown
		if mode == "?" then
			table.insert(data.categories, lang:getCanonicalName() .. " nouns with unknown or uncertain plurals")
			return
		-- Plural is not attested
		elseif mode == "!" then
			table.insert(data.inflections, {label = "plural not attested"})
			table.insert(data.categories, lang:getCanonicalName() .. " nouns with unattested plurals")
			return
		-- Uncountable noun; may occasionally have a plural
		elseif mode == "-" then
			table.insert(data.categories, "Ontelbare selfstandige naamwoorde in " .. lang:getCanonicalName())
			
			-- If plural forms were given explicitly, then show "usually"
			if #plurals > 0 then
				table.insert(data.inflections, {label = "gewoonlik " .. glossary_link("ontelbaar")})
				table.insert(data.categories, "Telbare selfstandige naamwoorde in " .. lang:getCanonicalName())
			else
				table.insert(data.inflections, {label = glossary_link("ontelbaar")})
			end
		-- Mixed countable/uncountable noun, always has a plural
		elseif mode == "~" then
			table.insert(data.inflections, {label = glossary_link("telbaar") .. " and " .. glossary_link("ontelbaar")})
			table.insert(data.categories, "Ontelbare selfstandige naamwoorde in " .. lang:getCanonicalName())
			table.insert(data.categories, "Telbare selfstandige naamwoorde in " .. lang:getCanonicalName())
			
			-- If no plural was given, add a default one now
			if #plurals == 0 then
				plurals = {"e"}
			end
		-- The default, always has a plural
		else
			table.insert(data.categories, "Telbare selfstandige naamwoorde in " .. lang:getCanonicalName())
			
			-- If no plural was given, add a default one now
			if #plurals == 0 then
				plurals = {"e"}
			end
			if plural and not mw.title.new(plural).exists then
				table.insert(categories, "Selfstandige naamwoorde in Afrikaans met ontbrekende meervoude")
			end
		end
		
		-- If there are no plurals to show, return now
		if #plurals == 0 then
			return
		end
		
		-- There are plural forms to show, so show them
		local pl_parts = {label = "meervoud", accel = {form = "p"}}
		
		local function check_ies(pl, stem)
			local newplural, nummatches = stem:gsub("([^aeiou])y$","%1ies")
			return nummatches > 0 and pl == newplural
		end
		local stem = PAGENAME
		local irregular = false
		for i, pl in ipairs(plurals) do
			if pl == "e" then
				table.insert(pl_parts, stem .. "e")
			elseif pl == "ë" then
				table.insert(pl_parts, stem .. "ë")
			elseif pl == "s" then
				table.insert(pl_parts, stem .. "s")
			else
				table.insert(pl_parts, pl)
				if type(pl) == "table" then
					pl = pl.term
				end
				if not stem:find(" ") and not (pl == stem .. "e" or pl == stem .. "s" or pl == stem .. "ë" or check_ies(pl, stem)) then
					irregular = true
					if pl == stem then
						table.insert(data.categories, lang:getCanonicalName() .. " indeclinable nouns")
					end
				end
			end
		end
		-- Uncomment hierdie vir nou terwyl ons nie weet wat 'n irregular plural in Afrkaans is nie
		-- Die boonste logika moet ook aangepas word vir Afrikaans
		-- if irregular then
			-- table.insert(data.categories, lang:getCanonicalName() .. " nouns with irregular plurals")
		-- end
		
		table.insert(data.inflections, pl_parts)
	end
}

-- List of irregular verbs. See further down.
local irregular_verbs = {}

-- Display additional inflection information for a adverb
pos_functions["verbs"] = {
	params = {
		[1] = {list = "pres", default = ""},
		[2] = {list = "past", default = ""},
		
		["sep"] = {},
		},
	func = function(args, data)
		local past_part = args[2]
		local sep = args["sep"]
		
		local stem = PAGENAME
		
		-- If separable, remove the prefix to create the stem
		if sep then
			stem = PAGENAME:gsub("^" .. sep, "")
			table.insert(data.categories, "Afrikaans separable verbs")
		end
		
		local forms = {}
		
		-- Is this the stem of an irregular verb?
		-- If so, delegate all the work to its function.
		if irregular_verbs[stem] then
			irregular_verbs[stem](forms)
			table.insert(data.categories, "Afrikaans irregular verbs")
		else
			forms["pres"] = {stem}
			forms["pres|ptcp"] = args[1]; if forms["pres|ptcp"][1] == "" then forms["pres|ptcp"][1] = stem .. "ende" end
			forms["past|ptcp"] = args[2]; if forms["past|ptcp"][1] == "" then forms["past|ptcp"][1] = "ge" .. stem end
		end
		
		for key, form in pairs(forms) do
			form.accel = {form = key}
		end
		
		-- Add the forms to the list
		if forms["pres"] then
			if sep then
				forms["pres"].accel = nil
				
				for i, form in ipairs(forms["pres"]) do
					forms["pres"][i] = "[[" .. form .. "]] [[" .. sep .. "]]"
				end
			end
			
			forms["pres"].label = "present"
			table.insert(data.inflections, forms["pres"])
		end
		
		if forms["pres|ptcp"] then
			if sep then
				for i, form in ipairs(forms["pres|ptcp"]) do
					forms["pres|ptcp"][i] = sep .. form
				end
			end
			
			forms["pres|ptcp"].label = "present participle"
			table.insert(data.inflections, forms["pres|ptcp"])
		end
		
		if forms["past"] then
			forms["past"].accel = nil
			
			if sep then
				for i, form in ipairs(forms["past"]) do
					forms["past"][i] = "[[" .. form .. "]] [[" .. sep .. "]]"
				end
			end
			
			forms["past"].label = "past"
			table.insert(data.inflections, forms["past"])
		end
		
		if forms["past|ptcp"] then
			if sep then
				for i, form in ipairs(forms["past|ptcp"]) do
					forms["past|ptcp"][i] = sep .. form
				end
			end
			
			forms["past|ptcp"].label = "past participle"
			table.insert(data.inflections, forms["past|ptcp"])
		end
	end
}

irregular_verbs["dink"] = function(forms)
	forms["pres"] = {"dink"}
	forms["pres|ptcp"] = {"denkende"}
	forms["past"] = {"dag", "dog"}
	forms["past|ptcp"] = {"gedag", "gedog", "gedink"}
end

irregular_verbs["hê"] = function(forms)
	forms["pres"] = {"het"}
	forms["pres|ptcp"] = {"hebbende"}
	forms["past"] = {"had"}
	forms["past|ptcp"] = {"gehad"}
end

irregular_verbs["kan"] = function(forms)
	forms["pres"] = {"kan"}
	forms["pres|ptcp"] = nil
	forms["past"] = {"kon"}
	forms["past|ptcp"] = nil
end

irregular_verbs["mag"] = function(forms)
	forms["pres"] = {"mag"}
	forms["pres|ptcp"] = nil
	forms["past"] = {"mog"}
	forms["past|ptcp"] = nil
end

irregular_verbs["moet"] = function(forms)
	forms["pres"] = {"moet"}
	forms["pres|ptcp"] = nil
	forms["past"] = {"moes"}
	forms["past|ptcp"] = nil
end

irregular_verbs["sal"] = function(forms)
	forms["pres"] = {"sal"}
	forms["pres|ptcp"] = nil
	forms["past"] = {"sou"}
	forms["past|ptcp"] = nil
end

irregular_verbs["wees"] = function(forms)
	forms["pres"] = {"is"}
	forms["pres|ptcp"] = {"synde"}
	forms["past"] = {"was"}
	forms["past|ptcp"] = {"gewees"}
end

irregular_verbs["weet"] = function(forms)
	forms["pres"] = {"weet"}
	forms["pres|ptcp"] = {"wetende"}
	forms["past"] = {"wis"}
	forms["past|ptcp"] = {"geweet"}
end

irregular_verbs["wil"] = function(forms)
	forms["pres"] = {"wil"}
	forms["pres|ptcp"] = nil
	forms["past"] = {"wou"}
	forms["past|ptcp"] = {"gewil"}
end

irregular_verbs["beter"] = function(forms)
	forms["pres"] = {"beter"}
	forms["pres|ptcp"] = nil
	forms["past"] = nil
	forms["past|ptcp"] = nil
end

return export