local export = {}
local pos_functions = {}
local lang = require("Module:languages").getByCode("es")
local suffix_categories = {
["adjectives"] = true,
["adverbs"] = true,
["nouns"] = true,
["verbs"] = true,
}
-- 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"], genders = {}, inflections = {}, categories = {}}
if args["suff"] then
data.pos_category = "suffixes"
if suffix_categories[poscat] then
local singular_poscat = poscat:gsub("s$", "")
table.insert(data.categories, "Spanish " .. singular_poscat .. "-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 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, data)
end
}
-- Display additional inflection information for a noun
pos_functions["nouns"] = {
params = {
[1] = {},
[2] = {},
["pl2"] = {},
["f"] = {},
["fpl"] = {},
["m"] = {},
["m2"] = {},
["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 masculine2 = args["m2"]
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, masculine2})
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