Mòdul:ca-pron/AFI
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
Mòdul que genera la pronúncia en català. La sortida és formatada amb el Mòdul:ca-pron.
local function list_true(list)
for i, val in ipairs(list) do
list[val] = true
end
return list
end
local valid_onsets = list_true({
"b", "bl", "br",
"c", "cl", "cr",
"ç",
"d", "dr",
"f", "fl", "fr",
"g", "gl", "gr", "gu", "gü",
"h", "hh", -- hint for aspirated h
"i",
"j",
"k", "kl", "kr",
"l", "ll", "L", -- hint for iodització
"m",
"n", "ny", "ñ",
"p", "pl", "pr",
"qu", "qü",
"r", "rr",
"s", "ss",
"t", "tg", "tj", "tr", "tx", "tz",
"u",
"v", "vl",
"w",
"x",
"z",
})
local function fix_prefixes(word)
-- Orthographic fixes for unassimilated prefixes
local prefix = {
"a[eè]ro", "ànte", "[aà]nti", "[aà]rxi", "[aà]uto", -- a- is ambiguous as prefix
"bi", "b[ií]li", "bio",
"c[oò]ntra", -- ambiguous co-
"dia", "dodeca",
"[eé]ntre", "equi", "estereo", -- ambiguous e-(radic)
"f[oó]to",
"g[aà]stro", "gr[eé]co",
"hendeca", "hepta", "hexa", "h[oò]mo",
"[ií]nfra", "[ií]ntra",
"m[aà]cro", "m[ií]cro", "mono", "morfo", "m[uú]lti",
"n[eé]o",
"octo", "orto",
"penta", "p[oòô]li", "pol[ií]tico", "pr[oòô]to", "ps[eèê]udo", "psico", -- ambiguous pre-(s), pro-
"qu[aà]si", "qu[ií]mio",
"r[aà]dio", -- ambiguous re-
"s[eèê]mi", "s[oó]bre", "s[uú]pra",
"termo", "tetra", "tri", -- ambiguous tele-(r)
"[uú]ltra", "[uu]n[ií]",
"v[ií]ce"
}
local prefix_r = {"[eèéê]xtra", "pr[eé]"}
local prefix_s = {"antropo", "centro", "deca", "d[ií]no", "eco", "[eèéê]xtra",
"hetero", "p[aà]ra", "post", "pré", "s[oó]ta", "tele"}
local prefix_i = {"pr[eé]", "pr[ií]mo", "pro", "tele"}
local no_prefix = {"autoic", "autori", "biret", "biri", "bisa", "bisell", "bisó", "biur", "contrari", "contrau",
"diari", "equise", "heterosi", "monoi", "parasa", "parasit", "preix", "psicosi", "sobrera", "sobreri"}
-- False prefixes
for _, pr in ipairs(no_prefix) do
if mw.ustring.find(word, "^" .. pr) then
return word
end
end
-- Double r in prefix + r + vowel
for _, pr in ipairs(prefix_r) do
word = mw.ustring.gsub(word, "^(" .. pr .. ")r([aàeèéiíïoòóuúü])", "%1rr%2")
end
word = mw.ustring.gsub(word, "^eradic", "erradic")
-- Double s in prefix + s + vowel
for _, pr in ipairs(prefix_s) do
word = mw.ustring.gsub(word, "^(" .. pr .. ")s([aàeèéiíïoòóuúü])", "%1ss%2")
end
-- Hiatus in prefix + i
for _, pr in ipairs(prefix_i) do
word = mw.ustring.gsub(word, "^(" .. pr .. ")i(.)", "%1ï%2")
end
-- Both prefix + r/s or i/u
for _, pr in ipairs(prefix) do
word = mw.ustring.gsub(word, "^(" .. pr .. ")([rs])([aàeèéiíïoòóuúü])", "%1%2%2%3")
word = mw.ustring.gsub(word, "^(" .. pr .. ")i(.)", "%1ï%2")
word = mw.ustring.gsub(word, "^(" .. pr .. ")u(.)", "%1ü%2")
end
-- Voiced s in prefix roots -fons-, -dins-, -trans-
word = mw.ustring.gsub(word, "^enfons([aàeèéiíoòóuú])", "enfonz%1")
word = mw.ustring.gsub(word, "^endins([aàeèéiíoòóuú])", "endinz%1")
word = mw.ustring.gsub(word, "tr([aà])ns([aàeèéiíoòóuúbdghlmv])", "tr%1nz%2")
-- in + ex > ineks/inegz
word = mw.ustring.gsub(word, "^inex", "inhex")
return word
end
local function restore_diaereses(word)
-- Some structural forms do not have diaeresis per diacritic savings, let's restore it to identify hiatus
word = mw.ustring.gsub(word, "([iu])um(s?)$", "%1üm%2") -- Latinisms (-ius is ambiguous but rare)
word = mw.ustring.gsub(word, "([aeiou])isme(s?)$", "%1ísme%2") -- suffix -isme
word = mw.ustring.gsub(word, "([aeiou])ist([ae]s?)$", "%1íst%2") -- suffix -ista
word = mw.ustring.gsub(word, "([aeou])ir$", "%1ír") -- verbs -ir
word = mw.ustring.gsub(word, "([aeou])int$", "%1ínt") -- present participle
word = mw.ustring.gsub(word, "([aeo])ir([éà])$", "%1ïr%2") -- future
word = mw.ustring.gsub(word, "([^gq]u)ir([éà])$", "%1ïr%2")
word = mw.ustring.gsub(word, "([aeo])iràs$", "%1ïràs")
word = mw.ustring.gsub(word, "([^gq]u)iràs$", "%1ïràs")
word = mw.ustring.gsub(word, "([aeo])ir(e[mu])$", "%1ïr%2")
word = mw.ustring.gsub(word, "([^gq]u)ir(e[mu])$", "%1ïr%2")
word = mw.ustring.gsub(word, "([aeo])iran$", "%1ïran")
word = mw.ustring.gsub(word, "([^gq]u)iran$", "%1ïran")
word = mw.ustring.gsub(word, "([aeo])iria$", "%1ïria") -- conditional
word = mw.ustring.gsub(word, "([^gq]u)iria$", "%1ïria")
word = mw.ustring.gsub(word, "([aeo])ir(ie[sn])$", "%1ïr%2")
word = mw.ustring.gsub(word, "([^gq]u)ir(ie[sn])$", "%1ïr%2")
return word
end
local function fix_y(word)
-- hint for Balearic iodització
word = string.gsub(word, "yll", "L")
-- hint for voiced palatal nasal
word = mw.ustring.gsub(word, "ny", "ñ")
-- y > vowel /i/ else consonant /j/
word = mw.ustring.gsub(word, "y([^aeiouàèéêíòóôúïü])", "i%1") -- vowel if not next to another vowel
word = mw.ustring.gsub(word, "([^aeiouàèéêíòóôúïü·%-%.])y", "%1i") -- excluding also syllables separators
return word
end
local function word_fixes(word)
word = mw.ustring.gsub(word, "%-([rs]?)", "-%1%1")
word = mw.ustring.gsub(word, "rç$", "rrs") -- silent r only in plurals -rs
word = fix_prefixes(word) -- internal pause after a prefix
word = restore_diaereses(word) -- no diaeresis saving
word = fix_y(word) -- ny > ñ else y > i vowel or consonant
return word
end
local function split_vowels(vowels)
local syllables = {{onset = "", vowel = mw.ustring.sub(vowels, 1, 1), coda = ""}}
vowels = mw.ustring.sub(vowels, 2)
while vowels ~= "" do
local syll = {onset = "", vowel = "", coda = ""}
syll.onset, syll.vowel, vowels = mw.ustring.match(vowels, "^([iu]?)(.)(.-)$")
table.insert(syllables, syll)
end
local count = #syllables
if count >= 2 and (syllables[count].vowel == "i" or syllables[count].vowel == "u") then
syllables[count - 1].coda = syllables[count].vowel
syllables[count] = nil
end
return syllables
end
-- Split the word into syllables
local function split_syllables(remainder)
local syllables = {}
while remainder ~= "" do
local consonants, vowels
consonants, remainder = mw.ustring.match(remainder, "^([^aeiouàèéêëíòóôúïüāēō]*)(.-)$")
vowels, remainder = mw.ustring.match(remainder, "^([aeiouàèéêëíòóôúïüāēō]*)(.-)$")
if vowels == "" then
syllables[#syllables].coda = syllables[#syllables].coda .. consonants
else
local onset = consonants
local first_vowel = mw.ustring.sub(vowels, 1, 1)
if (mw.ustring.find(onset, "[gq]$") and (first_vowel == "ü" or (first_vowel == "u" and vowels ~= "u"))) or
((onset == "" or onset == "h") and #syllables == 0 and first_vowel == "i" and vowels ~= "i" ) then
onset = onset .. mw.ustring.sub(vowels, 1, 1)
vowels = mw.ustring.sub(vowels, 2)
end
local vsyllables = split_vowels(vowels)
vsyllables[1].onset = onset .. vsyllables[1].onset
for _, s in ipairs(vsyllables) do
table.insert(syllables, s)
end
end
end
-- Shift over consonants from the onset to the preceding coda,
-- until the syllable onset is valid
for i = 2, #syllables do
local current = syllables[i]
local previous = syllables[i-1]
while not (current.onset == "" or valid_onsets[current.onset]) do
local letter = mw.ustring.sub(current.onset, 1, 1)
current.onset = mw.ustring.sub(current.onset, 2)
if not mw.ustring.find(letter, "[·%-%.]") then --syllables separators
previous.coda = previous.coda .. letter
else
break
end
end
end
-- Detect stress
for i, syll in ipairs(syllables) do
if mw.ustring.find(syll.vowel, "^[àèéêëíòóôú]$") then
syllables.stress = i -- primary stress: the last one stressed
syll.stressed = true
end
end
if not syllables.stress then
local count = #syllables
if count == 1 then
syllables.stress = 1
else
local final = syllables[count]
if final.coda == "" or final.coda == "s" or (final.coda == "n" and (final.vowel == "e" or final.vowel == "i" or final.vowel == "ï")) then
syllables.stress = count - 1
else
syllables.stress = count
end
end
syllables[syllables.stress].stressed = true
end
return syllables
end
local function mid_vowel_e(syllables)
-- most common cases, other ones are supposed ambiguous
post_consonants = syllables[syllables.stress].coda
post_vowel = ""
post_letters = post_consonants
if syllables.stress == #syllables - 1 then
post_consonants = post_consonants .. syllables[#syllables].onset
post_vowel = syllables[#syllables].vowel
post_letters = post_consonants .. post_vowel .. syllables[#syllables].coda
end
if syllables[syllables.stress].vowel == "e" then
if post_vowel == "i" or post_vowel == "u" then
return "è"
elseif mw.ustring.find(post_letters, "^ct[ae]?s?$") then
return "è"
elseif post_letters == "dre" or post_letters == "dres" then
return "é"
elseif mw.ustring.find(post_consonants, "^l") and syllables.stress == #syllables then
return "è"
elseif post_consonants == "l" or post_consonants == "ls" or post_consonants == "l·l" then
return "è"
elseif (post_letters == "ma" or post_letters == "mes") and #syllables > 2 then
return "ê"
elseif post_letters == "ns" or post_letters == "na" or post_letters == "nes" then -- inflection of -è
return "ê"
elseif post_letters == "nse" or post_letters == "nses" then
return "ê"
elseif post_letters == "nt" or post_letters == "nts" then
return "é"
elseif mw.ustring.find(post_letters, "^r[ae]?s?$") then
return "é"
elseif mw.ustring.find(post_consonants, "^r[dfjlnrstxyz]") then -- except bilabial and velar
return "è"
elseif post_letters == "sos" or post_letters == "sa" or post_letters == "ses" then -- inflection of -ès
return "ê"
elseif mw.ustring.find(post_letters, "^t[ae]?s?$") then
return "ê"
end
elseif syllables[syllables.stress].vowel == "è" then
if syllables.stress == #syllables and (post_letters == "s" or post_letters == "") then -- -ès, -è
return "ê"
else
return "è"
end
end
return nil
end
local function mid_vowel_o(syllables)
-- most common cases, other ones are supposed ambiguous
post_consonants = syllables[syllables.stress].coda
post_vowel = ""
post_letters = post_consonants
if syllables.stress == #syllables - 1 then
post_consonants = post_consonants .. syllables[#syllables].onset
post_vowel = syllables[#syllables].vowel
post_letters = post_consonants .. post_vowel .. syllables[#syllables].coda
end
if post_vowel == "i" or post_vowel == "u" then
return "ò"
elseif mw.ustring.sub(post_letters, 1, 1) == "i" and mw.ustring.sub(post_letters, 1, 2) ~= "ix" then -- diphthong oi except oix
return "ò"
elseif mw.ustring.find(post_letters, "^u[^s]") then -- diphthong ou, ambiguous if final
return "ò"
elseif #syllables == 1 and (post_letters == "" or post_letters == "s" or post_letters == "ns") then -- monosyllable
return "ò"
elseif post_letters == "fa" or post_letters == "fes" then
return "ò"
elseif post_consonants == "fr" then
return "ó"
elseif post_letters == "ldre" then
return "ò"
elseif post_letters == "ma" or post_letters == "mes" then
return "ó"
elseif post_letters == "ndre" then
return "ò"
elseif mw.ustring.find(post_letters, "^r[ft]s?$") then
return "ò"
elseif mw.ustring.find(post_letters, "^r[ae]?s?$") then
return "ó"
elseif post_letters == "rme" or post_letters == "rmes" then
return "ó"
end
return nil
end
local IPA_vowels = {
["a"] = "a", ["à"] = "a",
["e"] = "e", ["è"] = "ɛ", ["é"] = "e",
["i"] = "i", ["í"] = "i", ["ï"] = "i",
["o"] = "o", ["ò"] = "ɔ", ["ó"] = "o",
["u"] = "u", ["ú"] = "u", ["ü"] = "u",
}
local function replace_context_free(cons)
--cons = mw.ustring.gsub(cons, "·", "")
cons = mw.ustring.gsub(cons, "r", "ɾ")
cons = mw.ustring.gsub(cons, "ɾɾ", "r")
cons = mw.ustring.gsub(cons, "ss", "s")
cons = mw.ustring.gsub(cons, "ll", "ʎ") -- pending L by accent
cons = mw.ustring.gsub(cons, "ñ", "ɲ") -- hint ny > ñ
if mw.ustring.find(cons, "hh") then
cons = mw.ustring.gsub(cons, "hh", "h") -- hint hh > /h/
else
cons = mw.ustring.gsub(cons, "h", "")
end
cons = mw.ustring.gsub(cons, "[dt]j", "d͡ʒ")
cons = mw.ustring.gsub(cons, "tx", "t͡ʃ")
cons = mw.ustring.gsub(cons, "[dt]z", "d͡z")
cons = mw.ustring.gsub(cons, "ç", "s")
cons = mw.ustring.gsub(cons, "[cq]", "k")
cons = mw.ustring.gsub(cons, "l", "ɫ")
cons = mw.ustring.gsub(cons, "g", "ɡ")
cons = mw.ustring.gsub(cons, "j", "ʒ")
cons = mw.ustring.gsub(cons, "x", "ʃ")
cons = mw.ustring.gsub(cons, "[iy]", "j") -- must be after j > ʒ and fix_y
cons = mw.ustring.gsub(cons, "[uü]", "w")
return cons
end
local function postprocess_general(syllables)
syllables = mw.clone(syllables)
local voiced = list_true({"b", "d", "ɡ", "m", "n", "ɲ", "ɫ", "ʎ", "r", "ɾ", "v", "z", "ʒ"})
local voiceless = list_true({"p", "t", "k", "f", "s", "ʃ", ""})
local devoicing = {["b"]="p", ["d"]="t", ["ɡ"]="k"}
local voicing = {["p"]="b", ["t"]="d", ["k"]="ɡ", ["f"]="v", ["s"]="z", ["ʃ"]="ʒ"}
for i = 1, #syllables do
local current = syllables[i]
local previous = syllables[i - 1]
-- Coda consonant losses
if i < #syllables or (i == #syllables and mw.ustring.find(current.coda, "s$")) then
current.coda = mw.ustring.gsub(current.coda, "m[pb]", "m")
current.coda = mw.ustring.gsub(current.coda, "([ɫn])[td]", "%1")
end
-- Consonant assimilations
if i > 1 then
-- t + lateral/nasal assimilation, not t+[mn] in Valencian
if mw.ustring.find(current.onset, "^ʎ") then
previous.coda = mw.ustring.gsub(previous.coda, "t$", "ʎ")
end
-- nasal + labial > labialized assimilation
if mw.ustring.find(current.onset, "^[mbp]") then
previous.coda = mw.ustring.gsub(previous.coda, "n$", "m")
elseif mw.ustring.find(current.onset, "^[fv]") then
previous.coda = mw.ustring.gsub(previous.coda, "[mn]$", "ɱ")
-- n + velar > velarized assimilation
elseif mw.ustring.find(current.onset, "^[ɡk]") then
previous.coda = mw.ustring.gsub(previous.coda, "n$", "ŋ")
-- l/n + palatal > palatalized assimilation
elseif mw.ustring.find(current.onset, "^[ʒʎʃɲ]")
or mw.ustring.find(current.onset, "^t͡ʃ")
or mw.ustring.find(current.onset, "^d͡ʒ")
then
if not (previous.coda == "ɫ" and current.onset == "ʒ") then -- only in Central
previous.coda = mw.ustring.gsub(previous.coda, "[ɫn]$", {["ɫ"] = "ʎ", ["n"] = "ɲ"})
end
end
-- ɡʒ > d͡ʒ
if previous.coda == "ɡ" and current.onset == "ʒ" then
previous.coda = ""
current.onset = "d͡ʒ"
end
end
current.coda = mw.ustring.gsub(current.coda, "[mn]([fv])", "ɱ%1")
current.coda = mw.ustring.gsub(current.coda, "n[kɡ]", "ŋk")
current.coda = mw.ustring.gsub(current.coda, "n([ʃʒ])", "ɲ%1")
current.coda = mw.ustring.gsub(current.coda, "n(t͡ʃ)", "ɲ%1")
current.coda = mw.ustring.gsub(current.coda, "n(d͡ʒ)", "ɲ%1")
current.coda = mw.ustring.gsub(current.coda, "ɫʃ", "ʎʃ") -- ɫʒ only in Central
current.coda = mw.ustring.gsub(current.coda, "ɫ(t͡ʃ)", "ʎ%1")
--current.coda = mw.ustring.gsub(current.coda, "ɫ(d͡ʒ)", "ʎ%1")
-- Voicing or devoicing
if i > 1 then
local coda_letter = mw.ustring.sub(previous.coda, -1)
local onset_letter = mw.ustring.sub(current.onset, 1, 1)
if voiced[onset_letter] and voicing[coda_letter] then
previous.coda = mw.ustring.gsub(previous.coda, coda_letter .. "$", voicing[coda_letter])
elseif voiceless[onset_letter] and devoicing[coda_letter] then
previous.coda = mw.ustring.gsub(previous.coda, coda_letter .. "$", devoicing[coda_letter])
end
previous.coda = mw.ustring.gsub(previous.coda, "[bd]s", {["bs"] = "ps", ["ds"] = "ts"})
end
-- Allophones of r
if i == 1 then
current.onset = mw.ustring.gsub(current.onset, "^ɾ", "r")
end
if i > 1 and mw.ustring.find(previous.coda, "[ɫn]$") then
current.onset = mw.ustring.gsub(current.onset, "^ɾ", "r")
end
-- Double sound of letter x > ks/gz (on cultisms, ambiguous in onsets)
current.coda = mw.ustring.gsub(current.coda, "^ʃs?", "ks")
if i > 1 and previous.coda == "kz" then
previous.coda = "ɡz" -- voicing the group
end
if i > 1 and current.onset == "s" then
previous.coda = mw.ustring.gsub(previous.coda, "s$", "") -- reduction exs, exc(e/i) and sc(e/i)
end
if i > 1 and previous.onset == "" and (previous.vowel == "e" or previous.vowel == "ɛ")
and ((previous.coda == "" and current.onset == "ʃ") or (previous.coda == "ks" and current.onset == ""))
then
-- ex + (h) vowel > egz
previous.coda = "ɡ"
current.onset = "z"
end
-- Spirant lenition
if i > 1
and mw.ustring.find(current.onset, "^[bdɡ]")
and not mw.ustring.find(current.onset, "^d͡")
and not mw.ustring.find(previous.coda, "[pbtdkɡmɱnɲŋ]$")
and not (mw.ustring.find(previous.coda, "[ɫʎ]") and current.onset == "d")
and (previous.stressed == nil or current.stressed == nil)
then
current.onset = mw.ustring.gsub(current.onset, "[bdɡ]", {["b"] = "β", ["d"] = "ð", ["ɡ"] = "ɣ"})
end
end
-- Final devoicing
local final = syllables[#syllables].coda
final = mw.ustring.gsub(final, "d͡ʒ", "t͡ʃ")
final = mw.ustring.gsub(final, "d͡z", "t͡s")
final = mw.ustring.gsub(final, "b", "p")
final = mw.ustring.gsub(final, "d", "t")
final = mw.ustring.gsub(final, "ɡ", "k")
final = mw.ustring.gsub(final, "ʒ", "ʃ")
final = mw.ustring.gsub(final, "v", "f")
final = mw.ustring.gsub(final, "z", "s")
-- Final loses
final = mw.ustring.gsub(final, "j(t͡ʃ)$", "%1")
final = mw.ustring.gsub(final, "([ʃs])s", "%1") -- homophone plurals -xs, -çs
syllables[#syllables].coda = final
return syllables
end
local function to_IPA(syllables, mid_vowel_hint)
-- Ambiguous stressed vowel
if mw.ustring.find(syllables[syllables.stress].vowel, "[eéèoòó]") then
if mid_vowel_hint then
syllables[syllables.stress].vowel = mid_vowel_hint
elseif syllables[syllables.stress].vowel == "e" or syllables[syllables.stress].vowel == "o" then
error("Pronúncia \"" .. syllables[syllables.stress].vowel .. "\" ambigua.[[Categoria:Paraules en català sense transcripció fonètica]]")
end
end
local syllables_IPA = {stress = syllables.stress}
for key, val in ipairs(syllables) do
syllables_IPA[key] = {onset = val.onset, vowel = val.vowel, coda = val.coda, stressed = val.stressed}
end
-- Replace letters with IPA equivalents
for i, syll in ipairs(syllables_IPA) do
-- Voicing of s
if syll.onset == "s" and i > 1 and (syllables[i-1].coda == "" or syllables[i-1].coda == "i" or syllables[i-1].coda == "u") then
syll.onset = "z"
end
if mw.ustring.find(syll.vowel, "^[eèéêëēií]$") then
syll.onset = mw.ustring.gsub(syll.onset, "tg$", "d͡ʒ")
syll.onset = mw.ustring.gsub(syll.onset, "[cg]$", {["c"] = "s", ["g"] = "ʒ"})
syll.onset = mw.ustring.gsub(syll.onset, "[qg]u$", {["qu"] = "k", ["gu"] = "ɡ"})
end
syll.coda = mw.ustring.gsub(syll.coda, "ig(s?)$", "id͡ʒ%1")
syll.onset = replace_context_free(syll.onset)
syll.coda = replace_context_free(syll.coda)
syll.vowel = mw.ustring.gsub(syll.vowel, ".", IPA_vowels)
end
syllables_IPA = postprocess_general(syllables_IPA)
return syllables_IPA
end
local function reduction_ae(syllables)
for i = 1, #syllables do
local current = syllables[i]
local previous = syllables[i - 1] or {onset = "", vowel = "", coda = ""}
local posterior = syllables[i + 1] or {onset = "", vowel = "", coda = ""}
local pre_vowel_pair = previous.vowel .. previous.coda .. current.onset .. current.vowel
local post_vowel_pair = current.vowel .. current.coda .. posterior.onset .. posterior.vowel
local reduction = true
if current.stressed then
reduction = false
elseif pre_vowel_pair == "əe" then
reduction = false
elseif post_vowel_pair == "ea" or post_vowel_pair == "eɔ" then
reduction = false
elseif i < syllables.stress -1 and post_vowel_pair == "ee" then
posterior.vowel = "ə" -- avoid əe in next loop
elseif i > syllables.stress and post_vowel_pair == "ee" then
reduction = false
elseif pre_vowel_pair == "oe" or pre_vowel_pair == "ɔe" then
reduction = false
elseif i == #syllables and i == syllables.stress + 1 and current.vowel == "e" and mw.ustring.find(current.coda, "^k") then
-- only Balearic, need to do it at this point
reduction = false
end
if reduction then
current.vowel = mw.ustring.gsub(current.vowel, "[ae]", "ə")
end
end
return syllables
end
local function nasalAssim(onset, coda) -- tm>mm, tn>nn, pm>mm
if string.find(coda, "d$") and string.find(onset, "m") then
return string.gsub(coda, "d$", "m")
elseif string.find(coda, "d$") and string.find(onset, "n") then
return string.gsub(coda, "d$", "n")
elseif string.find(coda, "b$") and string.find(onset, "m") then
return string.gsub(coda, "b$", "m")
elseif mw.ustring.find(coda, "ɡ$") and string.find(onset, "n") then
-- velarization -gn-, -cn-
return mw.ustring.gsub(coda, "ɡ", "ŋ")
end
return coda
end
local accents = {}
-- Central
local function accent_central(syl, variant)
local syl1 = mw.clone(syl)
-- Reduction of unstressed vowels a,e
syl1 = reduction_ae(syl1)
-- Final consonant losses, in Central and North-western
local final = syl1[#syl1].coda
final = mw.ustring.gsub(final, "^ɾ(s?)$", "%1") -- no loss with hint -rr
final = mw.ustring.gsub(final, "mp$", "m") -- -mp/-mb
final = mw.ustring.gsub(final, "([ɫn])t$", "%1") -- -lt/-nt/-ld/-nd
final = mw.ustring.gsub(final, "[nŋ][kɡ](s?)$", "ŋ%1")
final = mw.ustring.gsub(final, "ɾts$", "ɾs")
final = mw.ustring.gsub(final, "jt͡ʃ$", "jt͡s") -- iodització v+igs: raigs > rajts
syl1[#syl1].coda = final
for i = 1, #syl1 do
local current = syl1[i]
local previous = syl1[i-1]
if current.stressed then
current.vowel = mw.ustring.gsub(current.vowel, "[êëô]", {["ê"] = "ɛ", ["ë"] = "ɛ", ["ô"] = "ɔ"})
end
-- Reduction of unstressed -ec (no reduction in Majorcan)
if i == #syl1 and i == syl1.stress + 1 and not current.stressed and mw.ustring.find(current.coda, "^k") then
current.vowel = mw.ustring.gsub(current.vowel, "e", "ə")
end
-- Reduction of unstressed o
if current.vowel == "o" and not (current.stressed or current.coda == "w") then
current.vowel = mw.ustring.gsub(current.vowel, "o", "u")
end
current.onset = mw.ustring.gsub(current.onset, "L", "ʎ")
current.coda = mw.ustring.gsub(current.coda, "L", "ʎ")
-- ɫ + ʒ (-lj-/-lg-) > palatalized assimilation
if current.onset == "ʒ" and previous then
if not (i == 2 and previous.onset == "m" and previous.vowel == "a" and previous.coda == "ɫ") -- except prefix mal-
and not (i > 2 and i == #syl1 - 1 and previous.vowel == "a" and previous.coda == "ɫ" and current.vowel == "i" and current.coda == "" and string.find(syl1[#syl1].onset, "^k?") and syl1[#syl1].vowel == "ə") -- except cultisms -àlgia/es, -àlgica/es
and not (i > 2 and i == #syl1 and previous.vowel == "a" and previous.coda == "ɫ" and current.vowel == "i" and string.find(current.coda, "^ks?")) -- except cultisms -àlgic/s
then
previous.coda = mw.ustring.gsub(previous.coda, "ɫ$", "ʎ")
end
end
current.coda = mw.ustring.gsub(current.coda, "ɫʒ", "ʎʒ")
-- nasal assimilations
if previous then previous.coda = nasalAssim(current.onset, previous.coda) end
-- v > b
if mw.ustring.find(current.onset, "v") then
current.onset = mw.ustring.gsub(current.onset, "v", "b")
if i > 1 and not mw.ustring.find(previous.coda, "[pbtdkɡmɱnɲŋ]$") and (previous.stressed == nil or current.stressed == nil) then
current.onset = mw.ustring.gsub(current.onset, "^b", "β")
elseif i > 1 and mw.ustring.find(current.onset, "^b") then
previous.coda = mw.ustring.gsub(previous.coda, "[ɱn]$", "m")
end
current.coda = mw.ustring.gsub(current.coda, "[ɱn]b", "mb")
end
-- allophones of r
current.coda = mw.ustring.gsub(current.coda, "ɾ", "r")
-- no spirants after r/z
if i > 1 and mw.ustring.find(previous.coda, "[rz]$") then
current.onset = mw.ustring.gsub(current.onset, "^[βðɣ]", {["β"] = "b", ["ð"] = "d", ["ɣ"] = "ɡ"})
end
-- Poststressed gemination bl, gl
if i > 1 and (current.onset == "βɫ" or current.onset == "ɣɫ") and previous.coda == "" and previous.stressed then
current.onset = mw.ustring.gsub(current.onset, "[βɣ]", {["β"] = "b", ["ɣ"] = "ɡ"})
previous.coda = mw.ustring.sub(current.onset, 1, 1)
end
-- Remove j before palatal obstruents
current.coda = mw.ustring.gsub(current.coda, "j([ʃʒ])", "%1")
current.coda = mw.ustring.gsub(current.coda, "j(t͡ʃ)", "%1")
current.coda = mw.ustring.gsub(current.coda, "j(d͡ʒ)", "%1")
if i > 1
and (mw.ustring.find(current.onset, "^[ʃʒ]")
or mw.ustring.find(current.onset, "^t͡ʃ")
or mw.ustring.find(current.onset, "^d͡ʒ")
)
then
previous.coda = mw.ustring.gsub(previous.coda, "j$", "")
end
end
local syl2 = mw.clone(syl1)
-- Final consonant losses, except in Central dialectal
final = syl1[#syl1].coda
final = mw.ustring.gsub(final, "jt͡s$", "t͡ʃ")
syl1[#syl1].coda = final
for i = 1, #syl1 do
if i > 1 and syl1[i].onset == "ɫ" then
syl2[i-1].coda = mw.ustring.gsub(syl2[i-1].coda, "ɫ", "") -- l·l > l
syl2[i-1].coda = mw.ustring.gsub(syl2[i-1].coda, "d", "ɫ")
syl1[i-1].coda = mw.ustring.gsub(syl1[i-1].coda, "d", "ɫ")
end
end
if variant == "1" then
return syl1
end
return syl2
end
accents["cen"] = function(syllabes)
return accent_central(syllabes, "1")
end
accents["cen2"] = function(syllabes)
return accent_central(syllabes, "2")
end
-- Balear dominant, en general mallorquí
accents["bal"] = function(syllables)
syllables = mw.clone(syllables)
-- Reduction of unstressed vowels a,e
syllables = reduction_ae(syllables)
for i = 1, #syllables do
local current = syllables[i]
local previous = syllables[i-1]
if current.stressed then
if string.sub(mw.title.getCurrentTitle().text, -4) == 'r-se' and i < #syllables then
-- change stress in infinitive + -se
current.stressed = nil
syllables[#syllables].stressed = true
syllables.stress = #syllables
current.vowel = mw.ustring.gsub(current.vowel, "[aeêë]", "ə")
else
current.vowel = mw.ustring.gsub(current.vowel, "[êëô]", {["ê"] = "ə", ["ë"] = "ɛ", ["ô"] = "ɔ"})
end
end
-- Reduction of unstressed o per vowel harmony
if i > 1 and current.stressed and mw.ustring.find(current.vowel, "[iu]") and not previous.stressed then
previous.vowel = mw.ustring.gsub(previous.vowel, "o", "u")
end
-- iodització
current.onset = mw.ustring.gsub(current.onset, "L", "j")
current.coda = mw.ustring.gsub(current.coda, "L", "j")
-- nasal assimilation
if previous then previous.coda = nasalAssim(current.onset, previous.coda) end
-- No distintion b/β in v/b area
current.onset = mw.ustring.gsub(current.onset, "β", "b")
-- Gemination bl, gl
if i > 1 and (current.onset == "bɫ" or current.onset == "ɣɫ") and previous.coda == "" then
current.onset = mw.ustring.gsub(current.onset, "ɣ", "ɡ")
previous.coda = mw.ustring.sub(current.onset, 1, 1)
end
-- tl > ll
if i > 1 and current.onset == "ɫ" then
previous.coda = mw.ustring.gsub(previous.coda, "d", "ɫ")
end
-- Palatal plosives in Majorcan
if i == #syllables then
current.coda = mw.ustring.gsub(current.coda, "k", "c")
end
if mw.ustring.find(current.vowel, "[aeəɛi]") then
current.onset = mw.ustring.gsub(current.onset, "^[kɡɣ]$", {["k"] = "c", ["ɡ"] = "ɟ", ["ɣ"] = "ʝ"})
end
-- Fortition of palatal fricative in -ejar
if i > 1 and current.vowel == "a" and previous.vowel == "ə" and previous.coda == "" then
current.onset = mw.ustring.gsub(current.onset, "^ʒ", "d͡ʒ")
end
-- No palatal gemination ʎʎ -> ll or ʎ, in Balearic and Valencian
if i > 1 and current.onset == "ʎ" and previous.coda == "ʎ" then
local prev_syll = previous.onset .. previous.vowel .. previous.coda
if mw.ustring.find(prev_syll, "[bpw]aʎ$")
or mw.ustring.find(prev_syll, "[mv]eʎ$")
or mw.ustring.find(prev_syll, "tiʎ$")
or mw.ustring.find(prev_syll, "m[oɔ]ʎ$")
or (mw.ustring.find(prev_syll, "uʎ$") and current.vowel == "a")
then
previous.coda = "ɫ"
current.onset = "ɫ"
else
previous.coda = ""
end
end
-- Remove j before palatal obstruents
current.coda = mw.ustring.gsub(current.coda, "j([ʃʒ])", "%1")
current.coda = mw.ustring.gsub(current.coda, "j(t͡ʃ)", "%1")
current.coda = mw.ustring.gsub(current.coda, "j(d͡ʒ)", "%1")
if i > 1
and (mw.ustring.find(current.onset, "^[ʃʒ]")
or mw.ustring.find(current.onset, "^t͡ʃ")
or mw.ustring.find(current.onset, "^d͡ʒ")
)
then
previous.coda = mw.ustring.gsub(previous.coda, "j$", "")
end
-- Final consonant losses
if #syllables == 1 then
current.coda = mw.ustring.gsub(current.coda, "ɾ(s?)$", "%1") -- no loss with hint -rr in monosyllables
current.coda = mw.ustring.gsub(current.coda, "([rɾ])ts$", "%1s")
elseif i == #syllables then
current.coda = mw.ustring.gsub(current.coda, "[rɾ](s?)$", "%1") -- including hint -rr
current.coda = mw.ustring.gsub(current.coda, "([rɾ])ts$", "%1s")
end
end
return syllables
end
-- Altres formes balears formals acceptades
accents["bal2"] = function(syllables)
syllables = mw.clone(syllables)
-- Reduction of unstressed vowels a,e
syllables = reduction_ae(syllables)
for i = 1, #syllables do
local current = syllables[i]
local previous = syllables[i-1]
if current.stressed then
if string.sub(mw.title.getCurrentTitle().text, -4) == 'r-se' and i < #syllables then
-- change stress in infinitive + -se
current.stressed = nil
syllables[#syllables].stressed = true
syllables.stress = #syllables
current.vowel = mw.ustring.gsub(current.vowel, "[aeêë]", "ə")
else
current.vowel = mw.ustring.gsub(current.vowel, "[êëô]", {["ê"] = "ɛ", ["ë"] = "ɛ", ["ô"] = "ɔ"})
end
end
-- Reduction of unstressed -ec (no reduction in Majorcan)
if i == #syllables and i == syllables.stress + 1 and not current.stressed and mw.ustring.find(current.coda, "^k") then
current.vowel = mw.ustring.gsub(current.vowel, "e", "ə")
end
-- Reduction of unstressed o
if not (current.stressed or current.coda == "w") then
current.vowel = mw.ustring.gsub(current.vowel, "o", "u")
end
-- iodització
current.onset = mw.ustring.gsub(current.onset, "L", "j")
current.coda = mw.ustring.gsub(current.coda, "L", "j")
-- nasal assimilation
if previous then previous.coda = nasalAssim(current.onset, previous.coda) end
-- No distintion b/β in v/b area
current.onset = mw.ustring.gsub(current.onset, "β", "b")
-- Gemination bl, gl
if i > 1 and (current.onset == "bɫ" or current.onset == "ɣɫ") and previous.coda == "" then
current.onset = mw.ustring.gsub(current.onset, "ɣ", "ɡ")
previous.coda = mw.ustring.sub(current.onset, 1, 1)
end
-- tl > ll
if i > 1 and current.onset == "ɫ" then
previous.coda = mw.ustring.gsub(previous.coda, "d", "ɫ")
end
-- No palatal gemination ʎʎ -> ll or ʎ, in Balearic and Valencian
if i > 1 and current.onset == "ʎ" and previous.coda == "ʎ" then
local prev_syll = previous.onset .. previous.vowel .. previous.coda
if mw.ustring.find(prev_syll, "[bpw]aʎ$")
or mw.ustring.find(prev_syll, "[mv]eʎ$")
or mw.ustring.find(prev_syll, "tiʎ$")
or mw.ustring.find(prev_syll, "m[oɔ]ʎ$")
or (mw.ustring.find(prev_syll, "uʎ$") and current.vowel == "a")
then
previous.coda = "ɫ"
current.onset = "ɫ"
else
previous.coda = ""
end
end
-- Remove j before palatal obstruents
current.coda = mw.ustring.gsub(current.coda, "j([ʃʒ])", "%1")
current.coda = mw.ustring.gsub(current.coda, "j(t͡ʃ)", "%1")
current.coda = mw.ustring.gsub(current.coda, "j(d͡ʒ)", "%1")
if i > 1
and (mw.ustring.find(current.onset, "^[ʃʒ]")
or mw.ustring.find(current.onset, "^t͡ʃ")
or mw.ustring.find(current.onset, "^d͡ʒ")
)
then
previous.coda = mw.ustring.gsub(previous.coda, "j$", "")
end
-- Allophones of r
current.coda = mw.ustring.gsub(current.coda, "ɾ", "r")
-- Final consonant losses
if i == #syllables then
current.coda = mw.ustring.gsub(current.coda, "r(s?)$", "%1") -- including hint -rr
current.coda = mw.ustring.gsub(current.coda, "([ɫn])t$", "%1")
current.coda = mw.ustring.gsub(current.coda, "rts$", "rs")
end
end
return syllables
end
-- Valencià formal, no betacista
accents["val"] = function(syllables, mid_vowel_hint)
syllables = mw.clone(syllables)
for i = 1, #syllables do
local current = syllables[i]
local previous = syllables[i-1]
if current.stressed then
current.vowel = mw.ustring.gsub(current.vowel, "[êëô]", {["ê"] = "e", ["ë"] = "e", ["ô"] = "o"})
end
current.onset = mw.ustring.gsub(current.onset, "L", "ʎ")
current.coda = mw.ustring.gsub(current.coda, "L", "ʎ")
-- No distintion b/β in v/b area
current.onset = mw.ustring.gsub(current.onset, "β", "b")
-- No gemination bl, gl
if i > 1 and ((current.onset == "bɫ" and previous.coda == "b") or (current.onset == "ɡɫ" and previous.coda == "ɡ")) then
current.onset = mw.ustring.gsub(current.onset, "ɡ", "ɣ")
previous.coda = ""
end
-- tl > ll but atl- > adl-
if i > 1 and current.onset == "ɫ" and not (i == 2 and previous.vowel == "a") then
previous.coda = mw.ustring.gsub(previous.coda, "d", "ɫ")
end
-- Fortition of palatal fricatives
current.onset = mw.ustring.gsub(current.onset, "^ʒ", "d͡ʒ")
current.coda = mw.ustring.gsub(current.coda, "^ʒ", "d͡ʒ")
if i > 1 and previous.vowel == "i" and previous.coda == "" and current.onset == "d͡z" then
current.onset = "z"
elseif (i == 1 and current.onset == "ʃ")
or (i > 1 and current.onset == "ʃ" and previous.coda ~= "" and previous.coda ~= "j" and previous.coda ~= "w")
then
current.onset = "t͡ʃ"
end
-- No palatal gemination ʎʎ -> ll or ʎ, in Balearic and Valencian
if i > 1 and current.onset == "ʎ" and previous.coda == "ʎ" then
local prev_syll = previous.onset .. previous.vowel .. previous.coda
if mw.ustring.find(prev_syll, "[bpw]aʎ$")
or mw.ustring.find(prev_syll, "[mv]eʎ$")
or mw.ustring.find(prev_syll, "tiʎ$")
or mw.ustring.find(prev_syll, "m[oɔ]ʎ$")
or (mw.ustring.find(prev_syll, "uʎ$") and current.vowel == "a")
then
previous.coda = "ɫ"
current.onset = "ɫ"
else
previous.coda = ""
end
end
-- Final consonant losses
if i == #syllables then
current.coda = mw.ustring.gsub(current.coda, "r+", "ɾ") -- hint -rr only for Central
current.coda = mw.ustring.gsub(current.coda, "[nŋ][kɡ](s?)$", "ŋ%1")
current.coda = mw.ustring.gsub(current.coda, "j(t͡ʃ)$", "%1")
end
end
return syllables
end
accents["val2"] = function(syllables)
syllables = mw.clone(syllables)
for i = 1, #syllables do
local current = syllables[i]
local previous = syllables[i-1]
if current.stressed then
current.vowel = mw.ustring.gsub(current.vowel, "[êëô]", {["ê"] = "e", ["ë"] = "e", ["ô"] = "o"})
end
-- Ascending diphthong ui
if current.vowel == "u" and mw.ustring.find(current.coda, "^j")
and i < #syllables and syllables[i+1].onset ~= "ʃ"
then
current.onset = current.onset .. "w"
current.vowel = "i"
current.coda = mw.ustring.gsub(current.coda, "^j", "")
end
-- Reduction of prestress o before i or labial
if i > 1 and current.stressed and not previous.stressed
and (current.vowel == "i" or (mw.ustring.find(current.onset, "^[pbmfv]") and previous.coda == ""))
then
previous.vowel = mw.ustring.gsub(previous.vowel, "o", "u")
end
-- Vowel assimilation of -a
if i > 1 and i == #syllables and current.vowel == "a" and current.coda == ""
and (previous.vowel == "ɛ" or previous.vowel == "ɔ")
then
current.vowel = previous.vowel
end
current.onset = mw.ustring.gsub(current.onset, "L", "ʎ")
current.coda = mw.ustring.gsub(current.coda, "L", "ʎ")
-- Reduction of initial consonants
if i == 1 then
current.onset = mw.ustring.gsub(current.onset, "^[pɡm]n", "n")
current.onset = mw.ustring.gsub(current.onset, "^[pt]([st])", "%1")
end
-- Reduction of groups ads-, obs-, subs- followed by consonant
if current.vowel == "a" and i < #syllables then
current.coda = mw.ustring.gsub(current.coda, "ts", "s")
elseif mw.ustring.find(current.vowel, "[ou]") and i < #syllables then
current.coda = mw.ustring.gsub(current.coda, "ps", "s")
end
-- No gemination bl, gl
if i > 1 and ((current.onset == "bɫ" and previous.coda == "b") or (current.onset == "ɡɫ" and previous.coda == "ɡ")) then
current.onset = mw.ustring.gsub(current.onset, "[bɡ]", {["b"]="β", ["ɡ"]="ɣ"})
previous.coda = ""
end
-- v > b
current.onset = mw.ustring.gsub(current.onset, "v", "b")
if i > 1 and not mw.ustring.find(previous.coda, "[pbtdkɡmɱnɲŋ]$") and (previous.stressed == nil or current.stressed == nil) then
current.onset = mw.ustring.gsub(current.onset, "^b", "β")
elseif i > 1 and mw.ustring.find(current.onset, "^b") then
previous.coda = mw.ustring.gsub(previous.coda, "[ɱn]$", "m")
end
current.coda = mw.ustring.gsub(current.coda, "[ɱn]b", "mb")
-- Fortition of palatal fricatives
current.onset = mw.ustring.gsub(current.onset, "^ʒ", "d͡ʒ")
current.coda = mw.ustring.gsub(current.coda, "^ʒ", "d͡ʒ")
if i > 1 and previous.vowel == "i" and previous.coda == "" and current.onset == "d͡z" then
current.onset = "z"
elseif (i == 1 and current.onset == "ʃ")
or (i > 1 and current.onset == "ʃ" and previous.coda ~= "" and previous.coda ~= "j" and previous.coda ~= "w")
then
current.onset = "t͡ʃ"
end
-- Remove j before palatal obstruents
if i > 1 and mw.ustring.find(current.onset, "^ʃ") then
previous.coda = mw.ustring.gsub(previous.coda, "j$", "")
end
-- No palatal gemination ʎʎ -> ll or ʎ, in Balearic and Valencian
if i > 1 and current.onset == "ʎ" and previous.coda == "ʎ" then
local prev_syll = previous.onset .. previous.vowel .. previous.coda
if mw.ustring.find(prev_syll, "[bpw]aʎ$")
or mw.ustring.find(prev_syll, "[mv]eʎ$")
or mw.ustring.find(prev_syll, "tiʎ$")
or mw.ustring.find(prev_syll, "m[oɔ]ʎ$")
or (mw.ustring.find(prev_syll, "uʎ$") and current.vowel == "a")
then
previous.coda = "ɫ"
current.onset = "ɫ"
else
previous.coda = ""
end
elseif i > 1 and current.onset == "ɫ" then
previous.coda = mw.ustring.gsub(previous.coda, "ɫ", "") -- l·l > l
if not (i == 2 and previous.vowel == "a") then
previous.coda = mw.ustring.gsub(previous.coda, "d", "") -- tl > l but atl- > adl-
end
end
-- Final consonant losses, as in Central and North-western except velars
if i == #syllables then
current.coda = mw.ustring.gsub(current.coda, "mp$", "m")
current.coda = mw.ustring.gsub(current.coda, "([ɫn])t$", "%1")
current.coda = mw.ustring.gsub(current.coda, "r+", "ɾ") -- hint -rr only for Central
current.coda = mw.ustring.gsub(current.coda, "j(t͡ʃ)$", "%1")
end
if i == #syllables then
current.coda = mw.ustring.gsub(current.coda, "ʎs$", "ʎʃ")
end
end
return syllables
end
local function accent_nocc(syl, variant)
local syl1 = mw.clone(syl)
-- Final consonant losses, in Central and North-western
local final = syl1[#syl1].coda
final = mw.ustring.gsub(final, "^ɾ(s?)$", "%1") -- no loss with hint -rr
final = mw.ustring.gsub(final, "mp$", "m") -- -mp/-mb
final = mw.ustring.gsub(final, "([ɫn])t$", "%1") -- -lt/-nt/-ld/-nd
final = mw.ustring.gsub(final, "[nŋ][kɡ](s?)$", "ŋ%1")
final = mw.ustring.gsub(final, "ɾts$", "ɾs")
final = mw.ustring.gsub(final, "j(t͡ʃ)$", "%1")
syl1[#syl1].coda = final
for i = 1, #syl1 do
local current = syl1[i]
local previous = syl1[i-1]
if current.stressed then
current.vowel = mw.ustring.gsub(current.vowel, "[êëô]", {["ê"] = "e", ["ë"] = "e", ["ô"] = "o"})
end
current.onset = mw.ustring.gsub(current.onset, "L", "ʎ")
current.coda = mw.ustring.gsub(current.coda, "L", "ʎ")
-- nasal assimilation
if previous then previous.coda = nasalAssim(current.onset, previous.coda) end
-- No gemination bl, gl
if i > 1 and ((current.onset == "bɫ" and previous.coda == "b") or (current.onset == "ɡɫ" and previous.coda == "ɡ")) then
current.onset = mw.ustring.gsub(current.onset, "[bɡ]", {["b"]="β", ["ɡ"]="ɣ"})
previous.coda = ""
end
-- v > b
if mw.ustring.find(current.onset, "v") then
current.onset = mw.ustring.gsub(current.onset, "v", "b")
if i > 1 and not mw.ustring.find(previous.coda, "[pbtdkɡmɱnɲŋ]$") and (previous.stressed == nil or current.stressed == nil) then
current.onset = mw.ustring.gsub(current.onset, "^b", "β")
elseif i > 1 and mw.ustring.find(current.onset, "^b") then
previous.coda = mw.ustring.gsub(previous.coda, "[ɱn]$", "m")
end
current.coda = mw.ustring.gsub(current.coda, "[ɱn]b", "mb")
end
-- allophones of r
current.coda = mw.ustring.gsub(current.coda, "ɾ", "r")
if (i == 1 and current.onset == "ʃ")
or (i > 1 and current.onset == "ʃ" and previous.coda ~= "" and previous.coda ~= "j" and previous.coda ~= "w")
then
current.onset = "t͡ʃ"
end
-- Fortition of palatal fricatives
if current.onset == "ʒ" and (i == 1 or previous.coda ~= '') then
current.onset = mw.ustring.gsub(current.onset, "ʒ", "d͡ʒ")
end
end
local syl2 = mw.clone(syl1)
for i = 1, #syl1 do
if i > 1 and syl1[i].onset == "ɫ" then
syl2[i-1].coda = mw.ustring.gsub(syl2[i-1].coda, "ɫ", "") -- l·l > l
syl2[i-1].coda = mw.ustring.gsub(syl2[i-1].coda, "d", "ɫ")
syl1[i-1].coda = mw.ustring.gsub(syl1[i-1].coda, "d", "ɫ")
end
end
if variant == "1" then
return syl1
end
return syl2
end
accents["noc"] = function(syllabes)
return accent_nocc(syllabes, "1")
end
accents["noc2"] = function(syllabes)
return accent_nocc(syllabes, "2")
end
local accent_order = {}
for accent, _ in pairs(accents) do
table.insert(accent_order, accent)
end
table.sort(accent_order)
local function join_syllables(syllables)
syllables = mw.clone(syllables)
for i, syll in ipairs(syllables) do
syll.vowel = mw.ustring.gsub(syll.vowel, "[āēō]", {["ā"] = "a", ["ē"] = "e", ["ō"] = "o"})
syll = syll.onset .. syll.vowel .. syll.coda
if i == syllables.stress then -- primary stress
syll = "ˈ" .. syll
elseif syllables[i].stressed then -- secondary stress
syll = "ˌ" .. syll
end
syllables[i] = syll
end
return "/" .. mw.ustring.gsub(table.concat(syllables, "."), "%.([ˈˌ.])", "%1") .. "/"
end
-- Main entry point
local function show(word)
word = mw.ustring.lower(mw.text.trim(word))
local mid_vowel_hint = nil
if word == "é" or word == "è" or word == "ê" or word == "ë" or word == "ó" or word == "ò" or word == "ô" then
mid_vowel_hint = word
word = mw.ustring.lower(mw.title.getCurrentTitle().text)
end
word = word_fixes(word)
local syllables = split_syllables(word)
if mid_vowel_hint == nil then
if mw.ustring.find(syllables[syllables.stress].vowel, "[éêëòóô]") then
mid_vowel_hint = mw.ustring.match(syllables[syllables.stress].vowel, "[éêëòóô]")
elseif mw.ustring.find(syllables[syllables.stress].vowel, "[eè]") then
mid_vowel_hint = mid_vowel_e(syllables)
elseif syllables[syllables.stress].vowel == "o" then
mid_vowel_hint = mid_vowel_o(syllables)
end
if mw.ustring.find(syllables[syllables.stress].vowel, "[eo]") and mid_vowel_hint == nil then
return ''
end
end
syllables = to_IPA(syllables, mid_vowel_hint)
local ret = {}
for _, accent in ipairs(accent_order) do
local syllables_accented = accents[accent](syllables)
ret[accent] = join_syllables(syllables_accented)
end
-- simplificació de variants idèntiques o amb al·lòfons
if ret.val == mw.ustring.gsub(ret.val2, "β", "b") then
ret.val = ret.val2
ret.val2 = nil
end
if ret.noc == ret.noc2 then
ret.noc2 = nil
end
if ret.val2 == nil and ret.noc2 == nil and mw.ustring.gsub(ret.val, "ɾ", "r") == mw.ustring.gsub(ret.noc, "ɾ", "r") then
ret.occ = ret.val
ret.val = nil
ret.noc = nil
elseif ret.noc == ret.val and ret.noc2 == ret.val2 then
ret.occ = ret.val
ret.occ2 = ret.val2
ret.noc = nil
ret.noc2 = nil
ret.val = nil
ret.val2 = nil
end
if ret.cen == ret.cen2 then
ret.cen2 = nil
end
if mw.ustring.gsub(ret.bal, "[cɟʝɾ]", {["c"]="k", ["ɟ"]="ɡ", ["ʝ"]="ɣ", ["ɾ"]="r"}) == mw.ustring.gsub(ret.bal2, "ɾ", "r") then
ret.bal = ret.bal2
ret.bal2 = nil
end
if ret.bal2 == nil and ret.cen2 == nil and mw.ustring.gsub(ret.bal, "ɾ", "r") == mw.ustring.gsub(ret.cen, "[βɾ]", {["β"] = "b", ["ɾ"] = "r"}) then
ret.ori = ret.cen
ret.cen = nil
ret.bal = nil
elseif ret.bal2 == nil and ret.cen2 == nil and mw.ustring.gsub(ret.bal, "[βðɣɾ]", {["β"] = "b", ["ð"] = "d", ["ɣ"] = "ɡ", ["ɾ"] = "r"}) == mw.ustring.gsub(ret.cen, "ɾ", "r") then
ret.ori = ret.cen
ret.cen = nil
ret.bal = nil
end
if ret.ori ~= nil and ret.occ ~= nil
and mw.ustring.gsub(ret.ori, "[βɾ]", {["β"] = "b", ["ɾ"] = "r"}) == mw.ustring.gsub(ret.occ, "[βɾ]", {["β"] = "b", ["ɾ"] = "r"})
then
ret.gen = ret.ori
ret.ori = nil
ret.occ = nil
end
return ret
end
-- on debug console use: =p.debug("your_word", "your_hint")
local function _debug(word, mid_vowel_hint)
word = word_fixes(mw.ustring.lower(word))
local syllables = split_syllables(word)
if mid_vowel_hint == nil then
if mw.ustring.find(syllables[syllables.stress].vowel, "[éêëòóô]") then
mid_vowel_hint = mw.ustring.match(syllables[syllables.stress].vowel, "[éêëòóô]")
elseif mw.ustring.find(syllables[syllables.stress].vowel, "[eè]") then
mid_vowel_hint = mid_vowel_e(syllables)
elseif syllables[syllables.stress].vowel == "o" then
mid_vowel_hint = mid_vowel_o(syllables)
end
if mw.ustring.find(syllables[syllables.stress].vowel, "[eo]") and mid_vowel_hint == nil then
return 'Vocal tònica ambigua'
end
end
syllables = to_IPA(syllables, mid_vowel_hint)
local ret = {}
for _, accent in ipairs(accent_order) do
local syllables_accented = accents[accent](syllables)
ret[accent] = join_syllables(syllables_accented)
end
local output = ''
for k, v in pairs(ret) do
output = output .. k .. ": " .. v .. "\n"
end
return output
end
-- Return exported functions
return {
show = show,
debug = _debug
}