Mòdul:oc-pron
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
Mòdul de suport per la plantilla:oc-pron. Vegeu la documentació de la plantilla.
local p = {}
local senseDiacritics = {
["à"] = "a", ["á"] = "ɔ",
["è"] = "ε", ["é"] = "e",
["í"] = "i", ["ï"] = "i", ["ì"] = "j",
["ò"] = "ɔ", ["ó"] = "u",
["ú"] = "y", ["ü"] = "y", ["ù"] = "w"
}
local function diftongs(mot)
-- marcatge intern: ì, ù consonants
-- Triftong uòu
mot = mw.ustring.gsub(mot, "uòu", "ìòù")
-- Diftongs creixents ia (no final), iá, iè, uè, ue, ui, uò, ió, uo
mot = mw.ustring.gsub(mot, "i([aáèóo])", "ì%1")
mot = mw.ustring.gsub(mot, "ìa(s?)$", "ia%1")
mot = mw.ustring.gsub(mot, "u([èeiòo])", "ù%1")
-- Diftongs decreixents ai, au, èi, èu, ei, eu, iu, òi, òu, oi, ou
mot = mw.ustring.gsub(mot, "([aèeòo])i", "%1ì")
mot = mw.ustring.gsub(mot, "([aèeòo])u", "%1ù")
mot = mw.ustring.gsub(mot, "iu", "iù")
return mot
end
local function accent(mot)
if not mw.ustring.find(mot, "[àáèéíòóú]") then
local accentuar = {["a"]="à", ["e"]="é", ["i"]="í", ["o"]="ó", ["u"]="ú"}
-- Vocal a accentuar, des del final
local accent = 2
if not string.find(mot, "[aeiou]s?$") then
accent = 1
end
local vocals = 0
for i = mw.ustring.len(mot), 1, -1 do
local lletra = mw.ustring.sub(mot, i, i)
if string.find(lletra, "[aeiou]") then
vocals = vocals + 1
if vocals == accent then
local accentuat = mw.ustring.gsub(lletra, ".", accentuar) .. mw.ustring.sub(mot, i+1)
if i > 1 then
accentuat = mw.ustring.sub(mot, 1, i-1) .. accentuat
end
return accentuat
end
end
end
if not mw.ustring.find(mot, "[àèéìòóù]") then
mot = mw.ustring.gsub(mot, "[aeiou]", accentuar, 1)
end
end
return mot
end
--[[
Sil·labificació
marcatge intern: vocals 0, obertures 1, codes 2
síl·laba: ·(1*)0(2*)·
]]
function p.sil(mot)
if type(mot) == "table" then mot = mot.args[1] end -- des de plantilles via invoke o des de mòduls via require
if mot == "" or mot == nil then
mot = mw.title.getCurrentTitle().text
end
mot = diftongs(mot)
-- Si no hi ha cap accent el posem
if not mw.ustring.find(mot, "[àèéíòóú]") then
mot = accent(mot)
end
local sil = mw.ustring.lower(mot)
sil = mw.ustring.gsub(sil, "[qg][uü][aàáeèéiíïoòóuúü]", "110")
sil = mw.ustring.gsub(sil, "[aàáeèéiíoòóuú][ìù]", "02")
sil = mw.ustring.gsub(sil, "[^aàáeèéiíoòóuú][ìù][aàáeèéiíoòóuú]", "110")
-- Nuclis vocàlics
sil = mw.ustring.gsub(sil, "[aàáeèéiíïoòóuúü]", "0")
-- Codes finals
sil = string.gsub(sil, "%l$", "2")
sil = string.gsub(sil, "%l2$", "22")
sil = string.gsub(sil, "%l22$", "222")
-- Obertures
sil = string.gsub(sil, "^%l", "1")
sil = string.gsub(sil, "^1%l", "11")
sil = string.gsub(sil, "^11%l", "111")
sil = string.gsub(sil, "ch0", "110")
sil = string.gsub(sil, "lh0", "110")
sil = string.gsub(sil, "nh0", "110")
sil = string.gsub(sil, "[ptcfbdg]r", "11")
sil = string.gsub(sil, "[pcfbg]l", "11")
sil = string.gsub(sil, "%l0", "10")
sil = mw.ustring.gsub(sil, "ç0", "10") -- %l no inclou ç
-- Codes interiors
sil = string.gsub(sil, "[ps][%l1]", "21")
sil = string.gsub(sil, "%l([12])", "2%1")
-- Separació de síl·labes
local anterior = ""
local motSil = {}
for i = 1, mw.ustring.len(mot) do
actual = mw.ustring.sub(sil, i, i)
if (actual == "0" or actual == "1") and (anterior == "0" or anterior == "2") then
table.insert(motSil, "·")
end
table.insert(motSil, mw.ustring.sub(mot, i, i))
anterior = actual
end
return table.concat(motSil)
end
-- Pronunciació
function p.pron(mot)
if type(mot) == "table" then mot = mot.args[1] or mw.title.getCurrentTitle().text end
if string.find(mot, '^/.+/$') then
return mot
end
mot_sil = {}
for mot_i in string.gmatch(mw.ustring.lower(mot), "%S+") do
mot_sil[#mot_sil+1] = p.sil(mot_i)
end
mot = table.concat(mot_sil, " ")
local vocal = "[aàáeèéiíïìoòóuúù]"
-- dígrafs
mot = mw.ustring.gsub(mot, "b(·?)s", "p%1s")
mot = string.gsub(mot, "ch", "tʃ")
mot = mw.ustring.gsub(mot, "q[uù]", "k")
mot = mw.ustring.gsub(mot, "gui([aàáeèéoòóuú])", "gwj%1")
mot = mw.ustring.gsub(mot, "gu([eèéií])", "g%1")
mot = mw.ustring.gsub(mot, "nh(%l)", "ɲ%1")
mot = mw.ustring.gsub(mot, "lh(%l)", "ʎ%1")
mot = mw.ustring.gsub(mot, "s(·?)h", "%1ʃ")
mot = string.gsub(mot, "tj", "tʃ")
mot = mw.ustring.gsub(mot, "t(·?)z", "%1ts")
mot = string.gsub(mot, "lt$", "l")
-- geminació/assimilació
mot = mw.ustring.gsub(mot, "("..vocal..")·([bg])l", "%1%2·%2l")
mot = mw.ustring.gsub(mot, "b(·?)d", "d%1d")
mot = mw.ustring.gsub(mot, "b(·?)j", "%1j")
mot = mw.ustring.gsub(mot, "[dgt](·?)m", "m%1m")
mot = mw.ustring.gsub(mot, "t(·?)l", "l%1l")
mot = mw.ustring.gsub(mot, "g·f", "f·f")
mot = mw.ustring.gsub(mot, "[bgmt](·?)n", "n%1n")
mot = string.gsub(mot, "mp·", "n·") -- excepció mp·t>t·t
mot = mw.ustring.gsub(mot, "[bcp](·?)t", "t%1t")
mot = string.gsub(mot, "gd", "tt")
-- consonants
if string.find(mot, "[bv]") then
mot = string.gsub(mot, "v", "b")
mot = string.gsub(mot, "b$", "p")
--mot = mw.ustring.gsub(mot, "("..vocal.."·?)b("..vocal..")", "%1β%2") -- només llenguadocià i gascó
--mot = mw.ustring.gsub(mot, "([rlz]·?)b", "%1β")
--mot = mw.ustring.gsub(mot, "b([rlz])", "β%1")
end
if string.find(mot, "d") then
mot = string.gsub(mot, "d$", "t")
--mot = mw.ustring.gsub(mot, "("..vocal.."·?)d("..vocal..")", "%1ð%2") -- només llenguadocià i gascó
--mot = mw.ustring.gsub(mot, "([rlz]·?)d", "%1ð")
--mot = mw.ustring.gsub(mot, "d([rlz])", "ð%1")
end
if string.find(mot, "g") then
mot = mw.ustring.gsub(mot, "t(·?)g([eèéiíì])", "%1dʒ%2")
--mot = mw.ustring.gsub(mot, "("..vocal.."·?)g([ei])", "%1tʃ%2")
--mot = mw.ustring.gsub(mot, "("..vocal.."·?)g([eèéiíì])", "%1dʒ%2")
mot = mw.ustring.gsub(mot, "g([eèéiíì])", "dʒ%1")
mot = mw.ustring.gsub(mot, "("..vocal.."·?)g$", "%1tʃ")
--mot = mw.ustring.gsub(mot, "([^aeèéiíìoòóuúù]·?)g([ei])", "%1ʃ%2")
--mot = mw.ustring.gsub(mot, "([^aeèéiíìoòóuúù]·?)g$", "%1ʃ")
mot = mw.ustring.gsub(mot, "([^aeèéiíìoòóuúù]·?)g$", "%1k")
--mot = mw.ustring.gsub(mot, "("..vocal.."·?)g("..vocal..")", "%1ɣ%2") -- només llenguadocià i gascó
--mot = mw.ustring.gsub(mot, "([rlz]·?)g", "%1ɣ")
--mot = mw.ustring.gsub(mot, "g([rlz])", "ɣ%1")
end
if string.find(mot, "j") then
mot = mw.ustring.gsub(mot, "t(·?)j([aoòóuúù])", "%1tʃ%2")
mot = string.gsub(mot, "j", "dʒ")
end
if string.find(mot, "[mn]") then
mot = mw.ustring.gsub(mot, "([^r])n(s?)$", "%1%2")
mot = string.gsub(mot, "n[dht]$", "n")
--mot = string.gsub(mot, "ns", "s")
mot = mw.ustring.gsub(mot, "n(·?[bmp])", "m%1")
mot = mw.ustring.gsub(mot, "n(·?[kg])", "ŋ%1")
mot = mw.ustring.gsub(mot, "n(·?)f", "ɱ%1f")
mot = mw.ustring.gsub(mot, "m(·[^aàáeèéiíoòóuúbmp])", "n%1")
mot = string.gsub(mot, "mp?(s?)$", "n%1")
mot = mw.ustring.gsub(mot, "mp·", "n·")
end
mot = string.gsub(mot, "h", "") -- atenció nh final
mot = mw.ustring.gsub(mot, "qü", "kw")
if string.find(mot, "r") then
mot = string.gsub(mot, "r(s?)$", "%1")
mot = string.gsub(mot, "r", "ɾ")
mot = mw.ustring.gsub(mot, "^ɾ", "r")
mot = mw.ustring.gsub(mot, "ɾ·ɾ", "·r")
mot = mw.ustring.gsub(mot, "ɾ[mn]$", "ɾ")
mot = mw.ustring.gsub(mot, "([nl])ɾ", "%1r")
end
if string.find(mot, "s") then
mot = mw.ustring.gsub(mot, "sɾ", "rr")
mot = mw.ustring.gsub(mot, "(" .. vocal .. "·?)s(" .. vocal .. ")", "%1z%2")
mot = mw.ustring.gsub(mot, "s(·?[bdgmnv])", "z%1")
mot = mw.ustring.gsub(mot, "s(·?s)", "%1")
end
if mw.ustring.find(mot, "[cçp]") then
mot = mw.ustring.gsub(mot, "ç", "s")
mot = mw.ustring.gsub(mot, "[cp](·?)s", "%1ts")
mot = mw.ustring.gsub(mot, "[cp](·?)c([eèéiíì])", "%1ts%2")
mot = mw.ustring.gsub(mot, "s(·?)c([eèéiíì])", "%1s%2")
mot = mw.ustring.gsub(mot, "c([eèéiíì])", "s%1")
mot = string.gsub(mot, "c", "k")
end
if string.find(mot, "x") then
mot = string.gsub(mot, "x·s", "·ts")
mot = mw.ustring.gsub(mot, "x(·?[^aàáeèéiíìoòóuúù])", "s%1")
mot = string.gsub(mot, "x", "ts")
end
mot = string.gsub(mot, "z$", "s")
-- vocals
mot = string.gsub(mot, "u", "y")
mot = string.gsub(mot, "o", "u")
mot = string.gsub(mot, "a(s?)$", "o̞%1")
mot = mw.ustring.gsub(mot, "a(·mén)$", "o̞%1") -- adverbis
-- accent
if mw.ustring.find(mot, "[àáèéíóòú]") then
mot = mw.ustring.gsub(mot, "·(%l-[àáèéíòóú])", "ˈ%1")
else
mot = mw.ustring.gsub(mot, "·(%l-)·(%l-)$", "ˈ%1·%2")
end
if not mw.ustring.find(mot, "ˈ") then -- monosíl·lab o accent en la primera
mot = "ˈ" .. mot
end
mot = mw.ustring.gsub(mot, "ˈ(.+)ˈ", "ˌ%1ˈ")
mot = mw.ustring.gsub(mot, "^(%l-[àáèéíòóú])(.+)ˈ", "ˌ%1%2ˈ")
mot = mw.ustring.gsub(mot, ".", senseDiacritics)
mot = mw.ustring.gsub(mot, "tʃ", "t͡ʃ")
mot = mw.ustring.gsub(mot, "dʒ", "d͡ʒ")
mot = string.gsub(mot, "g", "ɡ")
mot = string.gsub(mot, "ts", "t͡s")
mot = string.gsub(mot, "dz", "d͡z")
return '/' .. mw.ustring.gsub(mot, "·", ".") .. '/'
end
function p.plantilla_pron(frame)
local args = frame:getParent().args
local mot = args[1] or mw.title.getCurrentTitle().text
local ret = ':*<span style="font-weight: bold;">Pronúncia</span><sup>[[Viccionari:Pronúncia de l\'occità|(i)]]</sup>: '
ret = ret .. '<span class="IPA" title="pronúncia AFI">' .. p.pron(mot) .. '</span>'
if args[2] then
ret = ret .. ', <span class="IPA" title="pronúncia AFI">' .. p.pron(args[2]) .. '</span>'
end
return ret
end
return p