Mòdul:ca-lema
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
Aquest mòdul presenta un lema en català amb les indicacions de flexió, la sil·labificació i les categories corresponents ordenades. Actualment dóna suport a les plantilles {{ca-nom}} i {{ca-nom-forma}}, {{ca-adj}} i {{ca-adj-forma}}, i {{ca-verb}}. Vegeu la documentació de les plantilles per a la seva utilització.
El mòdul es basa en Mòdul:ca-general, per a les funcions generals d'ordenació, i en Mòdul:lema pel format general d'un lema. S'invoca amb una única funció flex
amb l'argument apropiat. Exemple: {{#invoke:ca-lema|flex|Substantius}}
Genera les formes en femení i en plural a partir d'unes regles vàlides en la majoria de casos. Genera també les etiquetes necessàries per a l'edició accelerada de formes flexionades.
local p = {}
local lang = {code = "ca", name = "català", sc = "Latn"}
local missing_entry = "Termes en " .. lang.name .. " amb flexions a crear"
local pos_functions = {}
-- Funció d'entrada per mostrar el lema flexionat, l'única que s'invoca des d'una plantilla
function p.flex(frame)
local args = frame:getParent().args
pagename = args.pagename
if not pagename or pagename == "" then
pagename = mw.title.getCurrentTitle().subpageText
end
local data = {lang = lang, heads = {}, genders = {}, inflections = {}, categories = {}}
local head = args.lema; if head == "" then head = nil end
table.insert(data.heads, head)
local isLemma = frame.args['forma'] == nil and true or nil
local poscat = frame.args[1] or error("Falta especificar la categoria lèxica com a primer paràmetre.")
if pos_functions[poscat] then
pos_functions[poscat].func(args, data, isLemma)
else
table.insert(data.categories, poscat .. " en " .. lang.name)
end
if args.cat and args.cat ~= "" then
table.insert(data.categories, args.cat)
end
if args.bot then
return require("Module:lema").make_bot_list(data.inflections)
else
return require("Module:lema").full_headword(data)
end
end
-- Informació de flexió per a substantius
pos_functions["Substantius"] = {func = function(args, data, isLemma)
-- Codis gènere-nombre:
-- "m", "f", "mf", "mof"
-- "m-p", "f-p", "mf-p" pluralia tantum
-- "m-s", "f-s", "mf-s" només o normalment en singular
-- "m-i", "f-i", "mf-i" invariable en nombre
-- "m-?", "f-?", "mf-?" sense plural conegut
-- "mp", "fp", "mfp" flexionats en plural
local genere = args[1] or ""
local plural = args[2] or args.p
local plural2 = args.p2 -- si està buit, l'anul·la
local fem = args["f"]
local fem2 = args["f2"]
local tipus = nil
local gn = mw.text.split(genere, "-")
if #gn > 1 then
genere = gn[1]
tipus = gn[2]
end
if genere == "" then
table.insert(data.genders, "?")
else -- conversió a "m", "f", "m-f", "m-p", "f-p", "m-f-p"
genere = string.gsub(genere, "i", "mf")
local generes = mw.text.split(genere, "")
local str_gender, sep = '', ''
for _, g in ipairs(generes) do
if g ~= "-" and g ~= "o" then
str_gender = str_gender .. sep
sep = '-'
else
sep = ''
end
str_gender = str_gender .. g
end
table.insert(data.genders, str_gender)
end
-- Categoria gramatical
if mw.ustring.find(pagename, "[^ ]+ [^ ]+") then
if isLemma then
table.insert(data.categories, "Locucions nominals en " .. lang.name)
else
table.insert(data.categories, "Formes de locucions nominals en " .. lang.name)
end
elseif genere == "mf" then
table.insert(data.categories, "Substantius femenins i masculins en " .. lang.name)
elseif genere == "mof" or genere == "fom" then
table.insert(data.categories, "Substantius de gènere vacil·lant en " .. lang.name)
elseif genere == "mfp" then
table.insert(data.categories, "Formes de substantius en plural en " .. lang.name)
elseif genere == "m" then
table.insert(data.categories, "Substantius masculins en " .. lang.name)
elseif genere == "mp" then
table.insert(data.categories, "Formes de substantius en plural en " .. lang.name)
elseif genere == "f" then
if isLemma then
table.insert(data.categories, "Substantius femenins en " .. lang.name)
else
table.insert(data.categories, "Formes de substantius en femení en " .. lang.name)
end
elseif genere == "fp" then
table.insert(data.categories, "Formes de substantius en plural en " .. lang.name)
else
if isLemma then
table.insert(data.categories, "Substantius en " .. lang.name)
else
table.insert(data.categories, "Formes de substantius en " .. lang.name)
end
end
-- Plural
if genere == "mp" or genere == "fp" or genere == "mfp" then
local sing, pAlt = forma_plural_alt(pagename)
plural2 = plural2 or pAlt
if plural2 ~= "" then
table.insert(data.inflections, {label = "alternatiu", plural2, accel = "plural-form-of gender-"..string.sub(genere, 1, -2).." origin-"..sing})
end
elseif tipus ~= "?" then
if tipus == "i" then
table.insert(data.inflections, {label = "plural invariable"})
table.insert(data.categories, "Substantius amb plural invariable en " .. lang.name)
elseif tipus == "p" then
table.insert(data.inflections, {label = "plurale tantum"})
table.insert(data.categories, "Substantius pluralia tantum en " .. lang.name)
elseif tipus == "s" then
if plural ~= nil then
table.insert(data.inflections, {label = "normalment en singular"})
else
table.insert(data.inflections, {label = "només en singular"})
end
-- table.insert(data.categories, "Substantius singularia tantum en " .. lang.name)
end
if plural ~= nil or tipus == nil then
local infl_parts = {label = "plural", accel = "plural-form-of gender-" .. genere}
local p, p2 = p.forma_plural_nominal(pagename)
if plural == "" or plural == nil then
plural = p
end
plural2 = plural2 or p2
table.insert(infl_parts, plural)
if plural2 ~= "" then
table.insert(infl_parts, plural2)
if not mw.title.new(plural2).exists then
table.insert(data.categories, missing_entry)
end
end
table.insert(data.inflections, infl_parts)
if not mw.title.new(plural).exists then
table.insert(data.categories, missing_entry)
end
end
end
-- Femení
if fem == "" then -- demanat però no definit
fem = p.forma_femenina(pagename)
end
if fem then
local infl_parts = {label = "femení", accel = "femenina-form-of gender-f"}
table.insert(infl_parts, fem)
if fem2 then
table.insert(infl_parts, fem2)
end
table.insert(data.inflections, infl_parts)
if not mw.title.new(fem).exists or (fem2 and not mw.title.new(fem2).exists) then
table.insert(data.categories, missing_entry)
end
end
end
}
-- Informació de flexió per a adjectius
pos_functions["Adjectius"] = {func = function(args, data, isLemma)
-- Gènere: m (masculí), i (invariable)
-- Gènere flexionats: f, mp, fp, ip
local genere = args[1]; if genere == "" then genere = nil end
local locucio = mw.ustring.find(pagename, "[ ']")
if not genere then
if locucio then
genere = "loc"
elseif string.find(pagename, "a$") then
genere = "i"
else
genere = "m"
end
end
genere = string.gsub(genere, "mf", "i")
genere = string.gsub(genere, "([^%-])p$", "%1%-p") -- conversió a "m-p", "f-p", "i-p"
table.insert(data.genders, genere)
-- Plurals:
-- p= plural masculí o plural de gènere invariable
-- p2= segon plural masculí o invariable
-- pf/fp = plural femení
local pl, pl2 = p.forma_plural_nominal(pagename, genere)
local plural = args.p or pl
local plural2 = args.p2 -- nil: a generar, "" no mostrar
local plural_fem = args.pf or args.fp -- nil: a generar, "" no mostrar
-- Gènere invariable
if genere == "i" or genere == "i-i" then
if locucio then
table.insert(data.categories, "Locucions adjectivals en " .. lang.name)
else
table.insert(data.categories, "Adjectius en " .. lang.name)
table.insert(data.categories, "Adjectius invariables en " .. lang.name)
end
if plural_fem == nil then plural_fem = pl2 end
if plural2 == nil then plural2 = pl2 end
if plural_fem ~= "" then
table.insert(data.inflections, {label = "plural masculí", accel = "plural-form-of gender-m", plural})
table.insert(data.inflections, {label = "plural femení", accel = "plural-form-of gender-f", plural_fem})
if not mw.title.new(plural).exists or not mw.title.new(plural_fem).exists then
table.insert(data.categories, missing_entry)
end
elseif plural2 ~= "" then
table.insert(data.inflections, {label = "plural", accel = "plural-form-of gender-i", plural, plural2})
if not mw.title.new(plural).exists or not mw.title.new(plural2).exists then
table.insert(data.categories, missing_entry)
end
elseif genere ~= "i-i" then
table.insert(data.inflections, {label = "plural", accel = "plural-form-of gender-i", plural})
if not mw.title.new(plural).exists then
table.insert(data.categories, missing_entry)
end
end
-- Doble gènere
elseif genere == "m" then
if locucio then
table.insert(data.categories, "Locucions adjectivals en " .. lang.name)
else
table.insert(data.categories, "Adjectius en " .. lang.name)
end
local fem = args.f or p.forma_femenina(pagename)
if plural2 == nil then plural2 = pl2 end
local pf, pf2 = p.forma_plural_nominal(fem, "")
if plural_fem == nil then plural_fem = pf end
table.insert(data.inflections, {label = "femení", accel = "femenina-form-of gender-f", fem})
if plural_fem == plural then
table.insert(data.inflections, {label = "plural invariable", accel = "plural-form-of gender-i", plural})
else
if plural2 == "" then
table.insert(data.inflections, {label = "plural masculí", accel = "plural-form-of gender-m", plural})
else
table.insert(data.inflections, {label = "plural masculí", accel = "plural-form-of gender-m", plural, plural2})
if not mw.title.new(plural2).exists then
table.insert(data.categories, missing_entry)
end
end
table.insert(data.inflections, {label = "plural femení", accel = "plural-form-of gender-f origin-" .. fem, plural_fem})
if not mw.title.new(plural_fem).exists then
table.insert(data.categories, missing_entry)
end
end
if not mw.title.new(fem).exists or not mw.title.new(plural).exists then
table.insert(data.categories, missing_entry)
end
-- Formes flexionades
elseif genere == "f" then
if locucio then
table.insert(data.categories, "Formes de locucions adjectivals en " .. lang.name)
else
table.insert(data.categories, "Formes d'adjectius en femení en " .. lang.name)
end
local pf, pf2 = p.forma_plural_nominal(pagename, "")
if plural_fem == nil then plural_fem = pf end
table.insert(data.inflections, {label = "plural", accel = "plural-form-of gender-f", plural_fem})
if not mw.title.new(plural_fem).exists then
table.insert(data.categories, missing_entry)
end
elseif genere == "m-p" then
if locucio then
table.insert(data.categories, "Formes de locucions adjectivals en " .. lang.name)
else
table.insert(data.categories, "Formes d'adjectius en plural en " .. lang.name)
end
local sing, pAlt = forma_plural_alt(pagename)
if plural2 == nil then plural2 = pAlt end
if plural2 ~= "" then
table.insert(data.inflections, {label = "alternatiu", accel = "plural-form-of gender-m origin-" .. sing, plural2})
if not mw.title.new(plural2).exists then
table.insert(data.categories, missing_entry)
end
end
elseif genere == "f-p" or genere == "i-p" then
if locucio then
table.insert(data.categories, "Formes de locucions adjectivals en " .. lang.name)
else
table.insert(data.categories, "Formes d'adjectius en plural en " .. lang.name)
end
elseif genere == "loc" then
table.insert(data.categories, "Locucions adjectivals en " .. lang.name)
end
end
}
-- Flexió de numerals: cardinals invariables amb possible femení, altres com adjectius
pos_functions["Numerals"] = {func = function(args, data, isLemma)
local genere = args[1] or "i"
local fem = args.f
local fem2 = args.f2
local plural = args.p
local plural2 = args.p2
local plural_fem = args.pf
table.insert(data.categories, "Numerals en " .. lang.name)
-- femení
fem = fem or p.forma_femenina(pagename)
if genere == "m" or (genere == "i" and args.f) then
table.insert(data.genders, "m")
table.insert(data.inflections, {label = "femení", fem, fem2})
else
table.insert(data.genders, genere)
end
-- plurals
if genere == "m" then
local pl, pl2 = p.forma_plural(pagename, genere)
plural = plural or pl
if plural2 == nil and pl2 ~= "" then plural2 = pl2 end
local pf, pf2 = p.forma_plural(fem, "")
plural_fem = plural_fem or pf
if plural_fem == plural then
table.insert(data.inflections, {label = "plural", plural})
else
table.insert(data.inflections, {label = "plural masculí", plural, plural2})
table.insert(data.inflections, {label = "plural femení", plural_fem})
end
end
end
}
-- Informació de verbs
pos_functions["Verbs"] = {func = function(args, data, isLemma)
local tipus = args[1] or ""
local locucio = pagename:find(" ")
if locucio then
table.insert(data.categories, "Locucions verbals en " .. lang.name)
else
table.insert(data.categories, "Verbs en " .. lang.name)
if tipus:find("p") then
table.insert(data.categories, "Verbs pronominals en " .. lang.name)
end
end
if not locucio and tipus == "" then
tipus = "?"
end
tipus = string.gsub(tipus, "[^atipm-]", "?")
if tipus ~= "" then
local totsTipus = mw.text.split(tipus, "-")
for i, tipusx in ipairs(totsTipus) do
local tipusPart = mw.text.split(tipusx, "")
local gendersPart = {}
for ii, tipusPartx in ipairs(tipusPart) do
if tipusPartx ~= "?" then tipusPartx = "v" .. tipusPartx end
table.insert(gendersPart, tipusPartx)
end
table.insert(data.genders, table.concat(gendersPart, "-"))
end
end
if args.defectiu then
table.insert(data.inflections, {label = "defectiu"})
end
local inflection = args.p
if not inflection and tipus:find("p") and string.find(pagename, "re?$") then
inflection = string.gsub(string.gsub(pagename, "re$", "re's"), "r$", "r-se")
end
if inflection and inflection ~= "" then
table.insert(data.inflections, {label = "pronominal", inflection})
end
if args.m then
table.insert(data.inflections, {label = "impersonal", args.m})
end
if args.i then
table.insert(data.inflections, {label = "intransitiu", args.i})
end
end
}
-- Forma femenina
-- TODO: locucions com el plural
function p.forma_femenina(head)
-- Usat per Mòdul:ca-verb
local fem = head
fem = mw.ustring.gsub(fem, "à$", "ana")
fem = string.gsub(fem, "[eo]$", "a")
fem = mw.ustring.gsub(fem, "[èé]$", "ena")
fem = mw.ustring.gsub(fem, "([^gq][aeou])í$", "%1ïna")
fem = mw.ustring.gsub(fem, "í$", "ina")
fem = mw.ustring.gsub(fem, "[òó]$", "ona")
fem = string.gsub(fem, "([aio])u$", "%1va")
fem = mw.ustring.gsub(fem, "ú$", "una")
if mw.ustring.find(fem, "g$") then
fem = string.gsub(fem, "leg$", "loga")
fem = string.gsub(fem, "oig$", "oja")
elseif mw.ustring.find(fem, "[ei]n$") and not mw.ustring.find(fem, "[àèéíòóú]") then
fem = mw.ustring.gsub(fem, "a([^aeio]+[ei]n)$", "à%1a")
fem = mw.ustring.gsub(fem, "e([^aeio]+[ei]n)$", "è%1a")
fem = mw.ustring.gsub(fem, "i([^aeio]+[ei]n)$", "í%1a")
fem = mw.ustring.gsub(fem, "o([^aeio]+[ei]n)$", "ò%1a")
fem = mw.ustring.gsub(fem, "u([^aeio]+[ei]n)$", "ú%1a")
elseif mw.ustring.find(fem, "s$") then
fem = mw.ustring.gsub(fem, "[aà]s$", "assa")
fem = mw.ustring.gsub(fem, "ès$", "esa")
fem = mw.ustring.gsub(fem, "és$", "essa")
fem = mw.ustring.gsub(fem, "ís$", "issa")
fem = mw.ustring.gsub(fem, "[oò]s$", "ossa")
fem = mw.ustring.gsub(fem, "ós$", "osa")
fem = mw.ustring.gsub(fem, "ús$", "usa")
end
fem = mw.ustring.gsub(fem, "([aiïu])t$", "%1da")
fem = mw.ustring.gsub(fem, "a(%l)i$", "à%1ia")
fem = mw.ustring.gsub(fem, "i(%l)i$", "í%1ia")
if fem == head and not string.find(head, "a$") then
fem = head .. "a"
end
return fem
end
-- Forma plural
function p.forma_plural_nominal(head, genere)
if head:find("[^ ]+ [^ ]+") then
local preposicions = {" a ", " al ", " amb ", " com ", " contra ", " des ", " d'", " del ", " dels ", " de ",
" dintre ", " en ", " endavant", " enrere", " entre ",
" fora ", " per ", " pel ", " pels ", " sense ", " sobre ", " sota "}
for i, prep in ipairs(preposicions) do
offset = mw.ustring.find(head, prep, 1, true)
if offset then
local part1 = mw.ustring.sub(head, 1, offset-1)
local part2 = mw.ustring.sub(head, offset)
local plural1, plural2 = p.forma_plural_nominal(part1, genere)
return plural1 .. part2, plural2 .. (plural2=="" and "" or part2)
end
end
local plurals1 = {}
local plurals2 = {}
for part in mw.text.gsplit(head, " ", true) do
local partplural1, partplural2 = p.forma_plural(part, genere)
table.insert(plurals1, partplural1)
table.insert(plurals2, partplural2=="" and partplural1 or partplural2)
end
local plural1 = table.concat(plurals1, " ")
local plural2 = table.concat(plurals2, " ")
return plural1, plural2==plural1 and "" or plural2
else
return p.forma_plural(head, genere)
end
end
function p.forma_plural(word, genere)
-- doble plural
if string.find(word, "s[cpt]$") or string.find(word, "xt$") then
return word .. "s", word .. "os"
elseif string.find(word, "ig$") and word ~= "puig" and word ~= "raig" then
return word .. "s", string.gsub(word, "ig$", "jos")
elseif genere == "i" and mw.ustring.find(word, "[aio]ç$") then -- model feliç
return word .. "os", mw.ustring.gsub(word, "ç$", "ces")
elseif genere == "i" and word:find("x$") then -- model circumflex
return word .. "os", word .. "es"
end
local plural = word
-- a -> es, amb canvis morfològics
if string.find(word, "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, "ja$", "ges")
plural = mw.ustring.gsub(plural, "([gq])ua$", "%1ües")
if plural == word then plural = string.gsub(word, "a$", "es") end
-- vocal accentuada + n -> sense accent + ns
elseif mw.ustring.find(word, "[àéèíóòú]n?$") then
plural = mw.ustring.gsub(plural, "à$", "ans")
plural = mw.ustring.gsub(plural, "[èé]n?$", "ens")
plural = mw.ustring.gsub(plural, "([^g][aeou])í$", "%1ïns")
plural = mw.ustring.gsub(plural, "ín?$", "ins")
plural = mw.ustring.gsub(plural, "[òó]n?$", "ons")
plural = mw.ustring.gsub(plural, "ú$", "uns")
if plural == word then plural = word .. "s" end
-- en/in -> accent ... + ens/ins
elseif mw.ustring.find(word, "[ei]n$") and not mw.ustring.find(word, "[àèéíòóú]") then
plural = mw.ustring.gsub(plural, "a([^aeio]+[ei]n)$", "à%1s")
plural = mw.ustring.gsub(plural, "e([^aeio]+[ei]n)$", "è%1s")
plural = mw.ustring.gsub(plural, "i([^aeio]+[ei]n)$", "í%1s")
plural = mw.ustring.gsub(plural, "o([^aeio]+[ei]n)$", "ò%1s")
plural = mw.ustring.gsub(plural, "u([^aeio]+[ei]n)$", "ú%1s")
if plural == word then plural = word .. "s" end
-- s -> s(s)os
elseif string.find(word, "s$") then
if not mw.ustring.find(word, "[aàeèéiíïoòóuú].*[eou]s$") then -- invariables excepte monosíl·labs
plural = mw.ustring.gsub(plural, "[oò]s$", "ossos") -- -os ha de ser el primer
plural = mw.ustring.gsub(plural, "[aà]s$", "assos")
plural = mw.ustring.gsub(plural, "és$", "essos")
plural = mw.ustring.gsub(plural, "[eè]s$", "esos")
plural = mw.ustring.gsub(plural, "oís$", "oïssos")
plural = mw.ustring.gsub(plural, "([^gq][au])ís$", "%1ïsos")
plural = mw.ustring.gsub(plural, "ís$", "issos")
plural = mw.ustring.gsub(plural, "ós$", "osos")
plural = mw.ustring.gsub(plural, "ús$", "usos")
plural = mw.ustring.gsub(plural, "us$", "ussos")
if plural == word then plural = word .. "os" end
end
else
plural = mw.ustring.gsub(plural, "([çxz])$", "%1os")
if plural == word then
plural = word .. "s"
end
end
return plural, ""
end
-- Forma plural alternativa
function forma_plural_alt(word)
local sing = ""
local pAlt = ""
if string.find(word, "s[cpt]os$") or string.find(word, "xtos$") then
sing = string.gsub(word, "os$", "")
pAlt = string.gsub(word, "os$", "s")
elseif string.find(word, "s[cpt]s$") or string.find(word, "xts$") then
sing = string.gsub(word, "s$", "")
pAlt = string.gsub(word, "s$", "os")
elseif string.find(word, "jos$") then
sing = string.gsub(word, "jos$", "ig")
pAlt = string.gsub(word, "jos$", "igs")
elseif string.find(word, "igs$") then
sing = string.gsub(word, "s$", "")
pAlt = string.gsub(word, "igs$", "jos")
end
return sing, pAlt
end
-- Funcions exportables per a proves a Mòdul:ca-general/ús
function p.fem(frame)
return p.forma_femenina(frame.args[1])
end
function p.plural(frame)
local pl, pl2 = p.forma_plural_nominal(frame.args[1])
return pl .. ' ' .. pl2
end
return p