Cebuano pronunciation module, used by {{ceb-IPA}}
, see its documentation.
-- Based on ] by Benwing2.
-- Adaptation by TagaSanPedroAko based on ].
local export = {}
local pron_utilities_module = "Module:pron utilities"
local lang = require("Module:languages").getByCode("ceb")
local u = require("Module:string/char")
local rfind = mw.ustring.find
local rsubn = mw.ustring.gsub
local rsplit = mw.text.split
local ulower = mw.ustring.lower
local AC = u(0x0301) -- acute = ́
local GR = u(0x0300) -- grave = ̀
local CFLEX = u(0x0302) -- circumflex = ̂
local TILDE = u(0x0303) -- tilde = ̃
local DIA = u(0x0308) -- diaeresis = ̈
local MACRON = u(0x0304) -- macron
local vowel = "aeiou" -- vowel
local V = ""
local accent = AC .. GR .. CFLEX .. MACRON
local accent_c = ""
local stress_c = ""
local ipa_stress = "ˈˌ"
local ipa_stress_c = ""
local separator = accent .. ipa_stress .. "# ."
local separator_c = ""
local C = "" -- consonant
local unstressed_words = require("Module:table").listToSet({
"ang", "sa", "og", "si", "ni", "kang", -- case markers. "Nang" here is for written "ng", but can also work with nang as in the contraction na'ng and the conjunction "nang"
"ko", "mo", "ka", --single-syllable personal pronouns
"nga",-- linker, also temporal particle
"gyud", "jud", "pa", -- particles
"di7", -- negation words
"kon", -- subordinating conjunctions
"ug", "o", -- coordinating conjunctions
"hay", -- interjections
"de", "del", -- in some Spanish-derived terms and names
"-an", "-han", "-hon", "i-", "-i", "in-", "-in-", "mag-", "mang-", "mo-", "-on", "pag-", "pang-" -- monosyllabic affixes
})
-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
local retval = rsubn(term, foo, bar)
return retval
end
-- version of rsubn() that returns a 2nd argument boolean indicating whether
-- a substitution was made.
local function rsubb(term, foo, bar)
local retval, nsubs = rsubn(term, foo, bar)
return retval, nsubs > 0
end
-- apply rsub() repeatedly until no change
local function rsub_repeatedly(term, foo, bar)
while true do
local new_term = rsub(term, foo, bar)
if new_term == term then
return term
end
term = new_term
end
end
-- ĵ and ɟ are used internally to represent and
--
function export.IPA(text)
local debug = {}
text = ulower(text)
-- decompose everything but ñ and ü
text = mw.ustring.toNFD(text)
text = rsub(text, "." .. "", {
= "ñ",
= "ü",
})
-- convert commas and en/en dashes to IPA foot boundaries
text = rsub(text, "%s*%s*", " | ")
-- question mark or exclamation point in the middle of a sentence -> IPA foot boundary
text = rsub(text, "()%s*%s*()", "%1 | %2")
-- canonicalize multiple spaces and remove leading and trailing spaces
local function canon_spaces(text)
text = rsub(text, "%s+", " ")
text = rsub(text, "^ ", "")
text = rsub(text, " $", "")
return text
end
text = canon_spaces(text)
-- Make prefixes unstressed unless they have an explicit stress marker; also make certain
-- monosyllabic words (e.g. ], ], ], ], etc.) without stress marks be
-- unstressed.
local words = rsplit(text, " ")
for i, word in ipairs(words) do
if rfind(word, "%-$") and not rfind(word, accent_c) or unstressed_words then
-- add macron to the last vowel not the first one
-- adding the macron after the 'u'
words = rsub(word, "^(.*" .. V .. ")", "%1" .. MACRON)
end
end
text = table.concat(words, " ")
-- Convert hyphens to spaces
text = rsub(text, "%-", " ")
-- canonicalize multiple spaces again, which may have been introduced by hyphens
text = canon_spaces(text)
-- now eliminate punctuation
text = rsub(text, "", "")
-- put # at word beginning and end and double ## at text/foot boundary beginning/end
text = rsub(text, " | ", "# | #")
text = "##" .. rsub(text, " ", "# #") .. "##"
table.insert(debug, text)
-- Add glottal stop for words starting with vowel
text = rsub(text, "()()", "%1ʔ%2")
-- handle certain combinations; ch ng and sh handling needs to go first
text = rsub(text, "(?)ch", "ts")
text = rsub(text, "(?)g̃", "ŋ") -- Spanish spelling support
text = rsub(text, "ng", "ŋ")
text = rsub(text, "sh", "sɟ")
--x
text = rsub(text, "()x(" .. V .. ")", "%1s%2")
text = rsub(text, "x", "ks")
--ll
text = rsub(text, "ll(?)(".. V.. ")", "ly%2")
--c, gü/gu+e or i, q
text = rsub(text, "c()", "s%1")
text = rsub(text, "(" .. V .. ")gü()", "%1ɡw%2")
text = rsub(text, "gü()", "ɡuw%1")
text = rsub(text, "gui()", "ɡy%1")
text = rsub(text, "gu()", "ɡ%1")
text = rsub(text, "qu()", "k%1")
text = rsub(text, "ü", "u")
table.insert(debug, text)
--alphabet-to-phoneme
text = rsub(text, "",
--="ɡ": U+0067 LATIN SMALL LETTER G → U+0261 LATIN SMALL LETTER SCRIPT G
{ = "k", = "p", = "ɡ", = "ĵ", = "ɲ", = "k", = "ɾ", = "b", = "s", = "ʔ"})
-- trill in rr
text = rsub(text, "ɾɾ", "r")
table.insert(debug, text)
text = rsub_repeatedly(text, "()()(?)()(" .. accent_c .. "?)","%1%2%3.w%4%5")
text = rsub_repeatedly(text, "(" .. V .. ")()(?)()(" .. accent_c .. "?)","%1.w%3%4")
text = rsub(text, "()()()(" .. accent_c .. "?)","%1%2.y%3%4")
text = rsub(text, "()()(" .. accent_c .. "?)","y%2%3")
text = rsub(text, "a(*)o()","a%1w%2")
--determining whether "y" is a consonant or a vowel
text = rsub(text, "y(" .. V .. ")", "ɟ%1") -- not the real sound
text = rsub(text,"y(*)()","i%1%2")
text = rsub(text, "w(" .. V .. ")","w%1")
text = rsub(text,"w(?)()","u%1%2")
table.insert(debug, text)
--vowels with grave/circumflex to vowel+glottal stop
text = rsub(text, CFLEX, AC .. GR)
text = rsub(text, "(" .. V .. ")(?)" .. GR .. "()", "%1%2ʔ%3")
text = rsub(text, "(" .. V .. ")(?)" .. GR, "%1%2")
-- Add glottal stop for words starting with vowel
text = rsub(text, "()(" .. V .. ")", "%1ʔ%2")
text = rsub(text, "◌", "")
text = rsub_repeatedly(text, "(" .. V .. accent_c .. "*)(" .. C .. V .. ")", "%1.%2")
text = rsub_repeatedly(text, "(" .. V .. accent_c .. "*" .. C .. ")(" .. C .. V .. ")", "%1.%2")
text = rsub_repeatedly(text, "(" .. V .. accent_c .. "*" .. C .. "+)(" .. C .. C .. V .. ")", "%1.%2")
text = rsub_repeatedly(text, "(" .. C .. ")%.s(" .. C .. ")", "%1s.%2")
-- Any aeo, or stressed iu, should be syllabically divided from a following aeo or stressed iu.
text = rsub_repeatedly(text, "(" .. accent_c .. "*)()", "%1.%2")
text = rsub_repeatedly(text, "(" .. accent_c .. "*)(" .. V .. AC .. ")", "%1.%2")
text = rsub(text, "(" .. AC .. ")()", "%1.%2")
text = rsub_repeatedly(text, "(" .. AC .. ")(" .. V .. AC .. ")", "%1.%2")
text = rsub_repeatedly(text, "i(" .. accent_c .. "*)i", "i%1.i")
text = rsub_repeatedly(text, "u(" .. accent_c .. "*)u", "u%1.u")
table.insert(debug, text)
local accent_to_stress_mark = { = "ˈ", = "" }
local function accent_word(word, syllables)
-- Now stress the word. If any accent exists in the word (including macron indicating an unaccented word),
-- put the stress mark(s) at the beginning of the indicated syllable(s). Otherwise, apply the default
-- stress rule.
if rfind(word, accent_c) then
for i = 1, #syllables do
syllables = rsub(syllables, "^(.*)(" .. accent_c .. ")(.*)$",
function(pre, accent, post)
return accent_to_stress_mark .. pre .. post
end
)
end
else
-- Default stress rule. Words without vowels (e.g. IPA foot boundaries) don't get stress.
if #syllables > 1 and rfind(word, "#") or #syllables == 1 and rfind(word, V) then
syllables = "ˈ" .. syllables
elseif #syllables >= 2 then
syllables = "ˈ" .. syllables
end
end
end
local words = rsplit(text, " ")
for j, word in ipairs(words) do
-- accentuation
local syllables = rsplit(word, "%.")
accent_word(word, syllables)
-- Reconstruct the word.
words = table.concat(syllables, ".")
end
text = table.concat(words, " ")
-- suppress syllable mark before IPA stress indicator
text = rsub(text, "%.(" .. ipa_stress_c .. ")", "%1")
--make all primary stresses but the last one be secondary
text = rsub_repeatedly(text, "ˈ(.+)ˈ", "ˌ%1ˈ")
table.insert(debug,text)
--correct final glottal stop placement
text = rsub(text,"()ʔ(*)()(" .. V .. ")","%1%2%3%4ʔ")
table.insert(debug,text)
--add temporary macron for /a/, /i/ and /u/ in stressed syllables so they don't get replaced by unstressed form
text = rsub(text,"()(*)(?)(?)()(?)(?)","%1%2%3%4ā%6%7")
text = rsub(text,"()(*)(?)(?)()(?)(?)","%1%2%3%4ē%6%7")
text = rsub(text,"()(*)(?)(?)()(?)(?)","%1%2%3%4ī%6%7")
text = rsub(text,"()(*)(?)(?)()(?)(?)","%1%2%3%4ō%6%7")
text = rsub(text,"()(*)(?)(?)()(?)(?)","%1%2%3%4ū%6%7")
table.insert(debug, text)
--Corrections for diphthongs
text = rsub(text,"()i","%1j") --ay
text = rsub(text,"()u","%1w") --aw
table.insert(debug, text)
--remove "ɟ" and "w" inserted on vowel pair starting with "i" and "u"
text = rsub(text,"()(?)ɟ()","%1%2%3")
text = rsub(text,"()(?)w()","%1%2%3")
table.insert(debug, text)
local ceb_IPA_table = {
= text,
= text
}
for key, value in pairs(ceb_IPA_table) do
text = ceb_IPA_table
--phonetic transcription
if key == "phonetic" then
table.insert(debug, text)
--Turn phonemic diphthongs to phonetic diphthongs
text = rsub(text, "()j", "%1ɪ̯")
text = rsub(text, "()w", "%1ʊ̯")
table.insert(debug, text)
--change a, e, i, o, u to unstressed equivalents (certain forms to restore)
text = rsub(text,"a","ɐ")
text = rsub(text,"e","e")
text = rsub(text,"i","ɪ")
text = rsub(text,"o","o")
text = rsub(text,"u","ʊ")
table.insert(debug,text)
--Combine consonants (except H) followed by I/U and certain stressed vowels
text = rsub(text,"()(?)ɪ()ɟ?()","%3%1%2ɟ%4")
text = rsub(text,"()(?)ʊ()w?()","%3%1%2w%4")
table.insert(debug, text)
text = rsub(text, "()(*)", "m%2")
text = rsub(text,"n()k","ŋ%1k") -- /n/ before /k/ (some proper nouns)
text = rsub(text,"n()ɡ","ŋ%1ɡ") -- /n/ before /ɡ/ (some proper nouns and loanwords)
-- text = rsub(text,"n()h","ŋ%1h") -- /n/ before /h/ (some proper nouns)
text = rsub(text,"n()m","m%1m") -- /n/ before /m/
text = rsub(text,"t()s","%1ć") -- /t/ before /s/
-- final fix for "iy" and "uw" combination
text = rsub(text,"()()ɟ()","%1%2%3")
text = rsub(text,"()()w()","%1%2%3")
--final fix for phonetic diphthongs
text = rsub(text,"()i̯", "ai̯") --ay
text = rsub(text,"()u̯", "au̯") --aw
text = rsub(text,"()i̯", "i") -- ey
text = rsub(text,"()u̯", "iu̯") --iw
text = rsub(text,"()i̯", "oi̯") --oy or uy
table.insert(debug,text)
--Change /ʌ/, /ɪ/ and /ʊ/ back to /a/, /i/ and /u/ in penultimate
text = rsub(text,"()()(?)ʌ","%1%2%3a")
text = rsub(text,"()()(?)ɪ","%1%2%3i")
text = rsub(text,"()()(?)ʊ","%1%2%3u")
table.insert(debug,text)
--Coalesce or to
text = rsub(text,"()()()","%2")
table.insert(debug,text)
--turn phonemic consonants to Cebuano dental consonants
text = rsub(text,"d","d̪")
text = rsub(text,"l","l̪")
text = rsub(text,"n","n̪")
text = rsub(text,"ɾ","ɾ̪")
text = rsub(text,"s","s̪")
text = rsub(text,"t","t̪")
table.insert(debug, text)
--delete temporary macron in /a/, /e/, /i/, /o/ and /u/
text = rsub(text,"ā","a")
text = rsub(text,"ē","i")
text = rsub(text,"ī","i")
text = rsub(text,"ō","o")
text = rsub(text,"ū","u")
table.insert(debug, text)
else
text = rsub(text,"%.","")
end
table.insert(debug, text)
--delete temporary macron in vowels
text = rsub(text,"ā","a")
text = rsub(text,"ē","e")
text = rsub(text,"ī","i")
text = rsub(text,"ō","o")
text = rsub(text,"ū","u")
-- convert fake symbols to real ones
local final_conversions = {
= "t͡s", -- fake "t.s" to real "t.s"
= "j", -- fake "y" to real "y"
= "d͡ʒ" -- fake "j" to real "j"
}
text = rsub(text, "", final_conversions)
-- remove # symbols at word and text boundaries
text = rsub(text, "#(?)", "")
-- resuppress syllable mark before IPA stress indicator
text = rsub(text, "%.(" .. ipa_stress_c .. ")", "%1")
-- Do not have multiple syllable break consecutively
text = rsub_repeatedly(text, "(+)", ".")
text = rsub_repeatedly(text, "(?)(" .. ipa_stress_c .. ")(?)", "%2")
ceb_IPA_table = mw.ustring.toNFC(text)
end
return ceb_IPA_table
end
local function respelling_to_IPA(data)
local IPA_result = export.IPA(data.respelling)
return ("/%s/ "):format(IPA_result, IPA_result)
end
function export.show(frame)
local parent_args = frame:getParent().args
return require(pron_utilities_module).format_prons {
lang = lang,
respelling_to_IPA = respelling_to_IPA,
raw_args = parent_args,
track_module = "ceb-pron",
}
end
return export