Module:Pt-adjectives

Frae Wikipedia, the free beuk o knawledge
local m_utilities = require("Module:utilities")
local m_links = require("Module:links")

local lang = require("Module:languages").getByCode("pt")

local export = {}

-- Functions that do the actual inflecting by creating the forms of a basic term.
local inflections = {}

-- 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
	local base = args[1] or (mw.title.getCurrentTitle().nsText == "Template" and "{{{1}}}"); if not base then error("Parameter 1 (base stem) may not be empty.") end
	local infl_type = args[2] or (mw.title.getCurrentTitle().nsText == "Template" and "o") or ""; if infl_type == "" then error("Parameter 2 (inflection type) may not be empty.") end
	
	if not inflections[infl_type] then
		error("Unknown inflection type '" .. infl_type .. "'")
	end
	
	local data = {forms = {}, title = nil, categories = {}}
	
	-- Generate the forms
	inflections[infl_type](args, base, data)
	
	-- Postprocess
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end

function postprocess(args, data)
	data.forms["comp_m_sg"] = {"[[mais]] " .. data.forms["m_sg"][1]}
	data.forms["comp_f_sg"] = {"[[mais]] " .. data.forms["f_sg"][1]}
	data.forms["comp_m_pl"] = {"[[mais]] " .. data.forms["m_pl"][1]}
	data.forms["comp_f_pl"] = {"[[mais]] " .. data.forms["f_pl"][1]}
	
	table.insert(data.forms["sup_m_sg"], 1, "[[o|o]] [[mais|mais]] " .. data.forms["m_sg"][1])
	table.insert(data.forms["sup_f_sg"], 1, "[[a|a]] [[mais|mais]] " .. data.forms["f_sg"][1])
	table.insert(data.forms["sup_m_pl"], 1, "[[os|os]] [[mais|mais]] " .. data.forms["m_pl"][1])
	table.insert(data.forms["sup_f_pl"], 1, "[[as|as]] [[mais|mais]] " .. data.forms["f_pl"][1])
	
	local aug = args["aug"]; if aug == "" then aug = nil end
	local dim = args["dim"]; if dim == "" then dim = nil end
	
	if not aug then
		for key, val in pairs(data.forms) do
			if key:find("aug") then
				data.forms[key] = nil
			end
		end
	end
	
	if not dim then
		for key, val in pairs(data.forms) do
			if key:find("dim") then
				data.forms[key] = nil
			end
		end
	end
end


-- Inflection functions

local function add_form(forms, key, form)
	if not forms[key] then
		forms[key] = {}
	end
	
	table.insert(forms[key], form)
end

local function make_superlative(data, base, base_f)
	base_f = base_f or base
	add_form(data.forms, "sup_m_sg", base .. "íssimo")
	add_form(data.forms, "sup_f_sg", base_f .. "íssima")
	add_form(data.forms, "sup_m_pl", base .. "íssimos")
	add_form(data.forms, "sup_f_pl", base_f .. "íssimas")
end

local function make_augmentative(data, base, base_f)
	base_f = base_f or base
	add_form(data.forms, "aug_m_sg", base .. "ão")
	add_form(data.forms, "aug_f_sg", base_f .. "ona")
	add_form(data.forms, "aug_m_pl", base .. "ões")
	add_form(data.forms, "aug_f_pl", base_f .. "onas")
end

local function make_diminutive(data, base, base_f)
	base_f = base_f or base
	add_form(data.forms, "dim_m_sg", base .. "inho")
	add_form(data.forms, "dim_f_sg", base_f .. "inha")
	add_form(data.forms, "dim_m_pl", base .. "inhos")
	add_form(data.forms, "dim_f_pl", base_f .. "inhas")
end

local function make_diminutive_a(data, base, base_f)
	base_f = base_f or base
	add_form(data.forms, "dim_m_sg", base .. "inha")
	add_form(data.forms, "dim_f_sg", base_f .. "inha")
	add_form(data.forms, "dim_m_pl", base .. "inhas")
	add_form(data.forms, "dim_f_pl", base_f .. "inhas")
end

inflections["a"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "a")
	add_form(data.forms, "f_sg", base .. "a")
	add_form(data.forms, "m_pl", base .. "as")
	add_form(data.forms, "f_pl", base .. "as")
	
	make_superlative(data, base)
	make_augmentative(data, base)
	make_diminutive_a(data, base)
end

