local m_adj = require("Module:pt-adjectives")
local m_conj = require("Module:User:Jberkel/pt-conj")
local lang = require("Module:languages").getByCode("pt")
local export = {}
local pos_functions = {}
-- 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 poscat = frame.args or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local genders = {}
local inflections = {}
local categories = {lang:getCanonicalName() .. " " .. poscat}
local heads = {}
-- Call POS-specific function
if pos_functions then
pos_functions(args, heads, genders, inflections, categories)
end
if #heads == 0 then
heads = { args or "" }
end
return require("Module:headword").full_headword(lang, nil, heads, nil, genders, inflections, categories, nil)
end
-- Display additional inflection information for an adjective
pos_functions = function(args, heads, genders, inflections, categories)
local base = args or (mw.title.getCurrentTitle().nsText == "Template" and "{{{1}}}")
local infl_type = args or (mw.title.getCurrentTitle().nsText == "Template" and "o") or ""
if base == "-" then
table.insert(inflections, {nil, label="]", accel=""})
genders = {}
elseif infl_type == "" then
local f_sg = {args}
local m_pl = {args or args}
local f_pl = {args}
if #f_sg > 0 then
f_sg.label = "feminine singular"
f_sg.accel = "feminine-singular-form-of"
table.insert(inflections, f_sg)
end
if #f_pl == 0 or m_pl == f_pl then
m_pl.label = "plural"
m_pl.accel = "plural-form-of"
table.insert(inflections, m_pl)
else
m_pl.label = "masculine plural"
m_pl.accel = "masculine-plural-form-of"
table.insert(inflections, m_pl)
f_pl.label = "feminine plural"
f_pl.accel = "feminine-plural-form-of"
table.insert(inflections, f_pl)
end
else
if not m_adj.inflections then
error("Unknown inflection type '" .. infl_type .. "'")
end
if not base then error("Parameter 1 (base stem) may not be empty.") end
local data = {forms = {}, title = nil, categories = {}}
m_adj.inflections(args, base, data)
if data.forms == data.forms then
table.insert(genders, "m")
table.insert(genders, "f")
else
table.insert(genders, "m")
local f_sg = data.forms
f_sg.label = "feminine singular"
f_sg.accel = "feminine-singular-form-of"
table.insert(inflections, f_sg)
end
if data.forms == data.forms then
local pl = data.forms
pl.label = "plural"
pl.accel = "plural-form-of"
table.insert(inflections, pl)
else
local m_pl = data.forms
m_pl.label = "masculine plural"
m_pl.accel = "masculine-plural-form-of"
table.insert(inflections, m_pl)
local f_pl = data.forms
f_pl.label = "feminine plural"
f_pl.accel = "feminine-plural-form-of"
table.insert(inflections, f_pl)
end
if plural and not mw.title.new(plural).exists then
table.insert(categories, "Portuguese nouns with missing plurals")
end
if plural2 and not mw.title.new(plural2).exists then
table.insert(categories, "Portuguese nouns with missing plurals")
end
end
local comp = args
if comp == "no" then
table.insert(inflections, {label = "not ]"})
table.insert(categories, lang:getCanonicalName() .. " uncomparable adjectives")
elseif comp == "both" then
table.insert(inflections, {label = "sometimes ]"})
table.insert(categories, lang:getCanonicalName() .. " uncomparable adjectives")
else
table.insert(inflections, {label = "]"})
end
end
local function addVerbInflections(verb, inflections)
local first_pres_sing = verb.forms.indi.pres.sing
if first_pres_sing and #first_pres_sing > 0 then
table.insert(inflections, { label = "first-person singular present indicative", first_pres_sing })
end
if verb.forms.part_past then
table.insert(inflections, { label = "past participle", verb.forms.part_past.sing.m })
end
if verb.forms.short_part_past then
table.insert(inflections, { label = "short past participle", verb.forms.short_part_past.sing.m })
end
if verb.forms.long_part_past then
table.insert(inflections, { label = "long past participle", verb.forms.long_part_past.sing.m })
end
end
local function addVerbCategories(verb, categories)
if verb.abundant then table.insert(categories, lang:getCanonicalName() .. " abundant verbs") end
if verb.defective then table.insert(categories, lang:getCanonicalName() .. " defective verbs") end
if verb.irregular then table.insert(categories, lang:getCanonicalName() .. " irregular verbs") end
if verb.forms.short_part_past and verb.forms.long_part_past then
table.insert(categories, lang:getCanonicalName() .. " verbs with short and long past participle")
end
end
pos_functions = function(args, heads, genders, inflections, categories)
local beginning = args or ""
local ending = args or ""
local compound = args
local verb = m_conj.inflect(beginning, ending, compound)
if verb then
table.insert(heads, verb.forms.infn.impe)
addVerbCategories(verb, categories)
addVerbInflections(verb, inflections)
else
table.insert(categories, lang:getCanonicalName() .. " verbs needing inflection")
end
end
return export