Módulo:Gl-flexión
Aparencia
[ máis información | ver o historial | | | ver as instrucións ]
Aínda non se redactaron as instrucións sobre como usar este módulo.
[ máis información | ver o historial | | | ver as instrucións ]
Os editores poden probar cambios no mesmo en Módulo:Gl-flexión/probas.
Por favor, engade as categorías na subpáxina de documentación e os interwikis no Wikidata. Ver as subpáxinas deste módulo.
Por favor, engade as categorías na subpáxina de documentación e os interwikis no Wikidata. Ver as subpáxinas deste módulo.
-- Grammatical cases for Galician: plural, ordinal
-- used from Module:Wikidades/i18n
local p = {}
local rsubn = mw.ustring.gsub
local rmatch = mw.ustring.match
local unaccented_vowel = "aeiouüAEIOUÜ"
local accented_vowel = "áéíóúýÁÉÍÓÚÝ"
local vowel = unaccented_vowel .. accented_vowel
local V = "[" .. vowel .. "]"
local AV = "[" .. accented_vowel .. "]"
local NAV = "[^" .. accented_vowel .. "]"
local W = "[iyuw]" -- glide
local C = "[^" .. vowel .. ".]"
local remove_accent = {
["á"]="a", ["é"]="e", ["í"]="i", ["ó"]="o", ["ú"]="u", ["ý"]="y",
["Á"]="A", ["É"]="E", ["Í"]="I", ["Ó"]="O", ["Ú"]="U", ["Ý"]="Y",
}
-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
local retval = rsubn(term, foo, bar)
return retval
end
-- version of rsubn() that returns a 2nd argument boolean indicating whether
-- a substitution was made.
local function rsubb(term, foo, bar)
local retval, nsubs = rsubn(term, foo, bar)
return retval, nsubs > 0
end
local prepositions = {
-- a + optional article
"a ",
"ás? ",
"aos? ",
-- con + optional article
"con ",
"coa?s? ",
-- de + optional article
"de ",
"d[oa]s? ",
"d'",
-- en/em + optional article
"en ",
"n[oa]s? ",
-- por + optional article
"por ",
"pol[oa]s? ",
-- para + optional article
"para ",
"pr[óá]s? ",
-- others
"at[aé] ",
"com[oa] ",
"entre ",
"sen ",
"so ",
"sobre ",
}
local function make_try(word)
return function(from, to)
local newval, changed = rsubb(word, from, to)
if changed then
return newval
end
return nil
end
end
-- Based on wikt:en:Module:gl-common
local function plural_form(term, exc_plural)
local exc = exc_plural[mot]
if exc then return exc end
local try = make_try(term)
-- Based on https://www.lingua.gal/c/document_library/get_file?file_path=/portal-lingua/celga/celga-1/material-alumno/Manual_Aula_de_Galego_1_resumo_gramatical.pdf
return try("r$", "res") or
try("z$", "ces") or
try("(" .. V .. "be)l$", "%1is") or -- vowel + -bel
try("(" .. AV .. ".*" .. V .. "l)$", "%1es") or -- non-final stress + -l e.g. [[túnel]] -> 'túneles'
try("^(" .. C .. "*" .. V .. C .. "*l)$", "%1es") or -- monosyllable ending in -l e.g. [[sol]] -> 'soles'
try("il$", "ís") or -- final stressed -il e.g. [[civil]] -> 'civís'
try("(" .. V .. ")l$", "%1is") or -- any other vowel + -l e.g. [[papel]] -> 'papeis'
try("(" .. V .. "[íú])s$", "%1ses") or -- vowel + stressed í/ú + -s e.g. [[país]] -> 'países'
try("(" .. AV .. ")s$", -- other final accented vowel + -s e.g. [[autobús]] -> 'autobuses'
function(av) return remove_accent[av] .. "ses" end) or
try("(" .. V .. "[iu]?s)$", "%1es") or -- diphthong + final -s e.g. [[deus]] -> 'deuses'
try("^(C" .. "*" .. V .. "s)$", "%1es") or -- monosyllable + final -s e.g. [[fros]] -> 'froses', [[gas]] -> 'gases'
try("([sx])$", "%1") or -- other final -s or -x (stressed on penult or antepenult or ending in cluster), e.g.
-- [[mércores]], [[lapis]], [[lux]], [[unisex]], [[luns]]
term .. "s" -- ending in vowel, -n or other consonant e.g. [[cadeira]], [[marroquí]], [[xersei]], [[limón]],
-- [[club]], [[clip]], [[robot]], [[álbum]]
end
function p.plural(term)
local exc_plural = mw.loadData("Module:Gl-flexión/plural")
if term:find(" ") then
local exc = exc_plural[term]
if exc then return exc end
for _, prep in ipairs(prepositions) do
local part1, part2 = rmatch(term, "^(.-)( " .. prep .. ".*)$")
if part1 then
return p.plural(part1) .. part2
end
end
local plurals = {}
for part in mw.text.gsplit(term, " ", true) do
table.insert(plurals, plural_form(part, exc_plural))
end
return table.concat(plurals, " ")
end
return plural_form(term, exc_plural)
end
-- Based on w:gl:Template:ordinal
function p.ordinal(number, feminine)
if feminine then
return number .. 'ª'
else
return number .. 'º'
end
end
return p