inflections["ca"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ca")
	add_form(data.forms, "f_sg", base .. "ca")
	add_form(data.forms, "m_pl", base .. "cas")
	add_form(data.forms, "f_pl", base .. "cas")
	
	make_superlative(data, base .. "qu")
	make_augmentative(data, base .. "c")
	make_diminutive(data, base .. "qu")
end

inflections["e"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "e")
	add_form(data.forms, "f_sg", base .. "e")
	add_form(data.forms, "m_pl", base .. "es")
	add_form(data.forms, "f_pl", base .. "es")
	
	make_superlative(data, base)
	make_augmentative(data, base)
	make_diminutive(data, base)
end

inflections["l"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "l")
	add_form(data.forms, "f_sg", base .. "l")
	add_form(data.forms, "m_pl", base .. "is")
	add_form(data.forms, "f_pl", base .. "is")
	
	make_superlative(data, base .. "l")
	make_augmentative(data, base .. "l")
	make_diminutive(data, base .. "l")
end

inflections["m"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "m")
	add_form(data.forms, "f_sg", base .. "m")
	add_form(data.forms, "m_pl", base .. "ns")
	add_form(data.forms, "f_pl", base .. "ns")
	
	make_superlative(data, base .. "m")
	make_augmentative(data, base .. "m")
	make_diminutive(data, base .. "m")
end

inflections["z"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "z")
	add_form(data.forms, "f_sg", base .. "z")
	add_form(data.forms, "m_pl", base .. "zes")
	add_form(data.forms, "f_pl", base .. "zes")
	
	make_superlative(data, base .. "c")
	make_augmentative(data, base .. "z")
	make_diminutive(data, base .. "z")
end

inflections["al"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "al")
	add_form(data.forms, "f_sg", base .. "al")
	add_form(data.forms, "m_pl", base .. "ais")
	add_form(data.forms, "f_pl", base .. "ais")
	
	make_superlative(data, base .. "al")
	make_augmentative(data, base .. "al")
	make_diminutive(data, base .. "al")
end

inflections["ável"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ável")
	add_form(data.forms, "f_sg", base .. "ável")
	add_form(data.forms, "m_pl", base .. "áveis")
	add_form(data.forms, "f_pl", base .. "áveis")
	
	make_superlative(data, base .. "abil")
	make_augmentative(data, base .. "abil")
	make_diminutive(data, base .. "abil")
end

inflections["ímico"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ímico")
	add_form(data.forms, "f_sg", base .. "ímica")
	add_form(data.forms, "m_pl", base .. "ímicos")
	add_form(data.forms, "f_pl", base .. "ímicas")
	
	make_superlative(data, base .. "qu")
	make_augmentative(data, base .. "c")
	make_diminutive(data, base .. "qu")
end

inflections["ível"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ível")
	add_form(data.forms, "f_sg", base .. "ível")
	add_form(data.forms, "m_pl", base .. "íveis")
	add_form(data.forms, "f_pl", base .. "íveis")
	
	make_superlative(data, base .. "ibil")
	make_augmentative(data, base .. "ibil")
	make_diminutive(data, base .. "ibil")
end

inflections["incrível"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "incrível")
	add_form(data.forms, "f_sg", base .. "incrível")
	add_form(data.forms, "m_pl", base .. "incríveis")
	add_form(data.forms, "f_pl", base .. "incríveis")
	
	make_superlative(data, base .. "incredibil")
	make_augmentative(data, base .. "incredibil")
	make_diminutive(data, base .. "incredibil")
end

inflections["il"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "il")
	add_form(data.forms, "f_sg", base .. "il")
	add_form(data.forms, "m_pl", base .. "is")
	add_form(data.forms, "f_pl", base .. "is")
	
	make_superlative(data, base .. "il")
	make_augmentative(data, base .. "il")
	make_diminutive(data, base .. "il")
end

inflections["ágico"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ágico")
	add_form(data.forms, "f_sg", base .. "ágica")
	add_form(data.forms, "m_pl", base .. "ágicos")
	add_form(data.forms, "f_pl", base .. "ágicas")
	
	make_superlative(data, base .. "agiqu")
	make_augmentative(data, base .. "agic")
	make_diminutive(data, base .. "agiqu")
end

inflections["ágil"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ágil")
	add_form(data.forms, "f_sg", base .. "ágil")
	add_form(data.forms, "m_pl", base .. "ágeis")
	add_form(data.forms, "f_pl", base .. "ágeis")
	
	make_superlative(data, base .. "agil")
	make_augmentative(data, base .. "agil")
	make_diminutive(data, base .. "agil")
end

inflections["ão"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ão")
	add_form(data.forms, "f_sg", base .. "ona")
	add_form(data.forms, "m_pl", base .. "ões")
	add_form(data.forms, "f_pl", base .. "onas")
	
	make_superlative(data, base .. "on")
	make_augmentative(data, base .. "on")
	make_diminutive(data, base .. "on")
end

inflections["o"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "o")
	add_form(data.forms, "f_sg", base .. "a")
	add_form(data.forms, "m_pl", base .. "os")
	add_form(data.forms, "f_pl", base .. "as")
	
	make_superlative(data, base)
	make_augmentative(data, base)
	make_diminutive(data, base)
end

inflections["co"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "co")
	add_form(data.forms, "f_sg", base .. "ca")
	add_form(data.forms, "m_pl", base .. "cos")
	add_form(data.forms, "f_pl", base .. "cas")
	
	make_superlative(data, base .. "qu")
	make_augmentative(data, base .. "c")
	make_diminutive(data, base .. "qu")
end

inflections["co2"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "co")
	add_form(data.forms, "f_sg", base .. "ca")
	add_form(data.forms, "m_pl", base .. "cos")
	add_form(data.forms, "f_pl", base .. "cas")
	
	make_superlative(data, base .. "c")
	make_superlative(data, base .. "qu")
	make_augmentative(data, base .. "c")
	make_diminutive(data, base .. "qu")
end

inflections["ógico"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ógico")
	add_form(data.forms, "f_sg", base .. "ógica")
	add_form(data.forms, "m_pl", base .. "ógicos")
	add_form(data.forms, "f_pl", base .. "ógicas")
	
	make_superlative(data, base .. "ogiqu")
	make_augmentative(data, base .. "ogic")
	make_diminutive(data, base .. "ogiqu")
end

inflections["ítmico"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ítmico")
	add_form(data.forms, "f_sg", base .. "ítmica")
	add_form(data.forms, "m_pl", base .. "ítmicos")
	add_form(data.forms, "f_pl", base .. "ítmicas")
	
	make_superlative(data, base .. "itmiqu")
	make_augmentative(data, base .. "itmic")
	make_diminutive(data, base .. "itmiqu")
end

inflections["áfico"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "áfico")
	add_form(data.forms, "f_sg", base .. "áfica")
	add_form(data.forms, "m_pl", base .. "áficos")
	add_form(data.forms, "f_pl", base .. "áficas")
	
	make_superlative(data, base .. "afic")
	make_augmentative(data, base .. "afic")
	make_diminutive(data, base .. "afic")
end

inflections["ático"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ático")
	add_form(data.forms, "f_sg", base .. "ática")
	add_form(data.forms, "m_pl", base .. "áticos")
	add_form(data.forms, "f_pl", base .. "áticas")
	
	make_superlative(data, base .. "atic")
	make_augmentative(data, base .. "atic")
	make_diminutive(data, base .. "atic")
end

inflections["ático2"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ático")
	add_form(data.forms, "f_sg", base .. "ática")
	add_form(data.forms, "m_pl", base .. "áticos")
	add_form(data.forms, "f_pl", base .. "áticas")
	
	make_superlative(data, base .. "atic")
	make_superlative(data, base .. "atiqu")
	make_augmentative(data, base .. "atic")
	make_diminutive(data, base .. "atic")
end

inflections["ítico"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ítico")
	add_form(data.forms, "f_sg", base .. "ítica")
	add_form(data.forms, "m_pl", base .. "íticos")
	add_form(data.forms, "f_pl", base .. "íticas")
	
	make_superlative(data, base .. "itic")
	make_augmentative(data, base .. "itic")
	make_diminutive(data, base .. "itic")
end

inflections["ótico"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ótico")
	add_form(data.forms, "f_sg", base .. "ótica")
	add_form(data.forms, "m_pl", base .. "óticos")
	add_form(data.forms, "f_pl", base .. "óticas")
	
	make_superlative(data, base .. "otic")
	make_augmentative(data, base .. "otic")
	make_diminutive(data, base .. "otic")
end

inflections["ástico"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ástico")
	add_form(data.forms, "f_sg", base .. "ástica")
	add_form(data.forms, "m_pl", base .. "ásticos")
	add_form(data.forms, "f_pl", base .. "ásticas")
	
	make_superlative(data, base .. "astiqu")
	make_augmentative(data, base .. "astic")
	make_diminutive(data, base .. "astiqu")
end

inflections["ácido"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ácido")
	add_form(data.forms, "f_sg", base .. "ácida")
	add_form(data.forms, "m_pl", base .. "ácidos")
	add_form(data.forms, "f_pl", base .. "ácidas")
	
	make_superlative(data, base .. "acid")
	make_augmentative(data, base .. "acid")
	make_diminutive(data, base .. "acid")
end

inflections["tímido"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "tímido")
	add_form(data.forms, "f_sg", base .. "tímida")
	add_form(data.forms, "m_pl", base .. "tímidos")
	add_form(data.forms, "f_pl", base .. "tímidas")
	
	make_superlative(data, base .. "timid")
	make_augmentative(data, base .. "timid")
	make_diminutive(data, base .. "timid")
end

inflections["ítido"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ítido")
	add_form(data.forms, "f_sg", base .. "ítida")
	add_form(data.forms, "m_pl", base .. "ítidos")
	add_form(data.forms, "f_pl", base .. "ítidas")
	
	make_superlative(data, base .. "itid")
	make_augmentative(data, base .. "itid")
	make_diminutive(data, base .. "itid")
end

inflections["go"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "go")
	add_form(data.forms, "f_sg", base .. "ga")
	add_form(data.forms, "m_pl", base .. "gos")
	add_form(data.forms, "f_pl", base .. "gas")
	
	make_superlative(data, base .. "gu")
	make_augmentative(data, base .. "g")
	make_diminutive(data, base .. "gu")
end

inflections["ério"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ério")
	add_form(data.forms, "f_sg", base .. "éria")
	add_form(data.forms, "m_pl", base .. "érios")
	add_form(data.forms, "f_pl", base .. "érias")
	
	make_superlative(data, base .. "er")
	make_superlative(data, base .. "eri")
	make_augmentative(data, base .. "erioz", base .. "eriaz")
	make_diminutive(data, base .. "erioz", base .. "eriaz")
end

inflections["frio"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "frio")
	add_form(data.forms, "f_sg", base .. "fria")
	add_form(data.forms, "m_pl", base .. "frios")
	add_form(data.forms, "f_pl", base .. "frias")
	
	make_superlative(data, base .. "fri")
	make_superlative(data, base .. "frigid")
	make_augmentative(data, base .. "fri")
	make_diminutive(data, base .. "frioz")
	make_diminutive(data, base .. "fri")
end

inflections["r"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "r")
	add_form(data.forms, "f_sg", base .. "r")
	add_form(data.forms, "m_pl", base .. "res")
	add_form(data.forms, "f_pl", base .. "res")
	
	make_superlative(data, base .. "r")
	make_augmentative(data, base .. "r")
	make_diminutive(data, base .. "r")
end

inflections["ar"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ar")
	add_form(data.forms, "f_sg", base .. "ar")
	add_form(data.forms, "m_pl", base .. "ares")
	add_form(data.forms, "f_pl", base .. "ares")
	
	make_superlative(data, base .. "ar")
	make_augmentative(data, base .. "ar")
	make_diminutive(data, base .. "ar")
end

inflections["or"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "or")
	add_form(data.forms, "f_sg", base .. "ora")
	add_form(data.forms, "m_pl", base .. "ores")
	add_form(data.forms, "f_pl", base .. "oras")
	
	make_superlative(data, base .. "or")
	make_augmentative(data, base .. "or")
	make_diminutive(data, base .. "or")
end

inflections["ôr"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ôr")
	add_form(data.forms, "f_sg", base .. "ôra")
	add_form(data.forms, "m_pl", base .. "ôres")
	add_form(data.forms, "f_pl", base .. "ôras")
	
	make_superlative(data, base .. "ôr")
	make_augmentative(data, base .. "ôr")
	make_diminutive(data, base .. "ôr")
end

inflections["ês"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ês")
	add_form(data.forms, "f_sg", base .. "esa")
	add_form(data.forms, "m_pl", base .. "eses")
	add_form(data.forms, "f_pl", base .. "esas")
	
	make_superlative(data, base .. "es")
	make_augmentative(data, base .. "es")
	make_diminutive(data, base .. "es")
end

inflections["eu"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "eu")
	add_form(data.forms, "f_sg", base .. "eia")
	add_form(data.forms, "m_pl", base .. "eus")
	add_form(data.forms, "f_pl", base .. "eias")
	
	make_superlative(data, base .. "euz")
	make_augmentative(data, base .. "euz")
	make_diminutive(data, base .. "euz")
end

inflections["ez"] = function(args, base, data)
	add_form(data.forms, "m_sg", base .. "ez")
	add_form(data.forms, "f_sg", base .. "eza")
	add_form(data.forms, "m_pl", base .. "ezes")
	add_form(data.forms, "f_pl", base .. "ezas")
	
	make_superlative(data, base .. "ez")
	make_augmentative(data, base .. "ez")
	make_diminutive(data, base .. "ez")
end


-- Make the table
function make_table(data)
	local function show_form(form)
		if not form then
			return "—"
		elseif type(form) ~= "table" then
			error("a non-table value was given in the list of inflected forms.")
		end
		
		local ret = {}
		
		for key, subform in ipairs(form) do
			table.insert(ret, m_links.full_link({lang = lang, term = subform}))
		end
		
		return table.concat(ret, "<br/>")
	end
	
	local function repl(param)
		if param == "lemma" then
			return m_links.full_link({lang = lang, alt = mw.title.getCurrentTitle().text}, "term")
		elseif param == "info" then
			return data.title and " (" .. data.title .. ")" or ""
		else
			return show_form(data.forms[param])
		end
	end
	
	local wikicode = [=[<div class="NavFrame" style="clear:both; white-space: nowrap; max-width: 50em">
<div class="NavHead">Inflection of {{{lemma}}}{{{info}}}</div>
<div class="NavContent">
{| style="border: 1px solid #999999; width: 100%; background:#F6F6F6;" cellpadding="3" cellspacing="0" class="inflection-table"
|-
! style="border: 1px solid #999999; background:#B0B0B0" rowspan="2" |
! style="border: 1px solid #999999; background:#D0D0D0" colspan="2" | seengular
! style="border: 1px solid #999999; background:#D0D0D0" colspan="2" | plural
|-
! style="border: 1px solid #999999; background:#D0D0D0; width:21%" | masculine
! style="border: 1px solid #999999; background:#D0D0D0; width:21%" | feminine
! style="border: 1px solid #999999; background:#D0D0D0; width:21%" | masculine
! style="border: 1px solid #999999; background:#D0D0D0; width:21%" | feminine
|- 
! style="border: 1px solid #999999; background:#b0bfd4" | [[Appendix:Glossary#positive|positive]]
| style="border: 1px solid #999999;" valign="top" | {{{m_sg}}}
| style="border: 1px solid #999999;" valign="top" | {{{f_sg}}}
| style="border: 1px solid #999999;" valign="top" | {{{m_pl}}}
| style="border: 1px solid #999999;" valign="top" | {{{f_pl}}}
|-
! style="border: 1px solid #999999; background:#b0bfd4" | [[Appendix:Glossary#comparative|comparative]]
| style="border: 1px solid #999999;" valign="top" | {{{comp_m_sg}}}
| style="border: 1px solid #999999;" valign="top" | {{{comp_f_sg}}}
| style="border: 1px solid #999999;" valign="top" | {{{comp_m_pl}}}
| style="border: 1px solid #999999;" valign="top" | {{{comp_f_pl}}}
|- 
! style="border: 1px solid #999999; background:#b0bfd4" | [[Appendix:Glossary#superlative|superlative]]
| style="border: 1px solid #999999;" valign="top" | {{{sup_m_sg}}}
| style="border: 1px solid #999999;" valign="top" | {{{sup_f_sg}}}
| style="border: 1px solid #999999;" valign="top" | {{{sup_m_pl}}}
| style="border: 1px solid #999999;" valign="top" | {{{sup_f_pl}}}
|- 
! style="border: 1px solid #999999; background:#b0bfd4" | [[Appendix:Glossary#augmentative|augmentative]]
| style="border: 1px solid #999999;" valign="top" | {{{aug_m_sg}}}
| style="border: 1px solid #999999;" valign="top" | {{{aug_f_sg}}}
| style="border: 1px solid #999999;" valign="top" | {{{aug_m_pl}}}
| style="border: 1px solid #999999;" valign="top" | {{{aug_f_pl}}}
|- 
! style="border: 1px solid #999999; background:#b0bfd4" | [[Appendix:Glossary#diminutive|diminutive]]
| style="border: 1px solid #999999;" valign="top" | {{{dim_m_sg}}}
| style="border: 1px solid #999999;" valign="top" | {{{dim_f_sg}}}
| style="border: 1px solid #999999;" valign="top" | {{{dim_m_pl}}}
| style="border: 1px solid #999999;" valign="top" | {{{dim_f_pl}}}
|}</div></div>]=]

	return mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)
end

export.inflections = inflections

return export