Module:cbk-pronunc

Hello, you have come here looking for the meaning of the word Module:cbk-pronunc. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:cbk-pronunc, but we will also tell you about its etymology, its characteristics and you will know how to say Module:cbk-pronunc in singular and plural. Everything you need to know about the word Module:cbk-pronunc you have here. The definition of the word Module:cbk-pronunc will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:cbk-pronunc, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

Chavacano pronunciation module, used to power Template:cbk-IPA.


-- Based on ] by TagaSanPedroAko, in turn based on ] by Benwing2. Some code based on ]
-- Adaptation by TagaSanPedroAko.

local export = {}

local m_IPA = require("Module:IPA")

local lang = require("Module:languages").getByCode("cbk")

local u = mw.ustring.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 W = "" -- glide
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 T = "" -- obstruent or nasal

local unstressed_words = require("Module:table").listToSet({ --feel free to add more unstressed words
	"a", "el", "la", "los", "de", "del", "na", -- articles and prepositions
	"y", "o", "si", "que", "ni", -- conjunctions
    "no", -- negation word
})

-- 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, phonetic)
	local debug = {}

	text = ulower(text or mw.title.getCurrentTitle().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)

	--determining whether "y" or "w" is a consonant or a Vowel
	text = rsub(text, "y(" .. V .. ")", "ɟ%1") -- not the real sound
	text = rsub(text, "y#", "i")
	text = rsub(text, "w(" .. V .. ")","w%1")
	text = rsub(text, "w#","u")

	-- handle certain combinations; ch, ll, ng and sh handling needs to go first
	text = rsub(text, "ch", "ć") --not the real sound
	text = rsub(text, "ll", "ʎ")
	text = rsub(text, "ñg", "ŋ") --use this for NG in loanwords from Philippine languages. Otherwise will be handled as Spanish NG
	text = rsub(text, "sh", "ʃ")

	--x
	text = rsub(text, "x", "ks")

	--c, g, q
	text = rsub(text, "c()", "s%1")
	text = rsub(text, "g()", "x%1")
	text = rsub(text, "gu(" .. V .. ")", "ɡ%1")
	text = rsub(text, "gü(" .. V .. ")", "ɡw%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
    --J is for Spanish J. To handle non-Spanish J, respell it to DI
    --7 is for glottal stop in loanwords from Philippine languages.
		{  = "k",  = "p",  = "ɡ",  = "x",  = "ɲ",  = "k",  = "ɾ",  = "b",  = "ɟ",  = "s",  = "ʔ" })

	-- trill in rr (as in ], ])
	text = rsub(text, "ɾɾ", "r")
	text = rsub(text, "()ɾ", "%1r")

	-- reduce any remaining double consonants;
	-- do this before handling of -nm- e.g. in ], which generates a double consonant, and do this
	text = rsub(text, "(" .. C .. ")%1", "%1")

	-- voiceless stop to voiced before obstruent or nasal; but intercept -ts-, -tz-
	local voice_stop = {  = "b",  = "d",  = "ɡ" }
	text = rsub(text, "t(" .. separator_c .. "*)", "!%1") -- temporary symbol
	text = rsub(text, "()(" .. separator_c .. "*" .. T .. ")",
			function(stop, after)
				return voice_stop .. after
			end)
	text = rsub(text, "!", "t")

	text = rsub(text, "n(*)", "m%1")

	-- remove silent h before syllable division
	text = rsub(text, "h", "")

	table.insert(debug, text)

	--syllable division
	local vowel_to_glide = {  = "j",  = "w",  = "w" }
	-- i, o and u between vowels -> j and w.
	text = rsub_repeatedly(text, "(" .. V .. accent_c .. "*)()(" .. V .. ")",
			function(v1, iou, v2)
				return v1 .. vowel_to_glide .. v2
			end
	)
	text = rsub_repeatedly(text, "(" .. V .. accent_c .. "*)(" .. C .. W .. "?" .. 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(text, "()%.()", ".%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 .. stress_c .. ")", "%1.%2")
	text = rsub(text, "(" .. stress_c .. ")()", "%1.%2")
	text = rsub_repeatedly(text, "(" .. stress_c .. ")(" .. V .. stress_c .. ")", "%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)

	--diphthongs
	text = rsub(text, "ih?()", "j%1")
	text = rsub(text, "uh?()", "w%1")

	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 ^ 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. Follow Spanish rules for stress.
			if #syllables > 1 and rfind(word, "#") or #syllables == 1 and rfind(word, "") 	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, "%.")

		if rfind(word, "men%.te#") then
			local mente_syllables
			-- Words ends in -mente (converted above to ménte); add a stress to the preceding portion
			-- (e.g. ] -> 'ágriaménte') unless already stressed (e.g. ]).
			-- It will be converted to secondary stress further below. Essentially, we rip the word apart
			-- into two words ('mente' and the preceding portion) and stress each one independently.
			mente_syllables = {}
			mente_syllables = table.remove(syllables)
			mente_syllables = table.remove(syllables)
			accent_word(table.concat(syllables, "."), syllables)
			accent_word(table.concat(mente_syllables, "."), mente_syllables)
			table.insert(syllables, mente_syllables)
			table.insert(syllables, mente_syllables)
		else
			accent_word(word, syllables)
		end

		-- Vowels are nasalized if followed by nasal in same syllable.
		if phonetic then
			for i = 1, #syllables do
				-- first check for two vowels (veinte)
				syllables = rsub(syllables, "(" .. V .. ")(" .. V .. ")()",
						"%1" .. TILDE .. "%2" .. TILDE .. "%3")
				-- then for one vowel
				syllables = rsub(syllables, "(" .. V .. ")()", "%1" .. TILDE .. "%2")
			end
		end

		-- Reconstruct the word.
		words = table.concat(syllables, phonetic and "." or "")
	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)

