Module:nl-headword

Vanuit Wiktionary, die vrye woordeboek.

Dokumentasie vir hierdie module kan geskep word by: Module:nl-headword/doc

local export = {}
local pos_functions = {}

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

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	PAGENAME = mw.title.getCurrentTitle().text
	
	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:headword").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 [[Appendix:Glossary#comparable|comparable]]"})
		else
			-- Comparative
			local infl_parts = {label = "[[Appendix:Glossary#comparative|comparative]]", comp}
			
			if comp2 then
				table.insert(infl_parts, comp2)
			end
	 
			table.insert(data.inflections, infl_parts)
			
			-- Superlative
			infl_parts = {label = "[[Appendix:Glossary#superlative|superlative]]", sup}
			
			if sup2 then
				table.insert(infl_parts, sup2)
			end
			
			table.insert(data.inflections, infl_parts)
		end
	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