Մոդուլ:hy-pronunciation

Վիքիբառարան-ից

Documentation for this module may be created at Մոդուլ:hy-pronunciation/doc

	-- Պատճենված է անգլերեն Վիքիբառարանի համապատասխան հոդվածից՝ https://en.wiktionary.org/wiki/Module:hy-pronunciation։ Ցանկալի է վերջինիս հետ պահպանել սինխրոն վիճակում։
local export = {}

-- single characters that map to IPA sounds   
local phonetic_chars_map = {
	["ա"]="ɑ", ["բ"]="b", ["գ"]="ɡ", ["դ"]="d", ["ե"]="ɛ", ["զ"]="z",
	["է"]="ɛ", ["ը"]="ə", ["թ"]="tʰ", ["ժ"]="ʒ", ["ի"]="i", ["լ"]="l",
	["խ"]="χ", ["ծ"]="t͡s", ["կ"]="k", ["հ"]="h", ["ձ"]="d͡z", ["ղ"]="ʁ", 
	["ճ"]="t͡ʃ", ["մ"]="m", ["յ"]="j", ["ն"]="n", ["շ"]="ʃ", ["ո"]="ɔ",
	["չ"]="t͡ʃʰ", ["պ"]="p", ["ջ"]="d͡ʒ", ["ռ"]="r", ["ս"]="s", ["վ"]="v", 
	["տ"]="t", ["ր"]="ɾ", ["ց"]="t͡sʰ", ["ւ"]="v", ["և"]="ɛv", ["փ"]="pʰ", ["ք"]="kʰ",
	["օ"]="ɔ", ["ֆ"]="f", ["-"]=" ",
}

-- character sequences of two that map to IPA sounds
local phonetic_2chars_map = {
	['ու'] = 'u',
	-- diphthongization in the following combinations: [իե] = [jɛ], [իու] = [ju], [իա] = [jɑ]
	['իե'] = 'jɛ',
	['իու'] = 'ju',
	['իա'] = 'jɑ'
}

function export.pronunciation(word)
	if type(word) == "table" then
		word = word.args[1] or word:getParent().args[1]
	end
	if not word or (word == "") then
		error("Please put the word as the first positional parameter!")
	end
	word = mw.ustring.lower(word)

	local phonetic = word

	-- then long consonants that are orthographically geminated.
	phonetic = mw.ustring.gsub(phonetic, "([բգդզթժլխծկձղճմյնշչպջռսվտրցփքֆ])%1", "%1ː")

	for pat, repl in pairs(phonetic_2chars_map) do
		phonetic = mw.ustring.gsub(phonetic, pat, repl)
	end

	-- ե and ո are pronounced as jɛ and vɔ word-initially.
	phonetic = mw.ustring.gsub(phonetic, "^ե", "յէ")
	phonetic = mw.ustring.gsub(phonetic, "^ո", "վօ")

	phonetic = mw.ustring.gsub(phonetic, '.', phonetic_chars_map)

	-- assimilation: nasal + velar plosives = velar nasal + velar plosives
	phonetic = mw.ustring.gsub(phonetic, "n([ɡkχ]+)", "ŋ%1")

	-- pseudo-palatalization under the influence of Russian [COLLOQUIAL, NOT STANDARD]
	--phonetic = mw.ustring.gsub(phonetic, "tj", "t͡sj")
	--phonetic = mw.ustring.gsub(phonetic, "tʰj", "t͡sʰj")
	--phonetic = mw.ustring.gsub(phonetic, "dj", "d͡zj")

	-- trilling of ɾ in some positions [COLLOQUIAL, NOT STANDARD]
	--phonetic = mw.ustring.gsub(phonetic, "ɾt", "rt")

	-- Do not add a stress mark for monosyllabic words. Check to see if the word contains only a single instance of [ɑɛəɔiu].
	local numberOfVowels = select(2, mw.ustring.gsub(phonetic, "[ɑɛəɔiu]", ""))

	-- If polysyllabic, add IPA stress mark using the following rules. The stress is always on the last syllable not 
	-- formed by schwa [ə]. In some rare cases the stress is not on the last syllable. In such cases the stressed vowel
	-- is marked by the Armenian stress character <՛>, e.g. մի՛թե. So:
	--      1) Find the vowel followed by <՛>․ If none, jump to step 2. Else check if it is the first vowel of the word.
	--         If true, put the IPA stress at the beginning, else do step 3.
	--      2) Find the last non-schwa vowel, i.e. [ɑɛɔiu],
	--      3) If the IPA symbol preceding it is [ɑɛəɔiu], i.e. a vowel, put the stress symbol between them, 
	--         if it is [b,ɡ,d,z,tʰ,ʒ,l,χ,t͡s,k,h,d͡z,ʁ,t͡ʃ,m,j,n,ʃ,t͡ʃʰ,p,d͡ʒ,r,s,v,t,ɾ,t͡sʰ,pʰ,kʰ,f], i.e. a consonant, 
	--         put the stress before that consonant.
	if numberOfVowels > 1 then
		local rcount
		phonetic, rcount = mw.ustring.gsub(phonetic, "([bɡdztʰʒlχt͡skhʁʃmjnprsvtɾf]?)([ː]?)([ɑɛɔiuə])՛", "ˈ%1%2%3")
		if rcount == 0 then
			phonetic = mw.ustring.gsub(phonetic, "([bɡdztʰʒlχt͡skhʁʃmjnprsvtɾf])([ː]?)([ɑɛɔiu])([bɡdzətʰʒlχt͡skhʁʃmjnprsvtɾf]*)$", "ˈ%1%2%3%4")
			phonetic = mw.ustring.gsub(phonetic, "([ɑɛəɔiu])([ɑɛɔiu])([bɡdzətʰʒlχt͡skhʁʃmjnprsvtɾf]*)$", "%1ˈ%2%3")
		end
		phonetic = mw.ustring.gsub(phonetic, "([tpk])ˈʰ", "ˈ%1ʰ")
		phonetic = mw.ustring.gsub(phonetic, "^([bɡdztʰʒlχt͡skhʁʃmjnprsvtɾf]+)ˈ([bɡdztʰʒlχt͡skhʁʃmjnprsvtɾf])", "ˈ%1%2")
		phonetic = mw.ustring.gsub(phonetic, "t͡ˈs", "ˈt͡s")
		phonetic = mw.ustring.gsub(phonetic, "t͡ˈʃ", "ˈt͡ʃ")
		phonetic = mw.ustring.gsub(phonetic, "d͡ˈʒ", "ˈd͡ʒ")
		phonetic = mw.ustring.gsub(phonetic, "d͡ˈz", "ˈd͡z")
		phonetic = mw.ustring.gsub(phonetic, "t͡sˈʰ", "ˈt͡sʰ")
		phonetic = mw.ustring.gsub(phonetic, "t͡ʃˈʰ", "ˈt͡ʃʰ")
	end

	return phonetic
end
 
return export