Last modified on 26 July 2014, at 00:17

Module:af-headword

The following documentation is located at Module:af-headword/documentation. [edit]
Useful links: subpage listtransclusionstestcases
Text-x-generic with pencil.svg This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}
local pos_functions = {}
 
local lang = require("Module:languages").getByCode("af")
 
-- 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
 
	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 inflections = {}
	local categories = {"Afrikaans " .. poscat}
 
	if pos_functions[poscat] then
		pos_functions[poscat](args, inflections, categories)
	end
 
	return require("Module:headword").full_headword(lang, nil, head, nil, nil, inflections, categories, nil)
end
 
-- Display additional inflection information for an adjective
pos_functions["adjectives"] = function(args, inflections, categories)
	local attr = args[1]; if attr == "" then attr = nil end
	local comp = args[2]; if comp == "" then comp = nil end
	local sup = args[3]; if sup == "" then sup = nil end
 
	local attr2 = args["attr2"]; if attr2 == "" then attr2 = nil end
	local comp2 = args["comp2"]; if comp2 == "" then comp2 = nil end
	local sup2 = args["sup2"]; if sup2 == "" then sup2 = nil end
 
	-- 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(inflections, {label = "used only [[predicative]]ly"})
		table.insert(categories, "Afrikaans predicative-only adjectives")
	else
		local infl_parts = {label = "[[attributive]]", attr}
 
		if attr2 then
			table.insert(infl_parts, attr2)
	   	end
 
	   	table.insert(inflections, infl_parts)
	end
 
	-- Comparative and superlative forms
	if comp == "-" then
		table.insert(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(inflections, infl_parts)
 
		-- Superlative
		infl_parts = {label = "[[Appendix:Glossary#superlative|superlative]]", sup}
 
		if sup2 then
			table.insert(infl_parts, sup2)
		end
 
		table.insert(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"] = function(args, inflections, categories)
	local pres_part = args[1]; if pres_part == "" then pres_part = nil end
	local pres_part2 = args["pres2"]; if pres_part2 == "" then pres_part2 = nil end
	local past_part = args[2]; if past_part == "" then past_part = nil end
	local past_part2 = args["past2"]; if past_part2 == "" then past_part2 = nil end
	local sep = args["sep"]; if sep == "" then sep = nil end
 
	local stem = PAGENAME
 
	-- If separable, remove the prefix to create the stem
	if sep then
		stem = PAGENAME:gsub("^" .. sep, "")
		table.insert(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(categories, "Afrikaans irregular verbs")
	else
		forms["present"] = stem
		forms["pres_part"] = pres_part or stem .. "ende"
		forms["pres_part2"] = pres_part2
		forms["past_part"] = past_part or "ge" .. stem
		forms["past_part2"] = past_part2
	end
 
	-- Add the forms to the list
	if forms["present"] then
		forms["present"] = "[[".. forms["present"] .. (sep and "]] [[" .. sep or "") .. "]]"
		table.insert(inflections, {label = "present", forms["present"]})
	end
 
	if forms["pres_part"] then
		forms["pres_part"] = "[[" .. (sep or "") .. forms["pres_part"] .. "]]"
		local infl_parts = {label = "present participle", accel = "present-participle-form-of", forms["pres_part"]}
 
		if forms["pres_part2"] then
			forms["pres_part2"] = "[[" .. (sep or "") .. forms["pres_part2"] .. "]]"
 
			table.insert(infl_parts, forms["pres_part2"])
		end
 
		table.insert(inflections, infl_parts)
	end
 
	if forms["past"] then
		forms["past"] = "[[".. forms["past"] .. (sep and "]] [[" .. sep or "") .. "]]"
		local infl_parts = {label = "past", forms["past"]}
 
		if forms["past2"] then
			forms["past2"] = "[[" .. (sep or "") .. forms["past2"] .. "]]"
			table.insert(infl_parts, forms["past2"])
		end
 
		table.insert(inflections, infl_parts)
	end
 
	if forms["past_part"] then
		forms["past_part"] = "[[" .. (sep or "") .. forms["past_part"] .. "]]"
		local infl_parts = {label = "past participle", accel = "past-participle-form-of", forms["past_part"]}
 
		if forms["past_part2"] then
			forms["past_part2"] = "[[" .. (sep or "") .. forms["past_part2"] .. "]]"
			table.insert(infl_parts, forms["past_part2"])
		end
 
		if forms["past_part3"] then
			forms["past_part3"] = "[[" .. (sep or "") .. forms["past_part3"] .. "]]"
			table.insert(infl_parts, forms["past_part3"])
		end
 
		table.insert(inflections, infl_parts)
	end
end
 
irregular_verbs["dink"] = function(forms)
	forms["present"] = "dink"
	forms["pres_part"] = "denkende"
	forms["past"] = "dag"
	forms["past2"] = "dog"
	forms["past_part"] = "gedag"
	forms["past_part2"] = "gedog"
	forms["past_part3"] = "gedink"
end
 
irregular_verbs["hê"] = function(forms)
	forms["present"] = "het"
	forms["pres_part"] = "hebbende"
	forms["past"] = "had"
	forms["past_part"] = "gehad"
end
 
irregular_verbs["kan"] = function(forms)
	forms["present"] = "kan"
	forms["pres_part"] = nil
	forms["past"] = "kon"
	forms["past_part"] = nil
end
 
irregular_verbs["mag"] = function(forms)
	forms["present"] = "mag"
	forms["pres_part"] = nil
	forms["past"] = "mog"
	forms["past_part"] = nil
end
 
irregular_verbs["moet"] = function(forms)
	forms["present"] = "moet"
	forms["pres_part"] = nil
	forms["past"] = "moes"
	forms["past_part"] = nil
end
 
irregular_verbs["sal"] = function(forms)
	forms["present"] = "sal"
	forms["pres_part"] = nil
	forms["past"] = "sou"
	forms["past_part"] = nil
end
 
irregular_verbs["wees"] = function(forms)
	forms["present"] = "is"
	forms["pres_part"] = "synde"
	forms["past"] = "was"
	forms["past_part"] = "gewees"
end
 
irregular_verbs["weet"] = function(forms)
	forms["present"] = "weet"
	forms["pres_part"] = "wetende"
	forms["past"] = "wis"
	forms["past_part"] = "geweet"
end
 
irregular_verbs["wil"] = function(forms)
	forms["present"] = "wil"
	forms["pres_part"] = nil
	forms["past"] = "wou"
	forms["past_part"] = "gewil"
end
 
irregular_verbs["beter"] = function(forms)
	forms["present"] = "beter"
	forms["pres_part"] = nil
	forms["past"] = nil
	forms["past_part"] = nil
end
 
return export