Mòdul:oc-lema
Aparença
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 occità amb les indicacions de flexió i les categories corresponents ordenades. Actualment dóna suport a les plantilles {{oc-nom}} i {{oc-adj}}. Vegeu la documentació de les plantilles per a la seva utilització.
S'invoca amb una única funció flex
amb l'argument apropiat. Exemple: {{#invoke:oc-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.
Caixa de proves:
local p = {}
local lang = {code = "oc", name = "occità", sc = "Latn"}
local pos_functions = {}
-- Funcions auxiliars
local function forma_femenina(masc) -- Forma femenina
local fem
if string.find(masc, "a$") then
fem = masc
elseif mw.ustring.find(masc, "[aàeéèoóòuú]c$") then
fem = string.gsub(masc, "c$", "ga")
elseif string.find(masc, "e$") then
fem = string.gsub(masc, "ce$", "ça")
fem = string.gsub(fem, "ge$", "ja")
fem = string.gsub(fem, "güe$", "gua")
fem = string.gsub(fem, "e$", "a")
elseif mw.ustring.find(masc, "[aàeéèiíoóòuú]g$") then
fem = string.gsub(masc, "g$", "ja")
elseif string.find(masc, "th$") then
fem = string.gsub(masc, "th$", "ra")
elseif string.find(masc, "i$") then
fem = mw.ustring.gsub(masc, "a([^aeiou][^aeiou]?)i$", "à%1ia")
fem = mw.ustring.gsub(fem, "i([^aeiou])i$", "í%1ia")
fem = string.gsub(fem, "i$", "ia")
elseif string.find(masc, "o$") then
fem = string.gsub(masc, "o$", "a")
elseif string.find(masc, "p$") then
fem = string.gsub(masc, "p$", "ba")
elseif mw.ustring.find(masc, "[àéèíóòú]s$") then
fem = mw.ustring.gsub(masc, "às$", "asa")
fem = mw.ustring.gsub(fem, "és$", "esa")
fem = mw.ustring.gsub(fem, "ès$", "essa")
fem = mw.ustring.gsub(fem, "([ao])ís$", "%1ïsa")
fem = mw.ustring.gsub(fem, "ís$", "isa")
fem = mw.ustring.gsub(fem, "òs$", "ossa")
fem = mw.ustring.gsub(fem, "ós$", "osa")
fem = mw.ustring.gsub(fem, "ús$", "usa")
elseif mw.ustring.find(masc, "[aàeéèiíoóòuú]t$") then
fem = string.gsub(masc, "t$", "da")
elseif string.find(masc, "u$") then
fem = string.gsub(masc, "([aeio])u$", "%1va")
fem = mw.ustring.gsub(fem, "i(%l)u$", "í%1ua")
fem = string.gsub(fem, "u$", "ua")
else
fem = masc .. "a"
end
return fem
end
-- Forma plural aranesa
local function forma_plural_ar(sing, pos)
local plural = sing
if string.find(sing, "a$") then
plural = string.gsub(plural, "ca$", "ques")
plural = string.gsub(plural, "ça$", "ces")
plural = string.gsub(plural, "ga$", "gues")
plural = string.gsub(plural, "gua$", "gües")
plural = string.gsub(plural, "ja$", "ges")
plural = string.gsub(plural, "a$", "es")
elseif pos == "adj-m" and string.find(sing, "e$") then
plural = string.gsub(plural, "([^aàeèéiíoòóuú][^aàeèéiíoòóuú]e)$", "%1s")
plural = string.gsub(plural, "e$", "i")
elseif pos == "adj-m" and string.find(sing, "i$") then
plural = sing .. "s"
elseif mw.ustring.find(sing, "ç$") then
plural = mw.ustring.gsub(sing, "ç$", "ci")
elseif string.find(sing, "[ns]c$") then
plural = string.gsub(sing, "c$", "qui")
elseif pos == "adj-m" and mw.ustring.find(sing, "[aàeéèiíoóòuú]th$") then
plural = string.gsub(sing, "th$", "ri")
elseif pos == "adj-m" and mw.ustring.find(sing, "[aàeéèiíoóòuú]t$") then
plural = string.gsub(sing, "t$", "di")
elseif mw.ustring.find(sing, "[àéèíóòú]s$") then
plural = mw.ustring.gsub(plural, "às$", "assi")
plural = mw.ustring.gsub(plural, "és$", "esi")
plural = mw.ustring.gsub(plural, "ès$", "essi")
plural = mw.ustring.gsub(plural, "([ao])ís$", "%1ïsi")
plural = mw.ustring.gsub(plural, "ís$", "isi")
plural = mw.ustring.gsub(plural, "òs$", "ossi")
plural = mw.ustring.gsub(plural, "ós$", "osi")
plural = mw.ustring.gsub(plural, "ús$", "usi")
elseif string.find(sing, "s$") or string.find(sing, "tz$") or string.find(sing, "ish$") or string.find(sing, "s[^aàeèéiíoòóuú]$") then
if pos == "nom-m" or pos == "adj-m" then
plural = sing .. "i"
else
plural = sing .. "es"
end
elseif pos == "adj-m" then
plural = sing .. "i"
else
plural = sing .. "s"
end
return plural
end
-- Forma plural general
local function forma_plural(sing, pos)
local plural = sing
if mw.ustring.find(sing, "[àéèíóòú]s$") then
plural = mw.ustring.gsub(plural, "às$", "asses")
plural = mw.ustring.gsub(plural, "és$", "eses")
plural = mw.ustring.gsub(plural, "ès$", "esses")
plural = mw.ustring.gsub(plural, "([ao])ís$", "%1ïses")
plural = mw.ustring.gsub(plural, "ís$", "ises")
plural = mw.ustring.gsub(plural, "òs$", "osses")
plural = mw.ustring.gsub(plural, "ós$", "oses")
plural = mw.ustring.gsub(plural, "ús$", "uses")
elseif mw.ustring.find(sing, "[aàeéèiíoóòuú][^aàeéèiíoóòuú]+[aeiou]s$") then
plural = sing
elseif mw.ustring.find(sing, "ç$") then
plural = mw.ustring.gsub(sing, "ç$", "ces")
elseif string.find(sing, "sc$") then
plural = string.gsub(sing, "c$", "ques")
elseif mw.ustring.find(sing, "[^aàeéèiíoóòuú]g$") then -- excepcions: larg, long...
plural = sing .. "s"
elseif string.find(sing, "tz$") then
plural = string.gsub(sing, "tz$", "ses")
elseif string.find(sing, "[sx]t$") or string.find(sing, "[cs]h$") or string.find(sing, "sp$") or string.find(sing, "[fgsxz]$") then
plural = sing .. "es"
else
plural = sing .. "s"
end
return plural, forma_plural_ar(sing, pos)
end
-- Plural de locucions
local function forma_plural_nominal(lema, pos)
if lema:find("[^ ]+ [^ ]+") then
local preposicions = {"a", "al", "als", "amb", "après", "cap", "contra", "darrièr", "daus", "davant", "de", "del", "dels",
"d", "dejós", "despuèi", "detràs", "dèus", "dins", "en", "entre", "fins", "jos", "jol", "per", "pel", "pels", "segon",
"sens", "sobre", "sota", "sus", "sul", "suls", "tras", "vèrs"}
for i, prep in ipairs(preposicions) do
offset = mw.ustring.find(lema, " " .. prep .. "[ ']", 1, false)
if offset then
local part1 = mw.ustring.sub(lema, 1, offset-1)
local part2 = mw.ustring.sub(lema, offset)
local plural1, plural2 = forma_plural_nominal(part1, pos)
return plural1 .. part2, plural2 .. part2
end
end
local plurals1 = {}
local plurals2 = {}
for part in mw.text.gsplit(lema, " ", true) do
local partplural1, partplural2 = forma_plural(part, pos)
table.insert(plurals1, partplural1)
table.insert(plurals2, partplural2)
end
return table.concat(plurals1, " "), table.concat(plurals2, " ")
else
return forma_plural(lema, pos)
end
end
-- 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 lema = args.lema; if lema == "" then lema = nil end
table.insert(data.heads, lema)
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("Mòdul:lema").make_bot_list(data.inflections)
else
return require("Mòdul: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"
-- "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; if plural == "" then plural = nil end
local plural2 = args[3] or args.p2; if plural2 == "" then plural2 = nil end
local plural3 = args.p3; if plural3 == "" then plural3 = nil end
local fem = args["f"]
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
local generes = mw.text.split(genere, "")
table.insert(data.genders, table.concat(generes, "-")) -- conversió a "m", "f", "m-f", "m-p", "f-p", "m-f-p"
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 string.find(genere, "p", -1) or isLemma == nil then
table.insert(data.categories, "Formes de substantius en " .. lang.name)
else
table.insert(data.categories, "Substantius en " .. lang.name)
end
-- Plural
if not (tipus == "?" or genere == "mp" or genere == "fp" or genere == "mfp") then
if tipus == "i" then
table.insert(data.inflections, {label = "plural invariable"})
elseif tipus == "p" then
table.insert(data.inflections, {label = "plurale tantum"})
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
end
if plural or plural2 or plural3 or not tipus then
local pl1, pl2 = forma_plural_nominal(pagename, "nom-" .. genere)
plural = plural or pl1
plural2 = plural2 or (pl2 == plural and "-" or pl2)
if plural ~= "-" or plural2 ~= "-" or plural3 then
local infl_parts = {label = "plural", accel = "plural-form-of gender-" .. genere}
if plural ~= "-" then
table.insert(infl_parts, plural)
end
if plural2 ~= "-" then
if plural ~= "-" then
table.insert(infl_parts, {term = plural2, qualifiers = {"aranès"}})
else
table.insert(infl_parts, plural2)
end
end
if plural3 then
table.insert(infl_parts, plural3)
end
table.insert(data.inflections, infl_parts)
end
end
end
-- Femení
if fem == "" then -- demanat però no definit
fem = forma_femenina(pagename)
end
if fem then
table.insert(data.inflections, {label = "femení", fem, accel = "femenina-form-of gender-f"})
end
if isLemma and tipus == nil then
if plural and plural ~= "-" and not mw.title.new(plural).exists then
table.insert(data.categories, "Termes en occità amb flexions a crear")
elseif plural2 and plural2 ~= "-" and not mw.title.new(plural2).exists then
table.insert(data.categories, "Termes en occità amb flexions a crear")
elseif fem and not mw.title.new(fem).exists then
table.insert(data.categories, "Termes en occità amb flexions a crear")
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, en aranès
-- pf = plural femení
-- pf2 = segon plural femení, en aranès
local plural = args.p; if plural == "" then plural = nil end
local plural2 = args.p2; if plural2 == "" then plural2 = nil end
local plural_fem = args.pf; if plural_fem == "" then plural_fem = nil end
local plural_fem2 = args.pf2; if plural_fem2 == "" then plural_fem2 = nil end
-- Gènere invariable
if genere == "i" then
table.insert(data.categories, "Adjectius en " .. lang.name)
table.insert(data.categories, "Adjectius invariables en " .. lang.name)
local pl1, pl2 = forma_plural_nominal(pagename, "adj-" .. genere)
plural = plural or pl1
plural2 = plural2 or pl2
if plural2 == "-" or plural2 == plural then
plural2 = nil
end
if plural ~= "-" or plural2 then
if plural_fem or plural_fem2 then
infl_parts = {label = "plural masculí", accel = "plural-form-of gender-m"}
else
infl_parts = {label = "plural", accel = "plural-form-of gender-i"}
end
if plural ~= "-" then
table.insert(infl_parts, plural)
end
if plural2 and plural ~= "-" then
table.insert(infl_parts, {term = plural2, qualifiers = {"aranès"}})
elseif plural2 then
table.insert(infl_parts, plural2)
end
table.insert(data.inflections, infl_parts)
if plural_fem or plural_fem2 then
infl_parts = {label = "plural femení", accel = "plural-form-of gender-f"}
if plural_fem then
table.insert(infl_parts, plural_fem)
end
if plural_fem2 and plural_fem then
table.insert(infl_parts, {term = plural_fem2, qualifiers = {"aranès"}})
elseif plural_fem2 then
table.insert(infl_parts, plural_fem2)
end
table.insert(data.inflections, infl_parts)
end
end
-- Doble gènere
elseif genere == "m" then
table.insert(data.categories, "Adjectius en " .. lang.name)
local plm1, plm2 = forma_plural_nominal(pagename, "adj-m")
plural = plural or plm1
plural2 = plural2 or (plm2 == plural and "-" or plm2)
local fem = args.f or forma_femenina(pagename)
local plf1, plf2 = forma_plural_nominal(fem, "adj-f")
plural_fem = plural_fem or plf1
plural_fem2 = plural_fem2 or (plf2 == plural_fem and "-" or plf2)
table.insert(data.inflections, {label = "femení", accel = "femenina-form-of gender-f", fem})
if plural ~= "-" or plural2 ~= "-" then
infl_parts = {label = "plural masculí", accel = "plural-form-of gender-m"}
if plural ~= "-" then
table.insert(infl_parts, plural)
end
if plural2 ~= "-" then
if plural ~= "-" then
table.insert(infl_parts, {term = plural2, qualifiers = {"aranès"}})
else
table.insert(infl_parts, plural2)
end
end
table.insert(data.inflections, infl_parts)
infl_parts = {label = "plural femení", accel = "plural-form-of gender-f origin-" .. fem}
if plural_fem ~= "-" then
table.insert(infl_parts, plural_fem)
end
if plural_fem2 ~= "-" then
if plural_fem ~= "-" then
table.insert(infl_parts, {term = plural_fem2, qualifiers = {"aranès"}})
else
table.insert(infl_parts, plural_fem2)
end
end
table.insert(data.inflections, infl_parts)
end
-- Formes flexionades
elseif genere == "f" then
table.insert(data.categories, "Formes d'adjectius en " .. lang.name)
local plf1, plf2 = forma_plural_nominal(pagename, "adj-f")
plural_fem = plural_fem or plural or plf1
plural_fem2 = plural_fem2 or plural2 or (plf2 == plural_fem and "-" or plf2)
if plural_fem ~= "-" or plural_fem2 ~= "-" then
infl_parts = {label = "plural", accel = "plural-form-of gender-f"}
if plural_fem ~= "-" then
table.insert(infl_parts, plural_fem)
end
if plural_fem2 ~= "-" and plural_fem ~= "-" then
table.insert(infl_parts, {term = plural_fem2, qualifiers = {"aranès"}})
elseif plural_fem2 ~= "-" then
table.insert(infl_parts, plural_fem2)
end
table.insert(data.inflections, infl_parts)
end
elseif genere == "m-p" or genere == "f-p" or genere == "i-p" then
table.insert(data.categories, "Formes d'adjectius en " .. lang.name)
elseif genere == "loc" then
table.insert(data.categories, "Locucions adjectivals en " .. lang.name)
end
end
}
-- Funcions exportables per a proves
function p.fem(frame)
return forma_femenina(frame.args[1])
end
function p.plural(frame)
local plural1, plural2 = forma_plural_nominal(frame.args[1], "nom-m")
local _, plural3 = forma_plural_nominal(frame.args[1], "adj-m")
if plural3 ~= plural2 then
plural2 = plural2 .. " (" .. plural3 .. ")"
end
return plural1 .. " / " .. plural2
end
function p.ordena(frame)
return require("Mòdul:utilitats").ordenacio(frame.args[1], "oc")
end
return p