local export = {}
-- single characters that map to IPA sounds
local phonetic_chars_map = {
-- Eastern Armenian
east = {
="ɑ", ="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", ="pʰ", ="kʰ",
="ɔ", ="f", =" ", ="", =""
},
-- Western Armenian
west = {
="ɑ", ="pʰ", ="kʰ", ="tʰ", ="ɛ", ="z",
="ɛ", ="ə", ="tʰ", ="ʒ", ="i", ="l",
="χ", ="d͡z", ="ɡ", ="h", ="t͡sʰ", ="ʁ",
="d͡ʒ", ="m", ="j", ="n", ="ʃ", ="ɔ",
="t͡ʃʰ", ="b", ="t͡ʃʰ", ="ɾ", ="s", ="v",
="d", ="ɾ", ="t͡sʰ", ="v", ="pʰ", ="kʰ",
="ɔ", ="f", =" ", ="", =""
},
}
-- character sequences of two that map to IPA sounds
local phonetic_2chars_map = {
east = {
= 'u',
-- diphthongization in the following combinations: = , =
= 'jɛ',
= 'jɑ'
},
west = {
= 'u',
= 'œ',
= function(before)
-- if not in the initial position and if not preceded by
-- This will not catch initial position in a word
-- that follows a vowel-initial word.
if not (before == '' or mw.ustring.find(before, '')) then
return 'ʏ'
end
end,
-- diphthongization in the following combinations: = , =
= 'jɛ',
= 'jɑ'
},
}
function export._pronunciation(word, system)
if not (phonetic_chars_map and phonetic_2chars_map) then
error("Invalid system " .. tostring(system))
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, "^ո", "վօ")
-- except when followed by another վ.
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(+)", "ŋ%1")
-- pseudo-palatalization under the influence of Russian
--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
--phonetic = mw.ustring.gsub(phonetic, "ɾt", "rt")
phonetic = mw.ustring.gsub(phonetic, "%S+", function(word)
-- Do not add a stress mark for monosyllabic words. Check to see if the word contains only a single instance of +.
local numberOfVowels = select(2, mw.ustring.gsub(phonetic, "", "%0"))
-- 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. ,
-- 3) If the IPA symbol preceding it is , i.e. a vowel, put the stress symbol between them,
-- if it is NOT , i.e. it is a consonant,
-- put the stress before that consonant.
if numberOfVowels > 1 then
local rcount
phonetic, rcount = mw.ustring.gsub(phonetic, "(*)՛", "ˈ%1")
if rcount == 0 then
phonetic = mw.ustring.gsub(phonetic, "(**)$", "ˈ%1")
phonetic = mw.ustring.gsub(phonetic, "(*?*ə*)$", "ˈ%1")
end
phonetic = mw.ustring.gsub(phonetic, "()ˈ(+)()", "%1%2ˈ%3")
phonetic = mw.ustring.gsub(phonetic, "(.)͡ˈ", "ˈ%1͡")
return phonetic
end
end)
return phonetic
end
function export.pronunciation(word, system)
if type(word) == "table" then
local frame = word
word = frame.args or frame:getParent().args
system = frame.args.system or "east"
end
if not word or (word == "") then
error("Please put the word as the first positional parameter!")
end
return export._pronunciation(word, system)
end
return export