This module contains utility functions used by Module:mwl-verb (to be implemented) and Module:mwl-headword.
--[=[
Based on ]
]=]
local export = {}
local romut_module = "Module:romance utilities"
local u = require("Module:string/char")
local rsplit = mw.text.split
local rfind = mw.ustring.find
local rmatch = mw.ustring.match
local rsubn = mw.ustring.gsub
local TEMPC1 = u(0xFFF1)
local TEMPC2 = u(0xFFF2)
local TEMPV1 = u(0xFFF3)
local DIV = u(0xFFF4)
local vowel = "aeiouáéêíóôú" .. TEMPV1
local V = ""
local AV = "" -- accented vowel
local W = "" -- glide
local C = ""
export.vowel = vowel
export.V = V
export.AV = AV
export.W = W
export.C = C
local prepositions = {
"a ", "als ",
"an ", "en ", "ne ", "no ", "na ", "nos ", "nas ",
"de ",
"como ",
"cun ", "cul ", "cula ", "culs ", "culas ",
"para ", "pra ", "pa ",
"por ", "po "
}
-- 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
export.rsub = rsub
-- apply rsub() repeatedly until no change
local function rsub_repeatedly(term, foo, bar)
while true do
local new_term = rsub(term, foo, bar)
if new_term == term then
return term
end
term = new_term
end
end
export.rsub_repeatedly = rsub_repeatedly
-- generate the plurals of nominals
function export.make_plural(form, special)
local retval = require(romut_module).handle_multiword(form, special,
function(term) return export.make_plural(term) end, prepositions)
if retval then
return retval
end
-- ends in stressed/unstressed vowel (stressed endings in -i/u are not marked)
if rfind(form, "$") then return {form .. "s"} end
-- ends in és
if rfind(form, "és$") then return {rsub(form, "és$", "es") .. "es"} end
-- ends in an unstressed vowel + ç (lhápeç - > lhápeç)
if rfind(form, AV .. ".*" .. V .. "ç$") then return {form} end
-- ends in a stressed vowel + ç
if rfind(form, V .. "ç$") then
return {rsub(form, "ç$", "zes")}
end
if rfind(form, V .. "$") then return {form .. "es"} end
return nil
end
function export.make_feminine(form, special)
local retval = require(romut_module).handle_multiword(form, special, export.make_feminine, prepositions)
if retval then
if #retval ~= 1 then
error("Internal error: Should have one return value for make_feminine: " .. table.concat(retval, ","))
end
return retval
end
if form:find("o$") then
local retval = form:gsub("o$", "a")
return retval
end
if form:find("eu$") then
return rsub(form, "eu$", "eia")
end
if rfind(form, "és$") then
return rsub(form, "és$", "esa")
end
if rfind(form, "dor$") then
return rsub(form, "dor$", "deira")
end
return form
end
function export.make_masculine(form, special)
local retval = require(romut_module).handle_multiword(form, special, export.make_masculine, prepositions)
if retval then
if #retval ~= 1 then
error("Internal error: Should have one return value for make_masculine: " .. table.concat(retval, ","))
end
return retval
end
if form:find("a$") then
local retval = form:gsub("a$", "o")
return retval
end
return form
end
return export