Module:nl-headword

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:nl-headword/documentation. [edit]

This module is used for Dutch headword-line templates.

The module is always invoked the same way, by passing a single parameter to the "show" function. This parameter is the name of the part of speech, but in plural (examples given are for nouns, and for adjective forms respectively):

{{#invoke:nl-headword|show|nouns}}
{{#invoke:nl-headword|show|adjective forms}}

The template will, by default, accept the following parameters (specific parts of speech may accept or require others):

  • head= - Override the headword display, used to add links to individual words in a multi-word term.
  • cat= - Override the default category, which is the same as the provided parameter. This may sometimes be useful if you have a word that is really, say, an interjection, but you want it to show inflection as if it were an adjective.

There is no parameter for the sort key, because this is not necessary. The sort key is automatically generated according to the normal alphabetical ordering in Dutch.


local m_headword = require("Module:headword")
local m_utilities = require("Module:utilities")
 
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)
	local args = frame:getParent().args
	PAGENAME = mw.title.getCurrentTitle().text
 
	local head = args["head"]; if head == "" then head = nil end
 
	-- The part of speech. This is also the name of the category that
	-- entries go in. However, the two are separate (the "cat" parameter)
	-- because you sometimes want something to behave as an adjective without
	-- putting it in the adjectives category.
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	local cat = args["cat"]; if cat == "" then cat = nil end
 
	local genders = {}
	local inflections = {}
	local categories = {"Dutch " .. (cat or poscat)}
 
	if pos_functions[poscat] then
		pos_functions[poscat](args, genders, inflections, categories)
	end
 
	return
		m_headword.format_headword(head, lang, nil) ..
		m_headword.format_genders(genders, lang) ..
		m_headword.format_inflections(inflections, lang, nil) ..
		m_utilities.format_categories(categories, lang)
end
 
-- Display additional inflection information for an adjective
pos_functions["adjectives"] = function(args, genders, inflections, categories)
	local shift = 0
	local mode = args[1]
 
	if mode == "inv" then
		table.insert(inflections, {label = "[[Appendix:Glossary#invariable|invariable]]"})
		table.insert(categories, "Dutch invariable adjectives")
		shift = 1
	elseif mode == "pred" then
		table.insert(inflections, {label = "used only [[predicative]]ly"})
		table.insert(categories, "Dutch predicative-only adjectives")
		shift = 1
	end
 
	local comp_mode = args[1 + shift]
 
	if comp_mode == "-" then
		table.insert(inflections, {label = "not [[Appendix:Glossary#comparable|comparable]]"})
	else
		-- Gather parameters
		local comparatives = {label = "[[Appendix:Glossary#comparative|comparative]]"}
		local p = args[1 + shift]; if p == "" then p = nil end
		local i = 1
 
		while p do
			table.insert(comparatives, p)
			i = i + 1
			p = args["comp" .. i]; if p == "" then p = nil end
		end
 
		local superlatives = {label = "[[Appendix:Glossary#superlative|superlative]]"}
		local p = args[2 + shift]; if p == "" then p = nil end
		local i = 1
 
		while p do
			table.insert(superlatives, p)
			i = i + 1
			p = args["sup" .. i]; if p == "" then p = nil end
		end
 
		-- Generate forms if none were given
		if #comparatives == 0 then
			if mode == "inv" or mode == "pred" then
				table.insert(comparatives, "peri")
			else
				table.insert(comparatives, require("Module:nl-adjective").make_comparative(PAGENAME))
			end
		end
 
		if #superlatives == 0 then
			if mode == "inv" or mode == "pred" then
				table.insert(superlatives, "peri")
			else
				-- Add preferred periphrastic superlative, if necessary
				if
					PAGENAME:find("[iï]de$") or PAGENAME:find("[^eio]e$") or
					PAGENAME:find("s$") or PAGENAME:find("sch$") or PAGENAME:find("x$") or
					PAGENAME:find("sd$") or PAGENAME:find("st$") or PAGENAME:find("sk$") then
					table.insert(superlatives, "peri")
				end
 
				table.insert(superlatives, require("Module:nl-adjective").make_superlative(PAGENAME))
			end
		end
 
		-- Replace "peri" with phrase
		for key, val in ipairs(comparatives) do
			if val == "peri" then comparatives[key] = "[[meer]] " .. PAGENAME end
		end
 
		for key, val in ipairs(superlatives) do
			if val == "peri" then superlatives[key] = "[[meest]] " .. PAGENAME end
		end
 
		table.insert(inflections, comparatives)
		table.insert(inflections, superlatives)
	end
end
 
-- Display additional inflection information for an adverb
pos_functions["adverbs"] = function(args, genders, inflections, categories)
	local comp = args[1]; if comp == "" then comp = nil end
	local sup = args[2]; if sup == "" then sup = nil end
 
	if comp then
		if not sup then
			sup = PAGENAME .. "st"
		end
 
		table.insert(inflections, {label = "[[Appendix:Glossary#comparative|comparative]]", comp})
		table.insert(inflections, {label = "[[Appendix:Glossary#superlative|superlative]]", sup})
	end
end
 
-- Display information for a noun's gender
-- This is separate so that it can also be used for proper nouns
function noun_gender(args, genders, inflections, categories)
	-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
	local g = args[1]; if g == "" then g = nil end
	local i = 2
 
	while g do
		if g == "c" then
			table.insert(categories, "Dutch nouns with common gender")
		elseif g == "p" then
			table.insert(categories, "Dutch pluralia tantum")
		elseif g ~= "m" and g ~= "f" and g ~= "n" then
			g = nil
		end
 
		table.insert(genders, g)
		g = args["g" .. i]; if g == "" then g = nil end
		i = i + 1
	end
 
	if #genders == 0 then
		table.insert(genders, "?")
	end
 
	-- Most nouns that are listed as f+m should really have only f
	if genders[1] == "f" and genders[2] == "m" then
		table.insert(categories, "Dutch nouns with f+m gender")
	end
end
 
pos_functions["proper nouns"] = function(args, genders, inflections, categories)
	noun_gender(args, genders, inflections, categories)
end
 
-- Display additional inflection information for a noun
pos_functions["nouns"] = function(args, genders, inflections, categories)
	noun_gender(args, genders, inflections, categories)
 
	-- Gather all the plural parameters
	local plurals = {}
	local p = args[2]; if p == "" then p = nil end
	local i = 2
 
	while p do
		table.insert(plurals, p)
 
		p = args["pl" .. i]; if p == "" then p = nil end
		i = i + 1
	end
 
	-- Gather all the diminutive parameters
	local diminutives = {}
	local p = args[3]; if p == "" then p = nil end
	local i = 2
 
	while p do
		table.insert(diminutives, p)
 
		p = args["dim" .. i]; if p == "" then p = nil end
		i = i + 1
	end
 
	-- Gather all the feminine parameters
	local feminines = {}
	local p = args["f"]; if p == "" then p = nil end
	local i = 2
 
	while p do
		table.insert(feminines, p)
 
		p = args["f" .. i]; if p == "" then p = nil end
		i = i + 1
	end
 
	-- Gather all the masculine parameters
	local masculines = {}
	local p = args["m"]; if p == "" then p = nil end
	local i = 2
 
	while p do
		table.insert(masculines, p)
 
		p = args["m" .. i]; if p == "" then p = nil end
		i = i + 1
	end
 
	-- Plural
	if genders[1] == "p" then
		table.insert(inflections, {label = "[[Appendix:Glossary#plurale tantum|plurale tantum]]"})
	elseif #plurals == 0 then
		table.insert(inflections, "<small><sup>???</sup> please provide the plural!</small>")
		table.insert(categories, "Dutch nouns needing inflection")
	elseif plurals[1] == "-" then
		table.insert(inflections, {label = "[[Appendix:Glossary#uncountable|uncountable]]"})
		table.insert(categories, "Dutch uncountable nouns")
	else
		local generated = generate_plurals(PAGENAME)
 
		-- Process the plural forms
		for i, p in ipairs(plurals) do
			-- Is this a shortcut form?
			if p:sub(1,1) == "-" then
				if not generated[p] then
					error("The shortcut plural " .. p .. " could not be generated.")
				end
 
				if p:sub(-2) == "es" then
					table.insert(categories, "Dutch nouns with plural in -es")
				elseif p:sub(-1) == "s" then
					table.insert(categories, "Dutch nouns with plural in -s")
				elseif p:sub(-4) == "eren" then
					table.insert(categories, "Dutch nouns with plural in -eren")
				else
					table.insert(categories, "Dutch nouns with plural in -en")
				end
 
				if p:sub(2,2) == ":" then
					table.insert(categories, "Dutch nouns with lengthened vowel in the plural")
				end
 
				p = generated[p]
			-- Not a shortcut form, but the plural form specified directly.
			else
				local matches = {}
 
				for pi, g in pairs(generated) do
					if g == p then
						table.insert(matches, pi)
					end
				end
 
				if #matches > 0 then
					table.insert(categories, "nl-noun plural matches generated form")
				elseif not PAGENAME:find("[ -]") then
					if p == PAGENAME then
						table.insert(categories, "Dutch invariable nouns")
					elseif
						p == PAGENAME .. "den" or p == PAGENAME:gsub("ee$", "eden") or
						p == PAGENAME .. "des" or p == PAGENAME:gsub("ee$", "edes") then
						table.insert(categories, "Dutch nouns with plural in -den")
					elseif p == PAGENAME:gsub("([ao])$", "%1%1ien") or p == PAGENAME:gsub("oe$", "oeien") then
						table.insert(categories, "Dutch nouns with glide vowel in plural")
					elseif p == PAGENAME:gsub("y$", "ies") then
						table.insert(categories, "Dutch nouns with English plurals")
					elseif
						p == PAGENAME:gsub("a$", "ae") or
						p == PAGENAME:gsub("[ei]x$", "ices") or
						p == PAGENAME:gsub("is$", "es") or
						p == PAGENAME:gsub("men$", "mina") or
						p == PAGENAME:gsub("ns$", "ntia") or
						p == PAGENAME:gsub("o$", "ones") or
						p == PAGENAME:gsub("o$", "onen") or
						p == PAGENAME:gsub("s$", "tes") or
						p == PAGENAME:gsub("us$", "era") or
						p == mw.ustring.gsub(PAGENAME, "[uü]s$", "i") or
						p == mw.ustring.gsub(PAGENAME, "[uü]m$", "a") or
						p == PAGENAME:gsub("x$", "ges") then
						table.insert(categories, "Dutch nouns with Latin plurals")
					elseif
						p == PAGENAME:gsub("os$", "oi") or
						p == PAGENAME:gsub("on$", "a") or
						p == PAGENAME:gsub("a$", "ata") then
						table.insert(categories, "Dutch nouns with Greek plurals")
					else
						table.insert(categories, "Dutch irregular nouns")
					end
				end
			end
 
			plurals[i] = p
		end
 
		-- Add the plural forms
		plurals.label = "plural"
		plurals.accel = "plural-form-of"
		table.insert(inflections, plurals)
	end
 
	-- Add the diminutive forms
	if diminutives[1] == "-" then
		-- do nothing
	elseif #diminutives == 0 then
		table.insert(inflections, "<small><sup>???</sup> please provide the [[Appendix:Glossary#diminutive|diminutive]]!</small>")
		table.insert(categories, "Dutch nouns needing inflection")
	else
		-- Process the diminutive forms
		for i, p in ipairs(diminutives) do
			diminutives[i] = {term = p, genders = {"n"}}
		end
 
		diminutives.label = "[[Appendix:Glossary#diminutive|diminutive]]"
		diminutives.accel = "diminutive-form-of"
		table.insert(inflections, diminutives)
	end
 
	-- Add the feminine forms
	if #feminines > 0 then
		feminines.label = "feminine"
		table.insert(inflections, feminines)
	end
 
	-- Add the masculine forms
	if #masculines > 0 then
		masculines.label = "masculine"
		table.insert(inflections, masculines)
	end
end
 
function generate_plurals(PAGENAME)
	local m_common = require("Module:nl-common")
	local generated = {}
 
	generated["-s"] = PAGENAME .. "s"
	generated["-'s"] = PAGENAME .. "'s"
 
	local stem_FF = m_common.add_e(PAGENAME, false, false)
	local stem_TF = m_common.add_e(PAGENAME, true, false)
	local stem_FT = m_common.add_e(PAGENAME, false, true)
 
	generated["-es"] = stem_FF .. "s"
	generated["-@es"] = stem_TF .. "s"
	generated["-:es"] = stem_FT .. "s"
 
	generated["-en"] = stem_FF .. "n"
	generated["-@en"] = stem_TF .. "n"
	generated["-:en"] = stem_FT .. "n"
 
	generated["-eren"] = m_common.add_e(PAGENAME .. (PAGENAME:find("n$") and "d" or ""), false, false) .. "ren"
	generated["-:eren"] = stem_FT .. "ren"
 
	if PAGENAME:find("f$") then
		local stem = PAGENAME:gsub("f$", "v")
		local stem_FF = m_common.add_e(stem, false, false)
		local stem_TF = m_common.add_e(stem, true, false)
		local stem_FT = m_common.add_e(stem, false, true)
 
		generated["-ves"] = stem_FF .. "s"
		generated["-@ves"] = stem_TF .. "s"
		generated["-:ves"] = stem_FT .. "s"
 
		generated["-ven"] = stem_FF .. "n"
		generated["-@ven"] = stem_TF .. "n"
		generated["-:ven"] = stem_FT .. "n"
 
		generated["-veren"] = stem_FF .. "ren"
		generated["-:veren"] = stem_FT .. "ren"
	elseif PAGENAME:find("s$") then
		local stem = PAGENAME:gsub("s$", "z")
		local stem_FF = m_common.add_e(stem, false, false)
		local stem_TF = m_common.add_e(stem, true, false)
		local stem_FT = m_common.add_e(stem, false, true)
 
		generated["-zes"] = stem_FF .. "s"
		generated["-@zes"] = stem_TF .. "s"
		generated["-:zes"] = stem_FT .. "s"
 
		generated["-zen"] = stem_FF .. "n"
		generated["-@zen"] = stem_TF .. "n"
		generated["-:zen"] = stem_FT .. "n"
 
		generated["-zeren"] = stem_FF .. "ren"
		generated["-:zeren"] = stem_FT .. "ren"
	elseif PAGENAME:find("heid$") then
		generated["-heden"] = PAGENAME:gsub("heid$", "heden")
	end
 
	return generated
end
 
pos_functions["past participles"] = function(args, genders, inflections, categories)
	if args[1] == "-" then
		table.insert(inflections, {label = "not used adjectivally"})
		table.insert(categories, "Dutch non-adjectival past participles")
	end
end
 
pos_functions["verbs"] = function(args, genders, inflections, categories)
	local past_sg = args[1]; if past_sg == "" then past_sg = nil end
	local past_ptc = args[2]; if past_ptc == "" then past_ptc = nil end
	local is_plural = args["pl"]; if is_plural == "" then is_plural = nil end  -- Used for reciprocal verbs (with "elkaar"), which can only be conjugated in plural
 
	-- Past singular
	if past_sg == "-" then
		table.insert(inflections, {label = "not inflected"})
		table.insert(categories, "Dutch uninflected verbs")
	elseif not past_sg then
		table.insert(inflections, "<small><sup>???</sup> please provide the past " .. (is_plural and "plural" or "singular") .. "!</small>")
		table.insert(categories, "Dutch verbs needing inflection")
	else
		local infl_parts = {label = "past " .. (is_plural and "plural" or "singular")}
		local past_sg2 = args["past_sg2"]; if past_sg2 == "" then past_sg2 = nil end
 
		table.insert(infl_parts, past_sg)
 
		if past_sg2 then
			table.insert(infl_parts, past_sg2)
		end
 
		table.insert(inflections, infl_parts)
	end
 
	-- Past participle
	if past_ptc == "-" then
		table.insert(inflections, {label = "no past participle"})
	elseif not past_ptc then
		table.insert(inflections, "<small><sup>???</sup> please provide the past participle!</small>")
		table.insert(categories, "Dutch verbs needing inflection")
	else
		local infl_parts = {label = "past participle"}
		local past_ptc2 = args["past_ptc2"]; if past_ptc2 == "" then past_ptc2 = nil end
 
		table.insert(infl_parts, past_ptc)
 
		if past_ptc2 then
			table.insert(infl_parts, past_ptc2)
		end
 
		table.insert(inflections, infl_parts)
	end
end
 
return export