Salta al contegnùo

Modulo:vec-pron/AFI

Da Wikisionario

La documentazione per questo modulo può essere creata in Modulo:vec-pron/AFI/man

--import ca.wiki module:ca-pron/AFI, and costumiz. for vec--
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",
	"h",
	"i",
	"j",
	"k", "kl", "kr",
	"l", "ll",
	"m",
	"n", "gn", "nj",
	"p", "pl",
	"qu", "cu",
	"r",
	"s", "ss",
	"t", "tz", "tr",
	"u",
	"v",
	"w",
	"x",
	"z",
})

local function fix_prefixes(word)
	-- Coresion ortogràfeghe par prefisi no insomejai
	local prefix = {
		"a[eè]ro", "ànte", "alt[ìi]", "[aà]nti", "[aà]rci", "[aà]uto", -- a- el ze anbìguo cofà prefix
		"bi", "b[iì]li", "bio",
		"c[oò]ntra", -- anbìguo co-
		"[eé]ntre", "ecui", "estereo", -- anbìgui e-(raiza)
		"f[oó]to",
		"[oòóaà]stro", "gr[eé]co","[eèé]lt[ìi]",
		"[iì]nfra", "[iì]ntra",
		"m[aà]cro", "m[iì]cro", "mono", "morfo", "m[uù]lti",
		"n[eé]o",
		"octo", "orto",
		"penta", "p[oòôuù][lł]i", "p[uùoòó][lł][ií]tego", "pr[oò]to", "ps[eè]udo", "psico", -- anbìgui pre-(s), pro-
		"cu[aà]zi",
		"r[aà]dio", -- anbìgui re-
		"s[eè]mi", "s[oó]ra",
		"termo", "tetra", "tri", -- anbìgui tele-(r)
		"[uù]ltra", "[uu]n[iì]",
		"v[iì]ce"
	}
	local prefix_r = {"[eèé]xtra", "pr[eé]"}
	local prefix_s = {"antropo", "sentro", "deca", "d[iì]no", "eco", "[eèé]xtra",
		"hetero", "p[aà]ra", "post", "pré", "s[oò]ta", "tełe", "tele"}
	local prefix_i = {"pr[eé]", "pr[iì]mo", "pro", "tele", "tełe"}
	local no_prefix = {"autoic", "autori", "biret", "biri", "biza", "bizeło", "bizon", "biur", "contrari", "contrau",
		"diari", "ecuize", "eterozi",  "eteroze", "monoi", "paraza", "parasit[ao]", "preiso", "psicozi", "psicoze", "sorera", "soreri"}
	
	-- Falsi prefisi
	for _, pr in ipairs(no_prefix) do
		if mw.ustring.find(word, "^" .. pr) then
			return word
		end
	end
	
	-- Dòpie s in prefix + s + vocal
	for _, pr in ipairs(prefix_s) do
		word = mw.ustring.gsub(word, "^(" .. pr .. ")s([aàeèéioòóu])", "%1ss%2")
	end
	
	-- Jato in prefix + i
	for _, pr in ipairs(prefix_i) do
		word = mw.ustring.gsub(word, "^(" .. pr .. ")i(.)", "%1ï%2")
	end
	
	-- Anbedò prefix + r/s or i/u
	for _, pr in ipairs(prefix) do
		word = mw.ustring.gsub(word, "^(" .. pr .. ")([rs])([aàeèéioòóu])", "%1%2%2%3")
		word = mw.ustring.gsub(word, "^(" .. pr .. ")i(.)", "%1ï%2")
		word = mw.ustring.gsub(word, "^(" .. pr .. ")u(.)", "%1ü%2")
	end
	
	-- S sonòre inte el prefiso -trans-
	word = mw.ustring.gsub(word, "tr([aà])ns([aàeèéioòóubdghlmv])", "tr%1ns%2")

	-- in + ex > ineks/inegz
	word = mw.ustring.gsub(word, "^inex", "inhex")
	
	return word
end