table.insert(debug,text)
   
    --correct final glottal stop placement
    text = rsub(text,"()ʔ()()","%1%2%3ʔ")

    --vowels with grave to vowel+glottal stop
    text = rsub(text,"à","aʔ")
    text = rsub(text,"è","eʔ")
    text = rsub(text,"ì","iʔ")
    text = rsub(text,"ò","oʔ")
    text = rsub(text,"ù","uʔ")

    table.insert(debug,text)

	--phonetic transcription
	if phonetic then

		--/j/-coalescence before D, S, and T

        text = rsub(text,"()()j","%2ĵ") -- /d/ before /j/
        text = rsub(text,"s()j","%1ʃ") -- /s/ before /j/
        text = rsub(text,"t()j","%1ć") -- /t/ before /j/
        text = rsub(text,"()d()()","%1ĵ%3") -- /dj/ at syllable onset
        text = rsub(text,"()s()()","%1ʃ%3") -- /sj/ at syllable onset
        text = rsub(text,"()t()()","%1ć%3") -- /tj/ at syllable onset

		-- θ, s, f before voiced consonants
		local voiced = "mnɲbdɟɡʎl"
		local r = "ɾr"
		local tovoiced = {
			 = "z",
		}
		local function voice(sound, following)
			return tovoiced .. following
		end
		text = rsub(text, "()(" .. separator_c .. "*)", voice)

		-- fricative vs. stop allophones; first convert stops to fricatives, then back to stops
		-- after nasals and sometimes after l
		-- only affects Chavacano Y (/b/, /d/ /g/ are not affricates)
		local stop_to_fricative = {  = "ʝ" }
		local fricative_to_stop = {  = "ɟ" }
		text = rsub(text, "", stop_to_fricative)
		text = rsub(text, "(" .. separator_c .. "*)()",
function(nasal_l, fricative)
					return nasal_l .. fricative_to_stop
				end
		)
		text = rsub(text, "(##" .. ipa_stress_c .. "*)()",
				function(stress, fricative)
					return stress .. fricative_to_stop
				end
		)
		text = rsub(text, "", {  = "t̪",  = "d̪" })

		--dental s/z
		local dental = "dt"
		local todental = {
			 = "s̪",
			 = "z̪",
		}
		local function dent(sound, following)
			return todental .. following
		end
		text = rsub(text, "()(" .. separator_c .. "*)", dent)

		-- nasal assimilation before consonants
		local labiodental, dentialveolar, dental, palatal, velar, alveolar = "ɱ", "n̪", "n̟", "ɲ", "ŋ", "n"
		local nasal_assimilation = {
			 = dentialveolar,  = dentialveolar,
			 = palatal,
			 = palatal,
			 = palatal,  = palatal,
			 = velar,  = velar,  = velar,
			 = alveolar,  = alveolar,  = alveolar,  = alveolar,  = alveolar,  = alveolar,
		}
		text = rsub(text, "n(" .. separator_c .. "*)(.)",
				function(stress, following)
					return (nasal_assimilation or "n") .. stress .. following
				end
		)

		-- lateral assimilation before consonants
		text = rsub(text, "l(" .. separator_c .. "*)(.)",
				function(stress, following)
					local l = "l"
					if following == "t" or following == "d" then
						-- dentialveolar
						l = "l̪"
					elseif following == "θ" then
						-- dental
						l = "l̟"
					elseif following == "ć" or following == "ɲ" or following == "ɟ" or following == "ʎ" then
						-- palatal
						l = "ʎ"
					end
					return l .. stress .. following
				end)

		--semivowels
		text = rsub(text, "eu", "ju")
		text = rsub(text, "()", "%1̯")
		text = rsub(text, "()", "%1̯")

	end

	table.insert(debug, text)

	-- convert fake symbols to real ones
    	local final_conversions = {
		 = "t͡ʃ", -- fake "ch" to real "ch"
		 =  "ʝ", -- fake "y" to real "y"
	}

    	local final_conversions_phonetic = {
		 = "t͡ʃ", -- fake "ch" to real "ch"
		 =  "ɟ͡ʝ", -- fake "y" to real "y"
		 =  "d͡ʒ", -- fake "di+vowel" to real "di+vowel"
	}

	if phonetic then
	text = rsub(text, "", final_conversions_phonetic)
    	end
	text = rsub(text, "", final_conversions)

	-- remove # symbols at word and text boundaries
	text = rsub(text, "#", "")

	return mw.ustring.toNFC(text)

end

function export.show(frame)
	local params = {
		 = {},
		 = {},
		 = {},
		 = { type = "number", default = 1 },
	}

	local parargs = frame:getParent().args
	local args = require("Module:parameters").process(parargs, params)

	local results = {}

	local text = args or mw.title.getCurrentTitle().text

	table.insert(results, { pron = "/" .. export.IPA(text, false) .. "/" })
	table.insert(results, { pron = "" })

	local bullet = string.rep("* ", args.bullets) .. " "
	local pre = args.pre and args.pre .. " " or ""
    local post = args.post and " " or ""

	return bullet .. pre .. m_IPA.format_IPA_full { lang = lang, items = results } .. post
end

return export