Módulu:Ast-flexón
La documentación pa esti módulu pue crease en Módulu:Ast-flexón/usu
local p = {}
local exc_fem = mw.loadData("Módulu:Ast-flexón/femenín")
-- Forma femenina d'una palabra
local function forma_fem(mot)
local exc = exc_fem[mot]
if exc then return exc end
local fem = mot
fem = mw.ustring.gsub(fem, "án$", "ana")
if string.find(mot, "e$") and not string.find(mot, "ble$") then
fem = string.gsub(fem, "gue$", "ga")
fem = string.gsub(fem, "e$", "a")
end
-- fem = mw.ustring.gsub(fem, "[é]$", "ena")
-- fem = mw.ustring.gsub(fem, "([^gq][aeou])í$", "%1ïna")
fem = mw.ustring.gsub(fem, "ín$", "ina")
-- fem = mw.ustring.gsub(fem, "a(%l)i$", "à%1ia")
-- fem = mw.ustring.gsub(fem, "i(%l)i$", "í%1ia")
fem = string.gsub(fem, "u$", "a")
fem = mw.ustring.gsub(fem, "ó$", "ona")
fem = string.gsub(fem, "([áaéíióoú])u$", "%1da")
fem = string.gsub(fem, "eu$", "ea")
fem = mw.ustring.gsub(fem, "ú$", "uda")
fem = string.gsub(fem, "logu$", "loga")
fem = string.gsub(fem, "oxu", "oxa")
fem = mw.ustring.gsub(fem, "ás$", "asa")
fem = mw.ustring.gsub(fem, "és$", "esa")
fem = mw.ustring.gsub(fem, "ís$", "isa")
fem = mw.ustring.gsub(fem, "ós$", "osa")
fem = mw.ustring.gsub(fem, "ús$", "usa")
-- fem = mw.ustring.gsub(fem, "([aiïu])t$", "%1da")
if fem == mot then
local no_fem = false
if string.find(mot, "a$") then
no_fem = true
elseif string.find(mot, "ble$") then
no_fem = true
elseif string.find(mot, "ei$") then
no_fem = true
if mot == "rei" then
fem = "na"
elseif mot == "virréi" then
fem = "virreina"
end
elseif string.find(mot, "[cinsv][ai]l$") and mot ~= "colexal" and mot ~= "oficial" then
no_fem = true
elseif string.find(mot, "del$") then
no_fem = true
elseif string.find(mot, "mim$") then
no_fem = true
elseif string.find(mot, "ar$") then
no_fem = true
require('Módulu:utilidaes').rastreu("ast-flexón/ar")
elseif string.find(mot, "es$") then
no_fem = true
elseif string.find(mot, "%a[ceptx]ante$") and mot ~= "bastante" and mot ~= "marchante" then
no_fem = true
elseif string.find(mot, "xente$") and mot ~= "sarxentu" then
no_fem = true
elseif string.find(mot, "ilotu$") then
no_fem = true
end
if no_fem == false then
fem = mot .. "a"
end
end
return fem
end
-- Forma femenina d'una locució
function p.fem(lema)
if type(lema) == "table" then lema = lema.args[1] end -- dende plantíes via invoke o dende módulos via require
if lema:find("[^ ]+ [^ ]+") then
local exc = exc_fem[lema]
if exc then return exc end
local preposiciones = {" a ", " al ", " cabo ", " con ", " contra ", " de ", " d'", " del ", " dende ", " dientro ",
" en ", " n'", " ente ", " ensin ", " fora ",
" per ", " pel ", " pela ", " pelos ", " sobre ", " so "}
for i, prep in ipairs(preposiciones) do
offset = mw.ustring.find(lema, prep, 1, true)
if offset then
local part1 = mw.ustring.sub(lema, 1, offset-1)
local part2 = mw.ustring.sub(lema, offset)
return p.fem(part1) .. part2 -- espresamente recursivu pa locuciones complexes
end
end
local femenins = {}
for part in mw.text.gsplit(lema, " ", true) do
if string.find(part, "al$") and #femenins > 0 then -- axetivos en -al invariables
table.insert(femenins, part)
else
table.insert(femenins, forma_fem(part))
end
end
return table.concat(femenins, " ")
else
return forma_fem(lema)
end
end
-- Plural d'una palabra
local function forma_plural(mot)
local plural = mot
-- a -> es, amb canvis morfològics
if string.find(mot, "a$") then
plural = string.gsub(plural, "ca$", "ques")
plural = string.gsub(plural, "ga$", "gues")
-- plural = mw.ustring.gsub(plural, "ça$", "ces")
plural = string.gsub(plural, "xa$", "xes")
plural = mw.ustring.gsub(plural, "([gq])ua$", "%1ües")
if plural == mot then plural = string.gsub(mot, "a$", "es") end
-- vocal acentuada (+n) -> ensin acentu + nes
elseif mw.ustring.find(mot, "[áéíóú]n?$") then
plural = mw.ustring.gsub(plural, "án?$", "anes")
plural = mw.ustring.gsub(plural, "én?$", "enes")
plural = mw.ustring.gsub(plural, "ín?$", "inos")
plural = mw.ustring.gsub(plural, "ón?$", "ones")
plural = mw.ustring.gsub(plural, "ún?$", "unes")
if plural == mot then plural = mot .. "s" end
-- s -> s(s)os
elseif string.find(mot, "s$") then
-- plural = mw.ustring.gsub(plural, "[oó]s$", "osos")
plural = mw.ustring.gsub(plural, "[aá]s$", "asos")
plural = mw.ustring.gsub(plural, "és$", "eses")
-- plural = mw.ustring.gsub(plural, "ès$", "esos")
-- plural = mw.ustring.gsub(plural, "oís$", "oïssos")
plural = mw.ustring.gsub(plural, "([^gq][au])ís$", "%1isos")
plural = mw.ustring.gsub(plural, "ís$", "isos")
plural = mw.ustring.gsub(plural, "ós$", "osos")
plural = mw.ustring.gsub(plural, "ús$", "usos")
if plural == mot and not string.find(mot, "es$") then plural = mot .. "os" end
else
plural = mw.ustring.gsub(plural, "([x])$", "%1os")
plural = mw.ustring.gsub(plural, "([z])$", "%1ces")
if plural == mot then
plural = mot .. "s"
end
end
return plural
end
-- Forma plural d'una llocución
function p.plural(lema)
if type(lema) == "table" then lema = lema.args[1] end -- dende plantíes via invoke o dende módulos via require
if lema:find("[^ ]+ [^ ]+") then
local preposiciones = {" a ", " al ", " cabo ", " con ", " contra ", " de ", " d'", " del ", " dende ", " dientro ",
" en ", " n'", " ente ", " ensin ", " fora ",
" per ", " pel ", " pela ", " pelos ", " sobre ", " so "}
for i, prep in ipairs(preposiciones) do
offset = mw.ustring.find(lema, prep, 1, true)
if offset then
local part1 = mw.ustring.sub(lema, 1, offset-1)
local part2 = mw.ustring.sub(lema, offset)
return p.plural(part1) .. part2
end
end
local plurals = {}
for part in mw.text.gsplit(lema, " ", true) do
table.insert(plurals, forma_plural(part))
end
return table.concat(plurals, " ")
else
return forma_plural(lema)
end
end
-- Función auxiliar pa l’apostrofación del artículu masculín, retorna true o false
-- Llimitaciones: ver plantía:deod'
local function sapostrofa(text)
local apostrofa = {
["her "]=false, ["his "]=false, -- palabres n'inglés que provoquen falsos apostrofos
["hakk"]=false, -- h consonante (hakka)
["hawa"]=false, -- h consonante (hawai)
["hia"]=false, ["hie"]=false, ["hio"]=false, ["hui"]=false, -- vocal consonante
-- ["uix"]=true, -- excepció per u vocal
["ha"]=true, ["he"]=true, ["hi"]=true, ["hí"]=true, ["ho"]=true, ["hu"]=true, ["hy"]=true, -- excepte anteriors
-- ["ia"]=false, ["ià"]=false, ["ie"]=false, ["io"]=false, ["iu"]=false, -- i consonant
-- ["ua"]=false, ["ue"]=false, ["ui"]=false, ["uí"]=false, ["uï"]=false, ["uo"]=false, -- u consonant
["ya"]=false, ["ye"]=false, ["yi"]=false, ["yo"]=false, ["yu"]=false, -- y consonant
["a"]=true, ["á"]=true, ["e"]=true, ["é"]=true,
["i"]=true, ["í"]=true, ["ï"]=true, ["y"]=true,
["o"]=true, ["ó"]=true, ["u"]=true, ["ú"]=true, ["ü"]=true, -- excepte anteriors
-- ["1 "]=true, ["11 "]=true -- dates amb "1 de" o "11 de "
}
local elText = mw.ustring.lower(require('Módulu:Delink')._delink({text}))
for i = 4, 1, -1 do
lletres = mw.ustring.sub(elText, 1, i)
apo = apostrofa[lletres]
if apo ~= nil then
return apo
end
end
return false
end
function p.apostrofar(frame)
args = frame:getParent().args
local text = args[2] or ""
local ret = (args[1] or "") .. " " .. text
if sapostrofa(text) then
local article = mw.language.getContentLanguage():lcfirst(args[1])
if article == "el" then
ret = "l'" .. text
elseif article == "al" then
ret = "a l'" .. text
elseif article == "del" then
ret = "de l'" .. text
elseif article == "pel" then
ret = "per l'" .. text
elseif article == "cal" then
ret = "ca l'" .. text
end
if article ~= args[1] then
ret = mw.language.getContentLanguage():ucfirst(ret)
end
end
return ret
end
return p