Module:User:Awesomemeeos/uktest
- This module lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • user page • user talk page • userspace
This is a private module sandbox of Awesomemeeos, for their own experimentation. Items in this module may be added and removed at Awesomemeeos's discretion; do not rely on this module's stability.
local m_uk_translit = require("Module:uk-translit")
local export = {}
function export.pronunciation(word, accent)
if type(word) == "table" then
word, accent =
word.args[1] or word:getParent().args[1],
word.args.accent or word:getParent().args.accent
end
if not word or (word == "") then
error("Please put the word as the first postional parameter!")
end
word = mw.ustring.lower(word)
-- single characters that map to IPA sounds
local phonetic_chars_map= {
["a"] = "ɑ", ["b"] = "b", ["v"] = "ʋ", ["h"] = "ɦ", ["g"] = "ɡ",
["d"] = "d", ["e"] = "ɛ", ["je"] = "jɛ", ["ž"] = "ʒ", ["z"] = "z",
["y"] = "ɪ", ["i"] = "i", ["ji"] = "ji", ["j"] = "j", ["k"] = "k",
["l"] = "l", ["m"] = "m", ["n"] = "n", ["o"] = "ɔ", ["p"] = "p",
["r"] = "r", ["s"] = "s", ["t"] = "t", ["u"] = "u", ["f"] = "f",
["x"] = "x", ["c"] = "t͡s", ["č"] = "t͡ʃ", ["š"] = "ʃ", ["šč"] = "ʃt͡ʃ",
["ʹ"] = "ʲ", ["ju"] = "ju", ["ja"] = "jɑ", ["ʺ"] = "j",
-- accented vowels
["ú"] = "ˈ"
}
-- character sequences of two that map to IPA sounds
local phonetic_2chars_map = {
["dž"] = "d͡ʒ", ["dz"] = "d͡z",
-- Dental plosives assimilate to following hissing/hushing consonants, which is not noted in the spelling.
["ds"] = "d͡zs", ["dš"] = "d͡ʒʃ", ["dč"] = "d͡ʒt͡ʃ", ["dc"] = "d͡zt͡s",
["ts"] = "t͡s", ["tš"] = "t͡ʃʃ", ["tč"] = "t͡ʃː", ["tc"] = "t͡sː",
}
-- character sequences of three that map to IPA sounds
local phonetic_3chars_map = {
["dzʹ"] = "d͡zʲ",
-- Dental plosives assimilate to following hissing/hushing consonants, which is not noted in the spelling.
["tʹs"] = "t͡sʲː"
}
local phonetic = word
-- first apply consonant cluster simplifications that always occur orthographically
phonetic = mw.ustring.gsub(phonetic, "ntsʹk", "nʹsʹk")
phonetic = mw.ustring.gsub(phonetic, "stsʹk", "sʹk")
phonetic = mw.ustring.gsub(phonetic, "ntst", "nst")
phonetic = mw.ustring.gsub(phonetic, "stč", "šč")
phonetic = mw.ustring.gsub(phonetic, "std", "zd")
phonetic = mw.ustring.gsub(phonetic, "sts", "sː")
phonetic = mw.ustring.gsub(phonetic, "stsʹk", "sʹk")
phonetic = mw.ustring.gsub(phonetic, "^zš", "šː")
phonetic = mw.ustring.gsub(phonetic, "zš", "žš")
phonetic = mw.ustring.gsub(phonetic, "^zč", "šč")
phonetic = mw.ustring.gsub(phonetic, "zč", "žč")
-- then long consonants that are orthographically geminated.
phonetic = mw.ustring.gsub(phonetic, "([bvhgd])%1", "%1ː")
phonetic = mw.ustring.gsub(phonetic, "([^d]+)žž", "%1žː") -- джж sequence encode diphonemic дж
phonetic = mw.ustring.gsub(phonetic, "([^d]+)zz", "%1zː") -- дзз sequence encode diphonemic дз
phonetic = mw.ustring.gsub(phonetic, "([jklmnprstfxcčššč])%1", "%1ː")
phonetic = mw.ustring.gsub(phonetic, "dždž", "džː")
phonetic = mw.ustring.gsub(phonetic, "dzdz", "dzː")
-- remap apostrophe to '!' so that it doesn't conflict with IPA stress mark
phonetic = mw.ustring.gsub(phonetic, "'", "!")
-- replace multiple letter sequences
for key, replacement in pairs(phonetic_3chars_map) do
phonetic = mw.ustring.gsub(phonetic, key, replacement)
end
for key, replacement in pairs(phonetic_2chars_map) do
phonetic = mw.ustring.gsub(phonetic, key, replacement)
end
-- replace single letters of the alphabet
phonetic = mw.ustring.gsub(phonetic, '.', phonetic_chars_map)
-- add IPA stress mark and remove the acute
phonetic = mw.ustring.gsub(phonetic, "([ɑɛiɪuɔ][\204\129\204\128])","ˈ%1")
phonetic = mw.ustring.gsub(phonetic, "([\204\129\204\128])","")
-- add accent if the word is monosyllabic and not "|accent=off"
local _, numberOfVowels = mw.ustring.gsub(phonetic, "[ɑɛiɪuɔ]", "")
if (numberOfVowels == 1) and (accent ~= "off") then
phonetic = mw.ustring.gsub(phonetic, "([ɑɛiɪuɔ])", "ˈ%1")
end
-- palatalizable consonants before /i/ or /j/ become palatalized
phonetic = mw.ustring.gsub(phonetic, "([tdsznlrbpʋfɡmkɦxʃʒ])([ː]?)([ˈ]?)i", "%1ʲ%2%3i")
phonetic = mw.ustring.gsub(phonetic, "([tdsznlrbpʋfɡmkɦxʃʒ])([ː]?)j", "%1ʲ%2")
-- eliminate garbage sequences of [ʲːj] resulting from -тьс- cluster followed by [j]
phonetic = mw.ustring.gsub(phonetic, "ʲːj", "ʲː")
-- consonant simplification: ст + ц' → [с'ц']. We do it here because of palatalization.
-- Due to the т +ц → [ц:] rule length is present. According to Орфоепскі словник p. 13,
-- both forms are proper, without length in normal (colloquial) speech and with length
-- in slow speech, so we parenthesize the length as optional.
phonetic = mw.ustring.gsub(phonetic, "st͡sʲ([ː]?)", "sʲt͡sʲ(%1)")
-- assimilation: voiceless + voiced = voiced + voiced
-- should /ʋ/ be included as voiced? Орфоепічний словник doesn't voice initial cluster of шв (p. 116)
phonetic = mw.ustring.gsub(phonetic, "p([bdzʒɡɦ]+)", "b%1")
phonetic = mw.ustring.gsub(phonetic, "f([bdzʒɡɦ]+)", "v%1")
phonetic = mw.ustring.gsub(phonetic, "t([bdzʒɡɦ]+)", "d%1")
phonetic = mw.ustring.gsub(phonetic, "tʲ([bdzʒɡɦ]+)", "dʲ%1")
phonetic = mw.ustring.gsub(phonetic, "s([bdzʒɡɦ]+)", "z%1")
phonetic = mw.ustring.gsub(phonetic, "sʲ([bdzʒɡɦ]+)", "zʲ%1")
phonetic = mw.ustring.gsub(phonetic, "ʃ([bdzʒɡɦ]+)", "ʒ%1")
phonetic = mw.ustring.gsub(phonetic, "k([bdzʒɡɦ]+)", "ɡ%1")
phonetic = mw.ustring.gsub(phonetic, "x([bdzʒɡɦ]+)", "ɦ%1")
phonetic = mw.ustring.gsub(phonetic, "t͡s([bdzʒɡɦ]+)", "d͡z%1")
phonetic = mw.ustring.gsub(phonetic, "t͡sʲ([bdzʒɡɦ]+)", "d͡zʲ%1")
phonetic = mw.ustring.gsub(phonetic, "t͡ʃ([bdzʒɡɦ]+)", "d͡ʒ%1")
phonetic = mw.ustring.gsub(phonetic, "ʃt͡ʃ([bdzʒɡɦ]+)", "ʒd͡ʒ%1")
-- In the sequence of two consonants, of which the second is soft, the first is pronounced soft too
-- unless the first consonant is a labial, namely б, п, в, ф, м.
phonetic = mw.ustring.gsub(phonetic, "([tdsznl])(.)ʲ", "%1ʲ%2ʲ")
phonetic = mw.ustring.gsub(phonetic, "([tdsznl])t͡sʲ", "%1ʲt͡sʲ")
phonetic = mw.ustring.gsub(phonetic, "([tdsznl])d͡zʲ", "%1ʲd͡zʲ")
phonetic = mw.ustring.gsub(phonetic, "t͡s(.)ʲ", "t͡sʲ%1ʲ")
phonetic = mw.ustring.gsub(phonetic, "d͡z(.)ʲ", "d͡zʲ%1ʲ")
phonetic = mw.ustring.gsub(phonetic, "d͡zt͡sʲ", "d͡zʲt͡sʲ")
phonetic = mw.ustring.gsub(phonetic, "t͡sd͡zʲ", "t͡sʲd͡zʲ")
-- Hushing consonants ж, ч, ш assimilate to the following hissing consonants, giving a long hissing consonant:
-- [ʒ] + [t͡sʲ] → [zʲt͡sʲ], [t͡ʃ] + [t͡sʲ] → [t͡sʲː], [ʃ] + [t͡sʲ] → [sʲt͡sʲ], [ʃ] + [sʲ] → [sʲː]
phonetic = mw.ustring.gsub(phonetic, "ʒt͡sʲ", "zʲt͡sʲ")
phonetic = mw.ustring.gsub(phonetic, "t͡ʃt͡sʲ", "t͡sʲː")
phonetic = mw.ustring.gsub(phonetic, "ʃt͡sʲ", "sʲt͡sʲ")
phonetic = mw.ustring.gsub(phonetic, "ʃsʲ", "sʲː")
-- Hissing consonants before hushing consonants within a word assimilate - on зш and зч word-initially and
-- word-medially see above.
-- [s] + [ʃ] → [ʃː], [z] + [ʃ] → [ʒʃ], [z] + [t͡s] → [ʒt͡s]
-- [z] + [d͡ʒ] → [ʒd͡ʒ]
phonetic = mw.ustring.gsub(phonetic, "zʒ", "ʒː")
phonetic = mw.ustring.gsub(phonetic, "sʃ", "ʃː")
phonetic = mw.ustring.gsub(phonetic, "zt͡s", "ʒt͡s")
phonetic = mw.ustring.gsub(phonetic, "zd͡ʒ", "ʒd͡ʒ")
-- cleanup: excessive palatalization: CʲCʲCʲ → CCʲCʲ
phonetic = mw.ustring.gsub(phonetic, "([^ɑɛiɪuɔ]+)ʲ([^ɑɛiɪuɔ]+)ʲ([^ɑɛiɪuɔ]+)ʲ", "%1%2ʲ%3ʲ")
-- unstressed /ɑ/ has an allophone [ɐ]
phonetic = mw.ustring.gsub(phonetic, "([^ˈ]+)ɑ", "%1ɐ")
phonetic = mw.ustring.gsub(phonetic, "^ɑ", "ɐ")
-- unstressed /u/ has an allophone [ʊ]
phonetic = mw.ustring.gsub(phonetic, "([^ˈ]+)u", "%1ʊ")
phonetic = mw.ustring.gsub(phonetic, "^u", "ʊ")
-- unstressed /ɔ/ has by assimilation an allophone [o] before a stressed syllable with /u/ or /i/
phonetic = mw.ustring.gsub(phonetic, "ɔ([bdzʒɡɦmnlrpftskxʲʃ͡]+)ˈ([uiʊ]+)", "o%1ˈ%2")
-- one allophone [e] covers unstressed /ɛ/ and /ɪ/
phonetic = mw.ustring.gsub(phonetic, "([^ˈ])ɛ", "%1e")
phonetic = mw.ustring.gsub(phonetic, "^ɛ", "e")
phonetic = mw.ustring.gsub(phonetic, "([^ˈ])ɪ", "%1e")
phonetic = mw.ustring.gsub(phonetic, "^ɪ", "e")
-- /ʋ/ has an allophone [u̯] in a syllable coda
phonetic = mw.ustring.gsub(phonetic, "([ɑɛiɪuɔɐoʊe]+)ʋ", "%1u̯")
-- /ʋ/ has an allophone [w] before /ɔ, u/and voiced consonants (not after a vowel)
phonetic = mw.ustring.gsub(phonetic, "ʋ([ˈ]?)([ɔuoʊbdzʒɡɦmnlr]+)", "w%1%2")
-- /ʋ/ has an allophone [ʍ] before before voiceless consonants (not after a vowel)
phonetic = mw.ustring.gsub(phonetic, "ʋ([pftskxʃ]+)", "ʍ%1")
-- in a syllable-final position (i.e. the first position of a syllable coda) /j/ has an allophone [i̯]:
phonetic = mw.ustring.gsub(phonetic, "([ɑɛiɪuɔɐoʊe]+)j([ˈ]?)([bdzʒɡɦmnlrpftskxʃ]+)", "%1i̯%2%3")
phonetic = mw.ustring.gsub(phonetic, "([ɑɛiɪuɔɐoʊe]+)j$", "%1i̯")
-- also at the beginning of a word before a consonant
phonetic = mw.ustring.gsub(phonetic, "^j([bdzʒɡɦmnlrpftskxʃ]+)", "i̯%1")
-- remove old orthographic apostrophe
phonetic = mw.ustring.gsub(phonetic, "!", "")
-- stress mark in correct place
phonetic = mw.ustring.gsub(phonetic, "([bdzʒɡɦjʲmnlrpftskxʃʋwʍː͡]+)ˈ", "ˈ%1")
phonetic = mw.ustring.gsub(phonetic, "([ui]̯)ˈ([ʲ]?[ɑɛiɪuɔɐoʊe])", "ˈ%1%2")
phonetic = mw.ustring.gsub(phonetic, "ˈ(l[ʲ]?[ː]?)([bdzʒɡɦmnrpftskxʃʋ])", "%1ˈ%2")
phonetic = mw.ustring.gsub(phonetic, "ˈ(r[ʲ]?[ː]?)([bdzʒɡɦlmnpftskxʃʋ])", "%1ˈ%2")
phonetic = mw.ustring.gsub(phonetic, "ˈ(m[ʲ]?[ː]?)([bpfszʃʋʒ])", "%1ˈ%2")
phonetic = mw.ustring.gsub(phonetic, "ˈ(n[ʲ]?[ː]?)([dtfkɡɦlxszʃʋʒ])", "%1ˈ%2")
return (phonetic)
end
return export