Module:es-headword

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
This module is used for Spanish 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:es-headword|show|nouns}}
{{#invoke:es-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. (for example, benvingut).

There is no parameter for the sort key, because this is not necessary. The sort key is automatically generated by Module:utilities, according to the normal alphabetical ordering in Spanish (encoded in Module:languages/data2).


local export = {}
local pos_functions = {}
 
local lang = require("Module:languages").getByCode("es")
 
-- 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 = {heads = args["head"], genders = {}, inflections = {}, categories = {}}
 
	if args["suff"] then
		table.insert(data.categories, lang:getCanonicalName() .. " 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
	else
		table.insert(data.categories, lang:getCanonicalName() .. " " .. poscat)
	end
 
	if pos_functions[poscat] then
		pos_functions[poscat].func(args, data)
	end
 
	return require("Module:headword").full_headword(lang, nil, data.heads, nil, data.genders, data.inflections, data.categories, nil)
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, data)
	local categories = {}
 
	local gender = args[1]
 
	if gender == "m-p" or gender == "f-p" then
		table.insert(data.categories, "Spanish pluralia tantum")
	end
 
	if gender == "mf" then
		table.insert(data.genders, "m")
		table.insert(data.genders, "f")
	else
		table.insert(data.genders, gender)
	end
 
	if #data.genders == 0 then
		table.insert(data.genders, "?")
	end
end
 
pos_functions["proper nouns"] = {
	params = {
		[1] = {},
		},
	func = function(args, data)
		noun_gender(args, genders, inflections, categories)
	end
}
 
-- Display additional inflection information for a noun
pos_functions["nouns"] = {
	params = {
		[1] = {},
		[2] = {},
		["pl2"] = {},
		["f"] = {},
		["fpl"] = {},
		["m"] = {},
		["mpl"] = {},
		},
	func = function(args, data)
		noun_gender(args, data)
 
		-- Plural
		if data.genders[1] == "m-p" or data.genders[1] == "f-p" then
			table.insert(data.inflections, {label = "[[Appendix:Glossary#plurale tantum|plurale tantum]]"})
		else
			local plural = args[2]
 
			if plural == "-" then
				table.insert(data.inflections, {label = "[[Appendix:Glossary#uncountable|uncountable]]"})
				table.insert(data.categories, "Spanish uncountable nouns")
			else
				local infl_parts = {label = "plural", accel = "plural-form-of"}
				local plural2 = args["pl2"]
 
				if not plural or plural == "s" then
					plural = PAGENAME .. "s"
				elseif plural == "es" then
					plural = PAGENAME .. "es"
				end
 
				table.insert(infl_parts, plural)
 
				if plural2 then
					table.insert(infl_parts, plural2)
				end
 
				if plural and not mw.title.new(plural).exists then
					table.insert(data.categories, "Spanish nouns with missing plurals")
				end
				if plural2 and not mw.title.new(plural2).exists then
					table.insert(data.categories, "Spanish nouns with missing plurals")
				end
 
				table.insert(data.inflections, infl_parts)
			end
		end
 
		-- Gendered forms
		local feminine = args["f"]
		local feminine_pl = args["fpl"]
		local masculine = args["m"]
		local masculine_pl = args["mpl"]
 
		if feminine then
			table.insert(data.inflections, {label = "feminine", feminine})
			if not mw.title.new(feminine).exists then
				table.insert(data.categories, "Missing Spanish noun forms")
			end
		end
		if feminine_pl then
			table.insert(data.inflections, {label = "feminine plural", feminine_pl})
			if not mw.title.new(feminine_pl).exists then
				table.insert(data.categories, "Missing Spanish noun forms")
			end
		end
 
		if masculine then
			table.insert(data.inflections, {label = "masculine", masculine})
			if not mw.title.new(masculine).exists then
				table.insert(data.categories, "Missing Spanish noun forms")
			end
		end
		if masculine_pl then
			table.insert(data.inflections, {label = "masculine plural", masculine_pl})
			if not mw.title.new(masculine_pl).exists then
				table.insert(data.categories, "Missing Spanish noun forms")
			end
		end
	end
}
 
function make_plural(base, gender)
	return base .. "s"
end
 
return export