local function fix_y(word)
	-- y > vowel i else consonant /j/, except ny
	
	word = mw.ustring.gsub(word, "nj", "ñ")
	
	word = mw.ustring.gsub(word, "j([^aeiouàèéêíòóôúïü])", "i%1") -- vowel if not next to another vowel
	word = mw.ustring.gsub(word, "([^aeiouàèéêíòóôúïü·%-%.])j", "%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 = 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 == "u" or (first_vowel == "u" and vowels ~= "u"))) or
				((onset == "" or onset == "aeou") 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, "^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 == "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 "ó"
	end
	
	return nil
end

local IPA_vowels = {
	["a"] = "a", ["à"] = "a",
	["e"] = "e", ["è"] = "ɛ", ["é"] = "e",
	["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, "ss", "s")
	cons = mw.ustring.gsub(cons, "s", "s")
	cons = mw.ustring.gsub(cons, "zz", "s")
	cons = mw.ustring.gsub(cons, "ł", "l")
	cons = mw.ustring.gsub(cons, "ƚ", "l")
	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, "[aeiou]ł[aeiou]", "%1e%2")
	cons = mw.ustring.gsub(cons, "[aeiou]l[aeiou]", "%1e%2")
	cons = mw.ustring.gsub(cons, "[dt]z", "ʤ")
	
	cons = mw.ustring.gsub(cons, "ç", "s")
	cons = mw.ustring.gsub(cons, "[cq]", "k")
	cons = mw.ustring.gsub(cons, "l", "l")
	cons = mw.ustring.gsub(cons, "g", "ɡ")
	cons = mw.ustring.gsub(cons, "gn", "ɲ")
	cons = mw.ustring.gsub(cons, "ni[aeiouàèéìòóù]", "ɲ%1")
	cons = mw.ustring.gsub(cons, "j", "j")
	cons = mw.ustring.gsub(cons, "x", "x")
	
	cons = mw.ustring.gsub(cons, "[i]", "j")  -- must be after j > z 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({""})
	local voiceless = list_true({""})
	local devoicing = {[""]=""}
	local voicing = {[""]=""}
	
	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, "n[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, "^LL") then
				previous.coda = mw.ustring.gsub(previous.coda, "t$", "LL")
			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, "^[zLLʃɲ]")
			or mw.ustring.find(current.onset, "^t͡ʃ")
			or mw.ustring.find(current.onset, "^d͡z")
			then
				previous.coda = mw.ustring.gsub(previous.coda, "[ŀn]$", {["ŀ"] = "LL", ["n"] = "ɲ"})
			end
			
			-- ɡz > d͡z
			if previous.coda == "z" and current.onset == "z" then
				previous.coda = ""
				current.onset = "z"
			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([ʃz])", "ɲ%1")
		current.coda = mw.ustring.gsub(current.coda, "n(t͡ʃ)", "ɲ%1")
		current.coda = mw.ustring.gsub(current.coda, "n(d͡z)", "ɲ%1")
		
		current.coda = mw.ustring.gsub(current.coda, "ŀ([ʃz])", "LL%1")
		current.coda = mw.ustring.gsub(current.coda, "ŀ(t͡ʃ)", "LL%1")
		current.coda = mw.ustring.gsub(current.coda, "ŀ(d͡z)", "LL%1")
		
		--current.coda = mw.ustring.gsub(current.coda, "ɲs", "ɲʃ")
		
		-- 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, "[ŀLL]") and current.onset == "d")
		and (previous.stressed == nil or current.stressed == nil)
		then
			current.onset = mw.ustring.gsub(current.onset, "[bdɡ]", {["b"] = "b", ["d"] = "d", ["ɡ"] = "g"})
		end
	
	end
	
	-- Final devoicing
	local final = syllables[#syllables].coda
	
	final = mw.ustring.gsub(final, "d͡z", "t͡ʃ")
	final = mw.ustring.gsub(final, "d͡z", "t͡s")
	final = mw.ustring.gsub(final, "b", "p")
	final = mw.ustring.gsub(final, "n", "ŋ.")
	final = mw.ustring.gsub(final, "ɡ", "k")
	final = mw.ustring.gsub(final, "z", "ʃ")
	final = mw.ustring.gsub(final, "v", "f")
	final = mw.ustring.gsub(final, "z", "z")
	
	-- 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)
	-- Stressed vowel is ambiguous
	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("Pronunsa \"" .. syllables[syllables.stress].vowel .. "\" ambigua.[[Categoria:Parole vènete sensa transcrision fonètega]]")
		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 = "s"
		end
		
		if mw.ustring.find(syll.vowel, "^[eèéêëií]$") then
			syll.onset = mw.ustring.gsub(syll.onset, "tg$", "d͡z")
			syll.onset = mw.ustring.gsub(syll.onset, "[cg]$", {["c"] = "s", ["g"] = "z"})
			syll.onset = mw.ustring.gsub(syll.onset, "[qg]u$", {["qu"] = "k", ["gu"] = "ɡ"})
		end
		
		syll.coda = mw.ustring.gsub(syll.coda, "ig(s?)$", "id͡z%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 talian, need to do it at this point
			reduction = false
		end
		
		if reduction then
			current.vowel = mw.ustring.gsub(current.vowel, "[ae]", "a")
		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")
	end
	return coda
end

local accents = {}

-- Central
local function accent_sentral(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", "o")
		end
		
		-- nasal assimilations
		if previous then previous.coda = nasalAssim(current.onset, previous.coda) end
		
		-- v > b
		if mw.ustring.find(current.onset, "b") then
			current.onset = mw.ustring.gsub(current.onset, "b", "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", "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, "[aɛeiɔou]$") then
			current.onset = mw.ustring.gsub(current.onset, "^[aɛeiðɔouð]", {["b"] = "b", ["ð"] = "d", ["g"] = "ɡ"})
		end
		
		-- Poststressed gemination bl, gl
		if i > 1 and (current.onset == "bŀ" or current.onset == "gŀ") and previous.coda == "" and previous.stressed then
			current.onset = mw.ustring.gsub(current.onset, "[bg]", {["b"] = "b", ["g"] = "ɡ"})
			previous.coda = mw.ustring.sub(current.onset, 1, 1)
		end
		
		-- Velarization -gn-, -cn-
		if i > 1 and current.onset == "n" then
			previous.coda = mw.ustring.gsub(previous.coda, "ɡ", "ŋ")
		end
		
		-- Remove j before palatal obstruents
		current.coda = mw.ustring.gsub(current.coda, "j([ʃz])", "%1")
		current.coda = mw.ustring.gsub(current.coda, "j(t͡ʃ)", "%1")
		current.coda = mw.ustring.gsub(current.coda, "j(d͡z)", "%1")
		
		if i > 1
		and (mw.ustring.find(current.onset, "^[ʃz]")
			or mw.ustring.find(current.onset, "^t͡ʃ")
			or mw.ustring.find(current.onset, "^d͡z")
		)
		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["sen"] = function(syllabes)
	return accent_sentral(syllabes, "1")
end
accents["sen2"] = function(syllabes)
	return accent_sentral(syllabes, "2")
end

-- talear dominant, en general mallorquí
accents["tal"] = 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 ZONTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
		if i > 1 and current.stressed and mw.ustring.find(current.vowel, "[io]") and not previous.stressed then
			previous.vowel = mw.ustring.gsub(previous.vowel, "o", "o")
		end
		
		-- nasal assimilation
		if previous then previous.coda = nasalAssim(current.onset, previous.coda) end
		
		-- No distintion θ in θ area
		current.onset = mw.ustring.gsub(current.onset, "θ", "s")
		
		-- Gemination bl, gl
		if i > 1 and (current.onset == "bŀ" or current.onset == "gŀ") and previous.coda == "" then
			current.onset = mw.ustring.gsub(current.onset, "g", "ɡ")
			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ąɛiouɔ]") then
			current.onset = mw.ustring.gsub(current.onset, "^[sd]$", {["s"] = "ts", ["d"] = "ð"})
		end
		
		-- Fortition of palatal fricative in -ejar
		if i > 1 and current.vowel == "a" and previous.vowel == "a" and previous.coda == "" then
			current.onset = mw.ustring.gsub(current.onset, "^z", "d͡z")
		end
		
		-- No palatal gemination LLLL -> ll or LL, in talearic and Valencian
		if i > 1 and current.onset == "LL" and previous.coda == "LL" then
			local prev_syll = previous.onset .. previous.vowel .. previous.coda
			if mw.ustring.find(prev_syll, "[bpw]aLL$")
				or mw.ustring.find(prev_syll, "[mv]eLL$")
				or mw.ustring.find(prev_syll, "tiLL$")
				or mw.ustring.find(prev_syll, "m[oɔ]LL$")
				or (mw.ustring.find(prev_syll, "uLL$") 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([ʃz])", "%1")
		current.coda = mw.ustring.gsub(current.coda, "j(t͡ʃ)", "%1")
		current.coda = mw.ustring.gsub(current.coda, "j(d͡z)", "%1")
		
		if i > 1
		and (mw.ustring.find(current.onset, "^[ʃz]")
			or mw.ustring.find(current.onset, "^t͡ʃ")
			or mw.ustring.find(current.onset, "^d͡z")
		)
		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 talears formals acceptades
accents["tal2"] = 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êë]", "a")
			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, "^r") then
			current.vowel = mw.ustring.gsub(current.vowel, "e", "a")
		end
		
		-- Reduction of unstressed o
		if not (current.stressed or current.coda == "w") then
			current.vowel = mw.ustring.gsub(current.vowel, "o", "o")
		end
		
		-- nasal assimilation
		if previous then previous.coda = nasalAssim(current.onset, previous.coda) end
		
		-- No distintionv
		current.onset = mw.ustring.gsub(current.onset, "v", "v")
		
		-- Gemination bl, gl
		if i > 1 and (current.onset == "bŀ" or current.onset == "gŀ") and previous.coda == "" then
			current.onset = mw.ustring.gsub(current.onset, "g", "ɡ")
			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 LLLL -> ll or LL, in talearic and Valencian
		if i > 1 and current.onset == "LL" and previous.coda == "LL" then
			local prev_syll = previous.onset .. previous.vowel .. previous.coda
			if mw.ustring.find(prev_syll, "[bpw]aLL$")
				or mw.ustring.find(prev_syll, "[mv]eLL$")
				or mw.ustring.find(prev_syll, "tiLL$")
				or mw.ustring.find(prev_syll, "m[oɔ]LL$")
				or (mw.ustring.find(prev_syll, "uLL$") 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([ʃz])", "%1")
		current.coda = mw.ustring.gsub(current.coda, "j(t͡ʃ)", "%1")
		current.coda = mw.ustring.gsub(current.coda, "j(d͡z)", "%1")
		
		if i > 1
		and (mw.ustring.find(current.onset, "^[ʃz]")
			or mw.ustring.find(current.onset, "^t͡ʃ")
			or mw.ustring.find(current.onset, "^d͡z")
		)
		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, "ɽ(s?)$", "%1") -- including hint -rr
			current.coda = mw.ustring.gsub(current.coda, "([ŀn])t$", "%1")
			current.coda = mw.ustring.gsub(current.coda, "ɽts$", "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
		
		-- No distintion b/b in v/b area
		current.onset = mw.ustring.gsub(current.onset, "v", "v")
		
		-- 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, "ɡ", "g")
			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, "^z", "d͡z")
		current.coda = mw.ustring.gsub(current.coda, "^z", "d͡z")
		
		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 LLLL -> ll or LL, in talearic and Valencian
		if i > 1 and current.onset == "LL" and previous.coda == "LL" then
			local prev_syll = previous.onset .. previous.vowel .. previous.coda
			if mw.ustring.find(prev_syll, "[bpw]aLL$")
			or mw.ustring.find(prev_syll, "[mv]eLL$")
			or mw.ustring.find(prev_syll, "tiLL$")
			or mw.ustring.find(prev_syll, "m[oɔ]LL$")
			or (mw.ustring.find(prev_syll, "uLL$") 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", "o")
		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
		
		-- 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"]="b", ["ɡ"]="g"})
			previous.coda = ""
		end
		
		-- v > b
		current.onset = mw.ustring.gsub(current.onset, "b", "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", "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, "^z", "d͡z")
		current.coda = mw.ustring.gsub(current.coda, "^z", "d͡z")

		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 LLLL -> ll or LL, in talearic and Valencian
		if i > 1 and current.onset == "LL" and previous.coda == "LL" then
			local prev_syll = previous.onset .. previous.vowel .. previous.coda
			if mw.ustring.find(prev_syll, "[bpw]aLL$")
			or mw.ustring.find(prev_syll, "[mv]eLL$")
			or mw.ustring.find(prev_syll, "tiLL$")
			or mw.ustring.find(prev_syll, "m[oɔ]LL$")
			or (mw.ustring.find(prev_syll, "uLL$") 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, "LLs$", "LLʃ")
		end
	end
	
	return syllables
end

local function accent_nosi(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
		
		-- 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"]="b", ["ɡ"]="g"})
			previous.coda = ""
		end
		
		-- v > b
		if mw.ustring.find(current.onset, "b") then
			current.onset = mw.ustring.gsub(current.onset, "b", "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", "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")
		
		-- Velarization -gn-, -cn-
		if i > 1 and current.onset == "n" then
			previous.coda = mw.ustring.gsub(previous.coda, "ɡ", "ŋ")
		end
		
		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 == "z" and (i == 1 or previous.coda ~= '') then
			current.onset = mw.ustring.gsub(current.onset, "z", "d͡z")
		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_nosi(syllabes, "1")
end
accents["noc2"] = function(syllabes)
	return accent_nosi(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 = 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, "v", "v") 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.osi = ret.val
		ret.val = nil
		ret.noc = nil
	elseif ret.noc == ret.val and ret.noc2 == ret.val2 then
		ret.osi = ret.val
		ret.osi2 = ret.val2
		ret.noc = nil
		ret.noc2 = nil
		ret.val = nil
		ret.val2 = nil
	end
	
	if ret.sen == ret.sen2 then
		ret.sen2 = nil
	end
	if mw.ustring.gsub(ret.tal, "[tsðaɛeiɔou]", {["ts"]="s", ["ð"]="d", ["ɽ"]="r"}) == mw.ustring.gsub(ret.tal2, "ɽ", "r") then
		ret.tal = ret.tal2
		ret.tal2 = nil
	end
	if ret.tal2 == nil and ret.sen2 == nil and mw.ustring.gsub(ret.tal, "ɽ", "r") == mw.ustring.gsub(ret.sen, "[bɽ]", {["b"] = "b", ["ɽ"] = "r"}) then
		ret.ori = ret.sen
		ret.sen = nil
		ret.tal = nil
	elseif ret.tal2 == nil and ret.sen2 == nil and mw.ustring.gsub(ret.tal, "[bðgɽ]", {["b"] = "b", ["ð"] = "d", ["g"] = "ɡ", ["ɽ"] = "r"}) == mw.ustring.gsub(ret.sen, "ɽ", "r") then
		ret.ori = ret.sen
		ret.sen = nil
		ret.tal = nil
	end
	
	if ret.ori ~= nil and ret.osi ~= nil
	and mw.ustring.gsub(ret.ori, "[bɽ]", {["b"] = "b", ["ɽ"] = "r"}) == mw.ustring.gsub(ret.osi, "[bɽ]", {["b"] = "b", ["ɽ"] = "r"})
	then
		ret.gen = ret.ori
		ret.ori = nil
		ret.osi = 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
	}
Traesto fora da Wikipèdia - L'ençiclopedia łìbara e cołaboradiva in łéngua Vèneta "https://vec.wiktionary.org/w/index.php?title=Modulo:vec-pron/AFI&oldid=36305"