Module:IPAc2-mh: Difference between revisions

Content deleted Content added
No edit summary
[w] off-glide tweak
 
(23 intermediate revisions by 3 users not shown)
Line 1:
-- This module is primarily maintained at:
-- https://en.wiktionary.org/wiki/Module:mh-pronunc
-- Please direct all technical queries and contributions there.
-- The version of this script on Wikipedia is only a mirror.
 
local export = {}
 
local math_maxMERGED_VOWELS = math.maxfalse
local PARENTHETICAL_EPENTHESIS = true
local mw_text_gsplit = mw.text.gsplit
local mw_text_splitPHONETIC_DETAILS = mw.text.splitfalse
local mw_text_trimW_OFF_GLIDES = mw.text.trimtrue
local mw_ustring_gsub = mw.ustring.gsub
local mw_ustring_lower = mw.ustring.lower
local string_byte = string.byte
local string_find = string.find
local string_gmatch = string.gmatch
local string_gsub = string.gsub
local string_lower = string.lower
local string_sub = string.sub
local table_concat = table.concat
local table_remove = table.remove
 
local ASYLL = "̯"
Line 26 ⟶ 18:
local TIE2 = "͜"
 
local C1_ = "pbtdcJszkgmnNrlyYhH_pbtdSZszkgmnNrlyYhH_"
local C1 = "["..C1_.."]"
local CC2_ = ".[jGw]"
local C = ".["..C2_.."]"
local V_ = "aEeiAV7MQOou"
local V = "["..V_.."]"
Line 39 ⟶ 32:
local EMPTY = {}
 
-- Adds elements to a sequence as if it's a set (retains unique elements only).
local function addUnique(seq, value)
for _, value2 in pairs(seq) do
Line 48 ⟶ 42:
end
 
-- Intended to work the same as JavaScript's Object.assign() function.
local function assign(target, ...)
local args = { ... }
Line 61 ⟶ 56:
 
local function fastTrim(text)
return string.match(text, "^%s*(.-)%s*$")
if text == "" or text == " " then
return ""
else
local atLeft = string_byte(text) == 32
local atRight = string_byte(text, -1) == 32
if atLeft then
if atRight then
return string_sub(text, 2, -2)
else
return string_sub(text, 2)
end
elseif atRight then
return string_sub(text, 1, -2)
else
return text
end
end
end
 
local function parseBoolean(text)
if type(text) == "string" then
text = string_gsubstring.gsub(text, "[^0-9A-Za-z]", "")
if text ~= "" and text ~= "0" and string_lowerstring.lower(text) ~= "false" then
return true
end
Line 93 ⟶ 72:
chars = chars or {}
local index = 1
for ch in string_gmatchstring.gmatch(text, pattern or UTF8_CHAR) do
chars[index] = ch
index = index + 1
Line 99 ⟶ 78:
if index <= #chars then
if shorten then
table_removetable.remove(chars, index)
else
repeat
Line 111 ⟶ 90:
 
local function string_gsub2(text, pattern, subst)
return string_gsubstring.gsub(string_gsubstring.gsub(text, pattern, subst), pattern, subst)
end
 
Line 137 ⟶ 116:
local function ZTBL(text, sep)
local tbl = {}
for key in mw_text_gsplitmw.text.gsplit(text, sep or " ") do
tbl[key] = true
end
Line 145 ⟶ 124:
 
 
local PARSE_PSEUDO_GLIDE = {
["y"] = "0",
local PARSE_C_CH_CW
["h"] = "0h",
local PARSE_REMAINING
["w"] = "0w"
}
 
local PARSE_C_CH_CW = {
["k"] = "kG",
["kh"] = "kGh", -- N\A
["kw"] = "kW",
["l"] = "lJ",
["lh"] = "lG",
["lw"] = "lW",
["m"] = "mJ",
["mh"] = "mG",
["mw"] = "mJw", -- N\A
["n"] = "nJ",
["nh"] = "nG",
["nw"] = "nW",
["ng"] = "NG",
["ngh"] = "NGh", -- N\A
["ngw"] = "NW",
["r"] = "rG",
["rh"] = "rGh", -- N\A
["rw"] = "rW",
["0"] = "_J",
["0h"] = "_G",
["0w"] = "_W"
}
 
local PARSE_REMAINING = {
["b"] = "pG",
["d"] = "rj",
["e"] = "E",
["&"] = "e",
["h"] = "hG",
["j"] = "tj",
["J"] = "j",
["p"] = "pj",
["t"] = "tG",
["w"] = "hw",
["W"] = "w",
["y"] = "hj",
["z"] = "yj",
["Z"] = "Yj",
["'"] = ""
}
 
local function parse(code)
local outSeq = {}
code = mw_ustring_gsubmw.ustring.gsub(code, "%s+", " ")
code = string_lowerstring.lower(code)
for text in mw_text_gsplitmw.text.gsplit(code, " ?*,[ ,]*") do
text = fastTrim(text)
if text ~= "" then
local temp = string_gsubstring.gsub(text, "[abdeghijklmnprtwy_&'%- ]", "")
if temp ~= "" then
error("'"..code.."' contains unsupported characters: "..temp)
Line 165 ⟶ 188:
-- Recognize "y_", "h_", "w_", "_y", "_h", "_w" as pseudo-glides.
text = string.gsub(text, "_*([hwy])_+", PARSE_PSEUDO_GLIDE)
PARSE_PSEUDO_GLIDE = PARSE_PSEUDO_GLIDE or {
text = string.gsub(text, "_+([hwy])", PARSE_PSEUDO_GLIDE)
["y"] = "0", ["h"] = "0h", ["w"] = "0w"
if string.find(text, "_") then
}
text = string_gsub(text, "_*([hwy])_+", PARSE_PSEUDO_GLIDE)
text = string_gsub(text, "_+([hwy])", PARSE_PSEUDO_GLIDE)
if string_find(text, "_") then
error("contains misplaced underscores: "..code)
end
-- a plain {i} protected from dialect-specific reflexes
text = string_gsubstring.gsub(text, "'i", "I")
-- "yi'y" and "'yiy" sequences
text = string_gsubstring.gsub(text, "('?)yi('*)y", function(aposA, aposB)
if aposA ~= "" then
-- "dwelling upon" i
Line 189 ⟶ 209:
-- Convert multigraphs to pseudo-X-SAMPA format.
text = string.gsub(text, "[klmnr0]g?[hw]?", PARSE_C_CH_CW)
PARSE_C_CH_CW = PARSE_C_CH_CW or {
if string.find(text, "g") then
["k"] = "kG",
["kh"] = "kGh", -- N\A
["kw"] = "kW",
["l"] = "lJ",
["lh"] = "lG",
["lw"] = "lW",
["m"] = "mJ",
["mh"] = "mG",
["mw"] = "mJw", -- N\A
["n"] = "nJ",
["nh"] = "nG",
["nw"] = "nW",
["ng"] = "NG",
["ngh"] = "NGh", -- N\A
["ngw"] = "NW",
["r"] = "rG",
["rh"] = "rGh", -- N\A
["rw"] = "rW",
["0"] = "_J",
["0h"] = "_G",
["0w"] = "_W"
}
text = string_gsub(text, "[klmnr0]g?[hw]?", PARSE_C_CH_CW)
if string_find(text, "g") then
error("contains g that is not part of ng: "..code)
end
-- Convert remaining sequences to pseudo-X-SAMPA format.
text = string.gsub(text, ".", PARSE_REMAINING)
PARSE_REMAINING = PARSE_REMAINING or {
["b"] = "pG",
["d"] = "rj",
["e"] = "E",
["&"] = "e",
["h"] = "hG",
["j"] = "tj",
["J"] = "j",
["p"] = "pj",
["t"] = "tG",
["w"] = "hw",
["W"] = "w",
["y"] = "hj",
["z"] = "yj",
["Z"] = "Yj",
["'"] = ""
}
text = string_gsub(text, ".", PARSE_REMAINING)
-- Enforce CVC, CVCVC, CVCCVC, etc. phonotactics,
-- but allow VC, CV at affix boundaries
-- where a vowel may link to another morpheme's consonant.
temp = string_gsubstring.gsub(text, "[%s%-]+", "")
if string_findstring.find(temp, "_..[jGw]") or
string_findstring.find(temp, ".[jGw]_.")
then
error("pseudo-glides may not neighbor a consonant")
end
if string_findstring.find(temp, VI.."_."..VI) then
error("pseudo-glides may only be at the beginning or end"..code)
end
if string_findstring.find(temp, VI..VI) then
error("vowels must be separated by a consonant: "..code)
end
if string_findstring.find(temp, ".[jGw].[jGw].[jGw]") then
error("each consonant cluster is limited to two: "..code)
end
if string_findstring.find(temp, ".[jGw].[jGw]$") then
error("may not end with a consonant cluster: "..code)
end
string_gsubstring.gsub(temp, "^(.[jGw])(.[jGw])", function(consonX, consonY)
if consonX ~= consonY then
error("may only begin with single or geminated consonant: "
Line 292 ⟶ 272:
["hj"] = "y", ["hG"] = "h", ["hw"] = "w",
["_j"] = "", ["_G"] = "", ["_w"] = "",
["a"] = "a",
["E"] = "e",
["e"] = "&",
["i"] = "i",
["I"] = "i"
}
local BENDER_MED = assign({}, BENDER_1968, {
Line 306 ⟶ 286:
["lG"] = "ļ",
["lw"] = "ļ°",
["e"] = "ȩ"
})
local BENDER_MOD = assign({}, BENDER_MED, {
Line 317 ⟶ 297:
["lG"] = "ḷ",
["lw"] = "ḷʷ",
["e"] = "ẹ"
})
local BENDER_DEFAULT = assign({}, BENDER_MOD, {
Line 325 ⟶ 305:
["lG"] = "ļ",
["lw"] = "ļʷ",
["e"] = "ȩ"
})
local BENDER_MAPS = {
["1968"] = BENDER_1968,
["med"] = BENDER_MED,
["mod"] = BENDER_MOD
}
 
Line 340 ⟶ 320:
local version = args and args.version
local map = BENDER_MAPS[
type(version) == "string" and string_lowerstring.lower(version) or ""
] or BENDER_DEFAULT
local outSeq = {}
for _, text in pairs(inSeq) do
text = string_gsubstring.gsub(text, ".[jGw]?", map)
addUnique(outSeq, text)
end
return outSeq
end
 
 
 
local TO_MOD = {
["Ȩ"] = "Ẹ", ["ȩ"] = "ẹ",
["Ļ"] = "Ḷ", ["ļ"] = "ḷ",
["M̧"] = "Ṃ", ["m̧"] = "ṃ",
["Ņ"] = "Ṇ", ["ņ"] = "ṇ",
["N̄"] = "Ñ", ["n̄"] = "ñ",
["O̧"] = "Ọ", ["o̧"] = "ọ"
}
 
local function toMOD(text)
text = mw.ustring.gsub(text, ".["..CEDILLA..MACRON.."]?", TO_MOD)
return text
end
 
Line 363 ⟶ 359:
["hj"] = "j", ["hG"] = "ɰ", ["hw"] = "w",
["_j"] = "", ["_G"] = "", ["_w"] = "",
["a"] = "æ",
["E"] = "ɛ",
["e"] = "e",
["i"] = "i",
["I"] = "i"
}
if false then
Line 386 ⟶ 382:
local outSeq = {}
for _, text in pairs(inSeq) do
text = string_gsubstring.gsub(text, ".[jGw]?", PHONEMIC_MAP)
addUnique(outSeq, text)
end
return outSeq
end
 
 
 
local TO_MOD = {
["Ȩ"] = "Ẹ", ["ȩ"] = "ẹ",
["Ļ"] = "Ḷ", ["ļ"] = "ḷ",
["M̧"] = "Ṃ", ["m̧"] = "ṃ",
["Ņ"] = "Ṇ", ["ņ"] = "ṇ",
["N̄"] = "Ñ", ["n̄"] = "ñ",
["O̧"] = "Ọ", ["o̧"] = "ọ"
}
 
local function toMOD(text, args)
text = mw_ustring_gsub(text, ".["..CEDILLA..MACRON.."]?", TO_MOD)
if args and parseBoolean(args.lower) then
text = mw_ustring_lower(text)
end
return text
end
 
Line 424 ⟶ 401:
local F2_BACK = 2
local F2_ROUND = 3
local F2 = {
["j"] = F2_FRONT,
["G"] = F2_BACK,
["w"] = F2_ROUND
}
 
local FRONT_VOWEL = {}
Line 443 ⟶ 424:
end
 
local function maxF1(a, b, c)
if bc then
return VOWEL[math_maxmath.max(2, F1[a], F1[b], F1[c])][F2_FRONT]
elseif b then
return VOWEL[math.max(F1[a], F1[b])][F2_FRONT]
else
return VOWEL[math_max(2, F1FRONT_VOWEL[a])][F2_FRONT]
end
end
Line 454 ⟶ 437:
-- Morphemes can begin with geminated consonants, but spoken words cannot.
text = string_gsubstring.gsub(text, "^(.[jGw])( *)%1( *)("..VI..")",
function(conson, _, __, vowel)
if conson == "hG" then
if isRalik then
return "hG"..vowel.._.."hG"..__..vowel
else
return "hG".._..__..vowel
end
else
returnif "hG"..vowelisRalik then
return "hj"..maxF1(vowel, "E")..conson.._..conson..__..vowel
end
else
return conson..maxF1(vowel, "E").._..conson..__..vowel
if isRalik then
end
return "hj"..maxF1(vowel)..conson..conson..vowel
else
return conson..maxF1(vowel)..conson..vowel
end
end
end)
-- Initial {yiyV-, yiwV-, wiwV-} sequences have special behavior.
-- To block this in the template argument, use "'i" instead of "i".
text = " "..text
text = string_gsubstring.gsub(text,
"([ jGw])( *)(h[jw])( *)i( *)(h[jw])( *)("..VI..")",
function(nonVowel, _, consonX, __, ___, consonY, ____, vowel)
if consonY == "hw" then
-- {yiwV-, wiwV-} sequences
Line 482 ⟶ 468:
end
-- {[yw]iwV-} becomes {[yw]iwwV-} in both dialects.
return nonVowel.._..consonX..__..
"I"..___..consonY..____..consonY..vowel
elseif consonX == "hj" then
-- {yiyV-} sequences
if isRalik then
-- "dwelling upon" i
return nonVowel.._..__.."Yj"..___..____..vowel
else
-- "passing over lightly" i
return nonVowel.._..__.."yj"..___..____..vowel
end
end
end
)
text = string_substring.sub(text, 2)
-- Restore protected {i}, we won't be checking for it anymore.
text = string_gsubstring.gsub(text, "I", "i")
return text
Line 507 ⟶ 494:
 
local IS_VOWEL = FRONT_VOWEL
 
local VOWEL_REFLEX
if true then
-- [f1]
local aEei = { "a", "E", "e", "i" }
local AEei = { "A", "E", "e", "i" }
local AV7i = { "A", "V", "7", "i" }
local AV7M = { "A", "V", "7", "M" }
local AV7u = { "A", "V", "7", "u" }
local AOou = { "A", "O", "o", "u" }
local QOou = { "Q", "O", "o", "u" }
-- [F2[secondaryR]][f1]
local _jv_X = { aEei, AEei, QOou }
local njv_X = { aEei, AV7i, QOou }
local hjvtX = { aEei, aEei, QOou }
local hjvkX = { AV7i, AV7i, QOou }
local _Gv_X = { AV7i, AV7M, QOou }
local rGv_X = { AEei, AV7M, QOou } -- not currently used
local hGv_X = { AV7M, AV7M, AV7M }
local _wv_X = { AV7u, AOou, QOou }
local rwv_X = { AOou, AOou, QOou }
local hwv_X = { AV7M, AOou, QOou }
local hwvtX = { AV7M, AV7M, QOou }
-- [F2[secondaryL]][F2[secondaryR]][f1]
local _Xv__ = { _jv_X, _Gv_X, _wv_X }
local nXv__ = { njv_X, _Gv_X, hwv_X }
local rXv__ = { _jv_X, _Gv_X, rwv_X }
local hXv__ = { _jv_X, hGv_X, hwv_X }
local hXvt_ = { hjvtX, hGv_X, hwvtX }
local hXvk_ = { hjvkX, hGv_X, _wv_X }
local hXvr_ = { hjvtX, hGv_X, hwv_X }
-- [primaryR][F2[secondaryL]][F2[secondaryR]][f1]
local __vX_ = {
["p"] = _Xv__, ["t"] = _Xv__, ["k"] = _Xv__,
["m"] = _Xv__, ["n"] = _Xv__, ["N"] = _Xv__,
["r"] = _Xv__, ["l"] = _Xv__
}
local n_vX_ = {
["p"] = nXv__, ["t"] = nXv__, ["k"] = nXv__,
["m"] = nXv__, ["n"] = nXv__, ["N"] = nXv__,
["r"] = nXv__, ["l"] = nXv__
}
local r_vX_ = {
["p"] = rXv__, ["t"] = rXv__, ["k"] = rXv__,
["m"] = rXv__, ["n"] = rXv__, ["N"] = rXv__,
["r"] = rXv__, ["l"] = _Xv__
}
local h_vX_ = {
["p"] = hXv__, ["t"] = hXvt_, ["k"] = hXvk_,
["m"] = hXv__, ["n"] = hXv__, ["N"] = hXvk_,
["r"] = hXvr_, ["l"] = hXv__
}
-- [primaryL][primaryR][F2[secondaryL]][F2[secondaryR]][f1]
VOWEL_REFLEX = {
["p"] = __vX_, ["t"] = __vX_, ["k"] = __vX_,
["m"] = __vX_, ["n"] = n_vX_, ["N"] = n_vX_,
["r"] = r_vX_, ["l"] = n_vX_, ["h"] = h_vX_
}
end
 
local CONSON_REFLEX
if true then
local map = {
["t"] = { ["j"] = "T" },
["n"] = { ["j"] = "J" },
["r"] = { ["j"] = "R" },
["l"] = { ["j"] = "L" }
}
for primary in mw.text.gsplit("ptkmnNrl", "") do
local map2 = map[primary]
if not map2 then
map2 = {}
map[primary] = map2
end
map2["j"] = map2["j"] or primary
map2["G"] = map2["G"] or primary
map2["w"] = map2["w"] or primary
end
map["T"] = map["t"]
map["J"] = map["n"]
map["R"] = map["r"]
map["L"] = map["l"]
CONSON_REFLEX = map
end
 
local VOICED_PRIMARY =
{ ["p"] = "b", ["t"] = "d", ["cT"] ="D", ["S"]="JZ", ["s"] = "z", ["k"] = "g" }
local VOICELESS_PRIMARY =
{ ["b"] = "p", ["d"] = "t", ["JD"] ="T", ["Z"]="cS", ["z"] = "s", ["g"] = "k" }
 
local PHONETIC_IPA
local function substDiphthong(
if true then
primaryL, secondaryL, vowel, epenth, primaryR, secondaryR
local map = {
)
["p"] = "p",
local f1 = F1[vowel]
["b"] = "b",
return (
["B"] = "β̞",
primaryL..secondaryL..
["t"] = "t",
VOWEL[f1][F2[secondaryL]]..epenth.."="..
["d"] = "d",
VOWEL[f1][F2[secondaryR]]..epenth..
["s"] = "s",
primaryR..secondaryR
["z"] = "z",
)
["k"] = "k",
["g"] = "ɡ",
["m"] = "m",
["n"] = "n",
["N"] = "ŋ",
["r"] = "r",
["l"] = "l",
["Hj"] = "j",
["HG"] = "ʔ",
["Hw"] = "w",
["_"] = "‿",
["j"] = "ʲ",
["G"] = "ˠ",
["w"] = "ʷ",
["a"] = "æ",
["E"] = "ɛ",
["e"] = "e",
["i"] = "i",
["A"] = "ɑ",
["V"] = "ʌ",
["7"] = "ɤ",
["M"] = "ɯ",
["Q"] = "ɒ",
["O"] = "ɔ",
["o"] = "o",
["u"] = "u",
["^"] = ASYLL,
["@"] = ASYLL,
["("] = "(",
[")"] = ")",
[":"] = "ː",
["="] = TIE2
}
if PHONETIC_DETAILS then
assign(map, {
["t"] = "t̪",
["T"] = "t̠",
["d"] = "d̪",
["D"] = "d̠",
["s"] = "s̠",
["z"] = "z̠",
["k"] = "k̠",
["g"] = "ɡ̠",
["n"] = "n̠",
["J"] = "n̪",
["N"] = "ŋ̠",
["r"] = "r̠",
["R"] = "r̪",
["l"] = "l̠",
["L"] = "l̪",
["a"] = "æ̝",
["E"] = "ɛ̝",
["E@"] = "e"..map["@"],
["E^"] = "e"..map["^"],
["Q"] = "ɒ̝",
["O"] = "ɔ̝",
["O@"] = "o"..map["@"],
["O^"] = "o"..map["^"]
})
end
map["T"] = map["T"] or map["t"]
map["D"] = map["D"] or map["d"]
map["S"] = map["S"] or (map["T"]..map["s"])
map["Z"] = map["Z"] or (map["D"]..map["z"])
map["kG"] = map["kG"] or map["k"]
map["gG"] = map["gG"] or map["g"]
map["J"] = map["J"] or map["n"]
map["NG"] = map["NG"] or map["N"]
map["R"] = map["R"] or map["r"]
map["L"] = map["L"] or map["l"]
map["Hj"] = map["Hj"] or map["i"]..map["^"]
local key
for primary in mw.text.gsplit("pbBtdTDSZszkgmnJNrRlL_", "") do
for secondary in mw.text.gsplit("jGw", "") do
key = primary..secondary
map[key] = map[key] or (map[primary]..map[secondary])
end
end
for vowel in mw.text.gsplit(V_, "") do
key = vowel.."@"
map[key] = map[key] or (map[vowel]..map["@"])
key = vowel.."^"
map[key] = map[key] or (map[vowel]..map["^"])
end
PHONETIC_IPA = map
end
 
local function toPhoneticRemainder(code, config, leftFlag, rightFlag)
local VOWEL_REFLEX
local PHONETIC_GLIDE
local PHONETIC_IPA
 
local function toPhoneticRemainder(code, config)
local text = code
local chars, subst
local diphthongs = config.diphthongs
-- If the phrase begins or ends with a bare vowel
-- and no pseudo-glide, display phrase threeup to five times
-- with each of the different pseudo-glides and possible vowel reflexes.
if IS_VOWEL[string_substring.sub(text, 1, 1)] then
text = "_j"..code
toPhoneticRemainder("_j"..text, config)
toPhoneticRemainder("_G"..text, config, false, rightFlag)
if not diphthongs then
toPhoneticRemainder("_w"..text, config)
toPhoneticRemainder(text, config, true, rightFlag)
end
text = "_G"..code
toPhoneticRemainder(text, config, false, rightFlag)
if not diphthongs then
toPhoneticRemainder(text, config, true, rightFlag)
end
text = "_w"..code
toPhoneticRemainder(text, config, false, rightFlag)
if not diphthongs then
toPhoneticRemainder(text, config, true, rightFlag)
end
return
end
if IS_VOWEL[string_substring.sub(text, -1)] then
toPhoneticRemainder(text = code.."_j", config)
toPhoneticRemainder(text.."_G", config, leftFlag, false)
if not diphthongs then
toPhoneticRemainder(text.."_w", config)
toPhoneticRemainder(text, config, leftFlag, true)
end
text = code.."_G"
toPhoneticRemainder(text, config, leftFlag, false)
if not diphthongs then
toPhoneticRemainder(text, config, leftFlag, true)
end
text = code.."_w"
toPhoneticRemainder(text, config, leftFlag, false)
if not diphthongs then
toPhoneticRemainder(text, config, leftFlag, true)
end
return
end
local diphthongs = config.diphthongs
local initialJ = config.initialJ
local medialJ = config.medialJ
local finalJ = config.finalJ
local geminateJ = config.geminateJ
local noHints = config.noHints
local outSeq = config.outSeq
local voice = config.voice
if initialJ == "x" or
-- Glides always trigger epenthesis, even neighboring other glides.
medialJ == "x" or
if not diphthongs then
finalJ == "x"
-- {ww} always causes the second glide to surface.
then
text = string_gsub(text, "([aEei])hw".."hw", "%1hw".."%1@".."Hw")
local subSeq = {}
config.outSeq = subSeq
if initialJ == "x" then
config.initialJ = "t"
end
if medialJ == "x" then
config.medialJ = "t"
end
if finalJ == "x" then
config.finalJ = "t"
end
toPhoneticRemainder(code, config)
if initialJ == "x" then
config.initialJ = "s"
end
if medialJ == "x" then
config.medialJ = "s"
end
if finalJ == "x" then
config.finalJ = "s"
end
toPhoneticRemainder(code, config)
addUnique(outSeq, table.concat(subSeq, " ~ "))
config.outSeq = outSeq
config.initialJ = initialJ
config.medialJ = medialJ
config.finalJ = finalJ
return
end
text = string_gsub(text, "([aEei])hG".."(.[jGw])", "%1hG".."%1@".."%2")
-- Glides always trigger epenthesis, even neighboring other glides.
text = string_gsub(text, "(.[jGw])".."hG([aEei])", "%1".."%2@".."hG%2")
text = string_gsubstring_gsub2(text, "([aEei])( *h)(.)".."(. *)(h)%3( *)([jGwaEei])", "%1h%2".."%1@".."%3")
function(vowelL, _, secondary, __, primaryR, ___, vowelR)
text = string_gsub(text, "(.[jGw])".."h(.)([aEei])", "%1".."%3@".."h%2%3")
if secondary == "w" then
text = string_gsub(text, "(.[jGw])".."([yY].)", "%1".."i@".."%2")
primaryR = "H"
end
return (
vowelL.._..secondary..
maxF1(vowelL, vowelR).."@"..
__..primaryR..secondary..___..vowelR
)
end
)
text = string.gsub(text, "([aEei])( *)hG( *.[jGw])", "%1%2hG%1@%3")
text = string.gsub(text, "(.[jGw])( *)hG( *)([aEei])", "%1%4@%2hG%3%4")
text = string.gsub(text, "([aEei])( *)h(.)( *.[jGw])", "%1%2h%3%1@%4")
text = string.gsub(text, "(.[jGw])( *)h(. *)([aEei])", "%1%4@%2h%3%4")
text = string.gsub(text, "(.[jGw])( *[yY].)", "%1i@%2")
-- Preserve these exceptionally stable clusters.
text = string_gsubstring.gsub(text, "l([jG] *)".."tG", "l%1|tG")
-- Unstable consonant clusters trigger epenthesis.
-- Liquids before coronal obstruents.
text = string_gsubstring.gsub(text, "([rl].)".."( *)t", "%1vt1v%2t")
-- Nasals and liquids after coronal obstruents.
text = string_gsubstring.gsub(text, "t(.)".."( *[nrl])", "t%1v%2")
-- Heterorganic clusters.
-- Labial consonants neighboring coronal or dorsal consonants.
text = string_gsubstring.gsub(text, "([pm].)".."( *[tnrlkN])", "%1v%2")
-- Coronal consonants neighboring labial or dorsal consonants.
text = string_gsubstring.gsub(text, "([tnrl].)".."( *[pmkN])", "%1v%2")
-- Dorsal consonants neighboring labial or coronal consonants.
text = string_gsubstring.gsub(text, "([kN].)".."( *[pmtnrl])", "%1v%2")
-- Organic speech involves certain consonant cluster assimilations.
Line 595 ⟶ 814:
-- Forward assimilation of rounded consonants.
-- There is no rounded coronal obstruent.
text = string_gsubstring.gsub(text, "(w *[^t])[jG]", "%1w")
-- Backward assimilation of remaining secondary articulations.
text = string_gsubstring.gsub(text, "[jGw]( *.)([jGw])", "%2%1%2")
-- Backward nasal assimilation of primary articulations.
text = string_gsubstring.gsub(text, "[pkrl](. *)([mnN])", "%2%1%2")
-- No longer need to protect exceptionally stable consonant clusters.
text = string_gsubstring.gsub(text, "|", "")
-- Give a vowel height to all epenthetic vowels that still lack one.
text = string_gsub2(text, "(.)( *..)v( *.. *)(.)",
function(vowelL, consonL, consonR, vowelR)
return vowelL..consonL..
maxF1(vowelL, vowelR, "E").."@"..
consonR..vowelR
end
)
-- Tag all vowels for next set of operations.
text = string_gsubstring.gsub(text, "([aEei])", "/%1")
-- There is no variation in the surface realizations of vowels
-- between two identical secondary articulations.
text = string_gsub2(text, "([jGw])( *)/([aEei])(@? *.)%1",
function(secondary, _, vowel, infix)
return (
secondary.._..VOWEL[F1[vowel]][F2[secondary]]..
infix..secondary
)
end
)
Line 626 ⟶ 850:
if diphthongs then
text = string_gsub2(text, "(.)([jGw])( *)/([aEei])(@?)( *)(.)([jGw])",
function(
"(.)([jGw])/([aEei])(@?)(.)([jGw])", substDiphthong)
primaryL, secondaryL, _, vowel, epenth, __, primaryR, secondaryR
)
local f1 = F1[vowel]
return (
primaryL..secondaryL.._..
VOWEL[f1][F2[secondaryL]]..epenth.."="..
VOWEL[f1][F2[secondaryR]]..epenth..__..
primaryR..secondaryR
)
end
)
else
-- Represent vowelsVowels neighboring pseudo-glides as diphthongs regardless.
textsubst = string_gsubfunction(text,
primaryL, secondaryL, _, vowel, epenth,
"(_)([jGw])/([aEei])(@?)(.)([jGw])", substDiphthong)
__, primaryR, secondaryR, flag
text = string_gsub(text,
)
"(.)([jGw])/([aEei])(@?)(_)([jGw])", substDiphthong)
local f2L = F2[secondaryL]
local f2R = F2[secondaryR]
if not VOWEL_REFLEX then
--local [f1]f2
if flag then
local aEei = { "a", "E", "e", "i" }
f2 = math.max(f2L, f2R)
local AEei = { "A", "E", "e", "i" }
else
local AV7i = { "A", "V", "7", "i" }
f2 = math.min(f2L, f2R)
local AV7M = { "A", "V", "7", "M" }
end
local AV7u = { "A", "V", "7", "u" }
return (
local AOou = { "A", "O", "o", "u" }
primaryL..secondaryL.._..
local QOou = { "Q", "O", "o", "u" }
-- VOWEL[F2F1[secondaryRvowel]][f1f2]..epenth..__..
primaryR..secondaryR
local _jv_X = { aEei, AEei, QOou }
)
local njv_X = { aEei, AV7i, QOou }
local _Gv_X = { AV7i, AV7M, QOou }
local hGv_X = { AV7M, AV7M, AV7M }
local _wv_X = { AV7u, AOou, QOou }
local hjvtX = { aEei, aEei, QOou }
local hwv_X = { AV7M, AOou, QOou }
local hwvtX = { AV7M, AV7u, QOou }
-- [F2[secondaryL]][F2[secondaryR]][f1]
local _Xv__ = { _jv_X, _Gv_X, _wv_X }
local nXv__ = { njv_X, _Gv_X, hwv_X }
local hXv__ = { _jv_X, hGv_X, hwv_X }
local hXvt_ = { hjvtX, hGv_X, hwvtX }
local hXvr_ = { hjvtX, hGv_X, hwv_X }
-- [primaryR][F2[secondaryL]][F2[secondaryR]][f1]
local __vX_ = {
["p"] = _Xv__, ["t"] = _Xv__, ["k"] = _Xv__,
["m"] = _Xv__, ["n"] = _Xv__, ["N"] = _Xv__,
["r"] = _Xv__, ["l"] = _Xv__
}
local n_vX_ = {
["p"] = nXv__, ["t"] = nXv__, ["k"] = nXv__,
["m"] = nXv__, ["n"] = nXv__, ["N"] = nXv__,
["r"] = nXv__, ["l"] = nXv__
}
local h_vX_ = {
["p"] = hXv__, ["t"] = hXvt_, ["k"] = hXv__,
["m"] = hXv__, ["n"] = hXv__, ["N"] = hXv__,
["r"] = hXvr_, ["l"] = hXv__
}
-- [primaryL][primaryR][F2[secondaryL]][F2[secondaryR]][f1]
VOWEL_REFLEX = {
["p"] = __vX_, ["t"] = __vX_, ["k"] = __vX_,
["m"] = __vX_, ["n"] = n_vX_, ["N"] = __vX_,
["r"] = __vX_, ["l"] = n_vX_, ["h"] = h_vX_
}
end
text = string.gsub(text, "(_)([jGw])( *)/("..V..")(@?)( *)(.)([jGw])",
function(a, b, c, d, e, f, g, h)
return subst(a, b, c, d, e, f, g, h, leftFlag)
end
)
text = string.gsub(text, "(.)([jGw])( *)/("..V..")(@?)( *)(_)([jGw])",
function(a, b, c, d, e, f, g, h)
return subst(a, b, c, d, e, f, g, h, rightFlag)
end
)
-- Vowels between two non-glides have the most predictable reflexes.
text = string_gsub2(text,
"([ptkmnNrl])(.)( *)/([aEei])(@? *)([ptkmnNrl])(.)",
function(
primaryL, secondaryL, _, vowel, epenthinfix, primaryR, secondaryR)
)
return primaryL..secondaryL..
return primaryL..secondaryL.._..
VOWEL_REFLEX[primaryL][primaryR]
[F2[secondaryL]][F2[secondaryR]][F1[vowel]]..
epenthinfix..primaryR..secondaryR
end
)
-- Exceptionally for the single word "rej".
text = string.gsub(text, "^(rG *)([V7])( *tj)$",
function(prefix, vowel, suffix)
return prefix..FRONT_VOWEL[vowel]..suffix
end
)
Line 697 ⟶ 918:
-- Vowels always claim the secondary articulation
-- of a neighboring back unrounded glide.
text = string_gsubstring.gsub(text, "(hG *)/([aEei])", function(prefix, vowel)
return "hG"prefix..BACK_VOWEL[vowel]
end)
text = string_gsubstring.gsub(text, "/([aEei])(@?) *hG)", function(vowel, epenthsuffix)
return BACK_VOWEL[vowel]..epenth.."hG"suffix
end)
-- Unless already claimed, epenthetic vowels after a glide
-- always claim the secondary articulation to the left.
text = string_gsubstring.gsub(text, "([hH])(.)( *)/([aEei])@",
function(primaryL, secondaryL, _, vowel)
return (
primaryL..secondaryL.._..
VOWEL[F1[vowel]][F2[secondaryL]].."@"
)
Line 717 ⟶ 938:
-- Unless already claimed, vowels before a glide
-- always claim the secondary articulation to the right.
text = string_gsubstring.gsub(text, "/([aEei])(@?)( *[hHyY])(.)",
function(vowel, epenth, primaryR, secondaryR)
return (
Line 728 ⟶ 949:
-- For now, unless already claimed, vowels before a rounded consonant
-- claim the secondary articulation to the right.
text = string_gsubstring.gsub(text, "/([aEei])(@? *.w)", function(vowel, suffix)
return ROUND_VOWEL[vowel]..suffix
end)
Line 734 ⟶ 955:
-- For now, unless already claimed, remaining vowels
-- claim the secondary articulation to the left.
text = string_gsubstring.gsub(text, "([jGw])( *)/([aEei])",
function(secondaryL, _, vowel)
return secondaryL.._..VOWEL[F1[vowel]][F2[secondaryL]]
end)
)
-- Vowels after {yi'y} and {'yiy}
-- claim the secondary articulation to the right.
subst = function(consonL, vowel, infix, secondaryR)
return consonL..VOWEL[F1[vowel]][F2[secondaryR]]..infix..secondaryR
end
text = string_gsub(text, "([yY].)([aEei])(@?.)([jGw])", subst)
-- Change certain vowels in a special environment from round to front.
text = string_gsubstring_gsub2(text, "([hyY]jhj *)([Oou])( *.w)( *"..V.." *h[jh])",
function(prefix, vowelLvowel, conson, vowelRsuffix)
return prefix..FRONT_VOWEL[vowel]..suffix
end
)
text = string.gsub(text, "(hj *)([Oou])( *)(.w)( *)("..V..")",
function(prefix, vowelL, _, conson, __, vowelR)
if conson ~= "hw" or F1[vowelL] ~= F1[vowelR] then
return prefix..FRONT_VOWEL[vowelL].._..conson..__..vowelR
end
end
)
text = string_gsubstring.gsub(text, "([hyY]jhj *)([Oou])( *.w *.w)",
function(prefix, vowel, suffix)
return prefix..FRONT_VOWEL[vowel]..suffix
end
)
text = string_gsubstring.gsub(text, "(a@? *hj *)Q( *.w *"..V..")", "%1a%2")
text = string_gsubstring.gsub(text, "(a@? *hj *)Q( *.w *.w)", "%1a%2")
-- Tag certain glide-vowel-non-glide sequences for special reflexes.
text = string_gsubstring.gsub(text, "(H[HyY][jw] *)("..V.." *[ptkmnNrl])", "%1/%2")
text = string_gsubstring.gsub(text, "^ *(h[jw] *)("..V.." *[ptkmnNrl])", "%1/%2")
text = string_gsubstring.gsub(text, "(@ *h[jw] *)("..V.." *[ptkmnNrl])", "%1/%2")
text = string_gsubstring.gsub(text,
"([EeiAV7MOou]@? *h[jw] *)([aAQ] *[ptkmnNrl])", "%1/%2")
text = string_gsubstring.gsub(text, "(hj[aEeiiMu]@?hw *hj *)("..V.."[ptkmnNrlEeV7] *[kN]G)", "%1/%2")
text = string.gsub(text,
"(hj *[aEei]@? *hw *)("..V.." *[ptkmnNrl])", "%1/%2")
-- Untag certain sequences, exempting them from special reflexes.
text = string_gsubstring.gsub(text, "(hj *)/([aEei] *[knNrl]w)", "hj%1%2")
-- Special reflexes.
text = string_gsubstring.gsub(text, "([jw])( *)/("..V..")( *)(.)([jGw])",
function(secondaryL, _, vowel, __, primaryR, secondaryR)
return (
secondaryL.._..
VOWEL_REFLEX["h"][primaryR]
[F2[secondaryL]][F2[secondaryR]][F1[vowel]]..
__..primaryR..secondaryR
)
end
)
-- Exceptional phrase-initial reflex.
text = string.gsub(text, "^ *([Hh]j *)([V7])( *[kN]G)",
function(prefix, vowel, suffix)
return prefix..FRONT_VOWEL[vowel]..suffix
end
)
text = string.gsub(text, "^ *([Hh]w *)M( *tG)", "%1u%2")
end
-- {yi'y}Temporarily neighboringcancel epenthetic {i} cancelsneighboring the epenthetic vowel{yi'y}.
text = string_gsubstring.gsub(text, "i@( *yj)", "yj%1")
-- {yi'y} neighboring non-epenthetic {i} may now be demoted to {y}.
text = string_gsubstring.gsub(text, "([iMu]@? *)yj", "%1hj")
text = string_gsubstring.gsub(text, "yj( *[iMu])", "hj%1")
-- {'yiy} may now be demoted everywhere.
text = string_gsubstring.gsub(text, "(i@ *)Yj", "i@hjihj%1hjihj")
text = string_gsubstring.gsub(text, "Yj", "hjihji@hj")
-- For the purposes of this template,
-- surface all glides pronounced in isolation.
text = string_gsubstring.gsub(text, "^ *h(.) *$", "H%1")
if not diphthongs then
-- Opportunistically front these vowels.
-- Surface realization of {yi'y}.
text = string_gsubstring.gsub(text, "yj",(hj *)([A7M])( *[kN]G *[kN]?G? *"i^..V..")",
function(prefix, vowel, suffix)
return prefix..FRONT_VOWEL[vowel]..suffix
-- Delete all remaining glides.
end
text = string_gsub(text, "[hH].", "")
)
else
-- Opportunistically front this vowel.
text = string_gsub(text, "([yh]j)A([kN]G[kN]?G?"..V..")", "%1a%2")
-- Surface certain glides.
text = string_gsubstring.gsub(text, "^ *h(w *[Oou])", "H%1")
text = string_gsubstring.gsub(text, "h(w *[aEeiAV7M])", "H%1")
text = string_gsubstring.gsub(text, "^ *h(j *[AV7MQOou])", "H%1")
text = string_gsubstring.gsub(text, "([ptkmnNrl].).@ *)h(jw *[AV7MQOouOou])", "%1H%2")
text = string_gsubstring.gsub(text, "([AV7MQOouptkmnNrl]..@? *)h(j[AV7MQOou] *"..V..")", "%1H%2")
text = string_gsubstring.gsub(text, "([aEeiAV7MAV7MQOou])(@? *)hwh(j *[QOouAV7MQOou])", "%1H%2")
text = string.gsub(text, "([aEeiAV7M])(@? *)hw( *)([QOou])",
function(vowelL, epenthL, vowelR)
function(vowelL, infix, _, vowelR)
if F1[vowelL] > F1[vowelR] then
return vowelL..epenthLinfix.."Hw".._..vowelR
end
end
)
text = string_gsubstring.gsub(text, "([AV7MQOou])(@? *)hj( *)([aEei])",
function(vowelL, epenthLinfix, _, vowelR)
if F1[vowelL] > F1[vowelR] then
return vowelL..epenthLinfix.."Hj".._..vowelR
end
end
)
text = string_gsubstring.gsub(text, "([aEei])(@? *)hj( *)([AV7MQOou])",
function(vowelL, epenthLinfix, _, vowelR)
if F1[vowelL] < F1[vowelR] then
return vowelL..epenthLinfix.."Hj".._..vowelR
end
end
)
text = string_gsubstring.gsub(text, "("..V..")( *)h([jw]) *$",
function(vowel, _, secondary)
if F2[vowel] ~= F2[secondary] then
return vowel.._.."H"..secondary
end
end
end)
-- Protect word-final epenthetic vowels after non-glides
-- from the next operation.
text = string.gsub(text, "([ptkmnNrl]."..V..")(@ )", "%1/%2")
-- De-epenthesize vowels if they still neighbor unsurfaced glides.
text = string_gsubstring.gsub(text, "("..V..")@( *h.)", "%1%2")
text = string_gsubstring.gsub(text, "(h. *"..V..")@", "%1")
-- Adjust F1 of currently remaining epenthetic vowels.
-- Surface realization for remaining glides and {yi'y},
text = string_gsub2(text,
-- except surfaced {y}.
"("..V..")( *.[jGw])(.)@( *.[jGw] *)("..V..")",
PHONETIC_GLIDE = PHONETIC_GLIDE or {
function(vowelL, infixL, vowel, infixR, vowelR)
-- Delete remaining unsurfaced glides.
["hj"] return = "",(
vowelL..infixL..
["hG"] = "",
VOWEL[F1[maxF1(vowelL, vowelR, "E")]][F2[vowel]].."/@"..
["hw"] = "",
infixR..vowelR
-- Simple realizations for surfaced {h}, {w} and {yi'y}.
)
["HG"] = "?",
end
["Hw"] = "W",
)
["yj"] = "i^"
}
text = string_gsubstring.gsub(text, "[yhH]./", PHONETIC_GLIDE"")
end
-- Delete all remaining unsurfaced glides.
text = string.gsub(text, "h.", "")
-- Surface realization for {yi'y}.
text = string.gsub(text, "yj", "i^")
if not diphthongs then
-- Realization for surfaced {y}.
text = string_gsub2(text, "("..V.."?)(@?)( *)Hj( *)("..V.."?)",
function(vowelL, epenthL, _, __, vowelR)
if vowelL ~= "" then
if vowelR ~= "" then
returnif vowelL (== vowelR and
F2[vowelL..epenthL..] == F2_FRONT
then
maxF1(vowelL, vowelR).."^"..vowelR
return vowelL.._..__..vowelR
)
else
return (
vowelL..epenthL.._..
maxF1(vowelL, vowelR, "E").."^"..__..vowelR
)
end
else
return vowelL.._..epenthL..maxF1(vowelL, "E").."^"..__
end
else
if vowelR ~= "" then
return _..maxF1(vowelR, "E").."^"..__..vowelR
else
return _.."i^"..__
end
end
Line 883 ⟶ 1,135:
)
-- AdjustFlatten this epenthetic vowel and surfaced glide.
text = string_gsubstring_gsub2(text, "([ptkmnNrlaAQ].[aEei])%^( *"..VC..")E@( *)E%^( *)a", "%1@1a%2%3a")
-- Collapse this epenthetic vowel and surfaced glide into a semi-vowel.
text = string.gsub(text, "([aEei])@( *)%1%^", "%2%1^")
end
if MERGED_VOWELS then
text = string.gsub(text, "[EO]", function(vowel)
return VOWEL[F1[vowel] + 1][F2[vowel]]
end)
end
Line 907 ⟶ 1,168:
index = index2
until index == 1
text = table_concattable.concat(chars, "")
end
-- Tweak remaining consonants, using offsets as a guide.
text = string_gsubstring.gsub(text, "()(.)([jGw])( *)([ptkmnNrl]?)([jGw]?)()",
function(
offsetL, primaryL, secondaryL, _, primaryR, secondaryR, offsetR)
)
local isInitial = offsetL == 1
local isFinal = offsetR == #chars + 1
if primaryL == "H" or
primaryL == "y"
then
return primaryL..secondaryL.._
end
if primaryL == "_" then
if noHints then
-- Delete pseudo-glide.
return ""_
end
elseif isInitial then
if isInitial then
-- Show secondary articulation to the left, not the right.
return secondaryL..primaryL.._
else
return primaryL..secondaryL
end
return primaryL..secondaryL.._
end
local geminated = primaryL == primaryR
if primaryR == "t" and
if primaryL ~= "t" and primaryR == "t" then
secondaryR == "j"
-- /tʲ/ is palatalized postalveolar.
then
-- /tˠ/ is velarized dental.
if primaryL == "t" and
-- /nʲ, rʲ, lʲ/ are palatalized dental.
secondaryL == "j"
-- /nˠ, rˠ, lˠ/ are velarized postalveolar.
then
-- Regressively assimilate primary dental or postalveolar.
primaryL = geminateJ
-- None of this will be visible unless PHONETIC_DETAILS == true.
primaryR = geminateJ
primaryL = CONSON_REFLEX[primaryL]
[secondaryL == "j" and "G" or "j"]
primaryR = CONSON_REFLEX[primaryR][secondaryR]
else
primaryL = CONSON_REFLEX[primaryL][secondaryL]
if primaryR ~= "" then
primaryR = CONSON_REFLEX[primaryR][secondaryR]
end
end
if primaryR == "T" then
if primaryL == "T" then
primaryL = finalJ
primaryR = initialJ
if primaryL == "S" and
primaryR ~= "s"
then
primaryL = "T"
elseif
primaryL == "T" and
primaryR == "s" and
medialJ == "S"
then
primaryL = "S"
end
else
primaryR = medialJ
end
elseif primaryL == "T" then
primaryL == "t" and
secondaryL == "j"
then
if isInitial then
primaryL = initialJ
Line 951 ⟶ 1,240:
if primaryR ~= "" then
-- Consonant cluster.
-- For some reason, the {t} in {lt} and {ļt} is voiceless.
if primaryL ~= primaryR and
if primaryLnot ~=geminated "l"and
primaryL ~= "l" and
primaryL ~= "L"
then
primaryL = VOICED_PRIMARY[primaryL] or primaryL
primaryR = VOICED_PRIMARY[primaryR] or primaryR
end
-- Display secondary articulation only once for the cluster.
if secondaryL == secondaryR then
if primaryLsecondaryL == primaryR then""
primaryR = ":"
secondaryR = ""
elseif primaryL ~= "l" then
secondaryL = ""
end
end
elseif
not isInitial and
Line 979 ⟶ 1,264:
primaryR = VOICED_PRIMARY[primaryR] or primaryR
end
return primaryL..secondaryL.._..primaryR..secondaryR
end
)
if not PHONETIC_IPAdiphthongs then
local map = {
-- Elegantly connect long and epenthetic vowels across word gaps.
["p"] = "p",
text = string.gsub(text, "(["..V_..":]): +", "%1 : ")
["b"] = "b",
text = string.gsub(text, "("..V..") +%1([^%^])", "%1 :%2")
["t"] = "t",
text = string.gsub(text, "("..V..") +%1$", "%1 :")
["d"] = "d",
text = string.gsub(text, "("..V..")@ +%1", " %1 :")
["s"] = "s",
text = string.gsub(text, "("..V.."@) +", " %1 ")
["z"] = "z",
["k"] = "k",
if W_OFF_GLIDES then
["g"] = "ɡ",
-- Add [w] off-glides after certain consonants.
["m"] = "m",
subst = function(primary, _, epenth)
["n"] = "n",
["N"] if epenth == "ŋ", then
["r"] = return primary.."rHw",.._
end
["l"] = "l",
["?"] = "ʔ",
["W"] = "w",
["_"] = "‿",
["j"] = "ʲ",
["G"] = "ˠ",
["w"] = "ʷ",
["a"] = "æ",
["E"] = "ɛ",
["e"] = "e",
["i"] = "i",
["A"] = "ɑ",
["V"] = "ʌ",
["7"] = "ɤ",
["M"] = "ɯ",
["Q"] = "ɒ",
["O"] = "ɔ",
["o"] = "o",
["u"] = "u",
["^"] = ASYLL,
["@"] = BREVE,
[":"] = "ː",
["="] = TIE2
}
map["c"] = map["c"] or (map["t"]..TIE..map["s"])
map["J"] = map["J"] or (map["d"]..TIE..map["z"])
map["kG"] = map["kG"] or map["k"]
map["gG"] = map["gG"] or map["g"]
map["NG"] = map["NG"] or map["N"]
for primary in mw_text_gsplit("pbtdcJszkgmnNrl_", "") do
for secondary in mw_text_gsplit("jGw", "") do
local key = primary..secondary
map[key] = map[key] or (map[primary]..map[secondary])
end
if false and PHONETIC_DETAILS then
text = string.gsub(text, "([pbm])(G *[aEei])(@?)",
function(primary, _, epenth)
if epenth == "" then
return primary.."B".._
end
end
)
else
text = string.gsub(text, "([pbm])G( *[aEei])(@?)", subst)
end
text = string.gsub(text, "([kgnNrl])w( *[aEeiAV7M])(@?)", subst)
-- Remove [w] off-glides after certain consonants
-- when they occur after rounded vowels.
text = string.gsub(text, "([QOou] *[nrl]? *[nrl])Hw", "%1w")
text = string.gsub(text, "([QOou] *[kgN]? *N)Hw( *M)", "%1w%2")
end
PHONETIC_IPA = map
end
text = string_gsub(text, ".[jGw]?", PHONETIC_IPA)
if PARENTHETICAL_EPENTHESIS then
addUnique(config.outSeq, text)
if not diphthongs then
text = string.gsub(text, "(.)@("..V..")", "%1^%2")
end
text = string.gsub(text, "(.)@", "(%1)")
text = string.gsub(text, "%)(=?)%(", "%1")
if not diphthongs and W_OFF_GLIDES then
if false and PHONETIC_DETAILS then
text = string.gsub(text, "([pbm]G%()([aEei])", "%1BG%2")
else
text = string.gsub(text, "([pbm]G%()([aEei])", "%1Hw%2")
end
text = string.gsub(text, "([kgnNrl]w%()([aEeiAV7M])", "%1Hw%2")
text = string.gsub(text, "([QOou] *[nrl]w%()Hw", "%1")
text = string.gsub(text, "([QOou] *Nw%()HwM", "%1M")
end
end
-- Convert remaining word gaps to liaison.
text = fastTrim(text)
text = string.gsub(text, " +", false and "_" or "")
text = string.gsub(text, ".[jGw@%^]?", PHONETIC_IPA)
addUnique(outSeq, text)
end
Line 1,042 ⟶ 1,334:
 
 
local PHONETIC_ARG_J = { ["t"] = "T", ["c"] = "S", ["s"] = "s", ["x"] = "x" }
 
local function toPhonetic(inSeq, args)
Line 1,050 ⟶ 1,342:
-- For other values, list both possible dialect reflexes where applicable.
local dialect = args and args.dialect and
mw_ustring_lowermw.ustring.lower(mw_text_trimmw.text.trim(args.dialect)) or ""
if dialect == "rālik" then
dialect = "ralik"
Line 1,058 ⟶ 1,350:
local diphthongs = not not (args and parseBoolean(args.diphthongs))
-- Argument "J" has format like "tstttst".
-- Recognized letters are "t" = plosive, "c" = affricate, "s" = fricative.
-- Letters for initial, medial, final and geminatefinal respectively.
-- Real-world pronunciation said to vary by sociological factors,
-- but all realizations may occur in free variation.
local modeJ = splitChars(args and args.J and string.lower(args.J) or "tst")
PHONETIC_ARG_J = PHONETIC_ARG_J or { ["t"] = "t", ["c"] = "c", ["s"] = "s" }
local modeJ = splitChars(args and args.J and string_lower(args.J) or "tstt")
local initialJ = PHONETIC_ARG_J[modeJ[1] or ""] or "t"
local medialJ = PHONETIC_ARG_J[modeJ[2] or ""] or "s"
local finalJ = PHONETIC_ARG_J[modeJ[3] or ""] or initialJ
local geminateJ = PHONETIC_ARG_J[modeJ[4] or ""] or initialJ
-- If enabled, do not display pseudo-glide hints at all.
Line 1,089 ⟶ 1,379:
["medialJ"] = medialJ,
["finalJ"] = finalJ,
["geminateJ"] = geminateJ,
["noHints"] = noHints,
["voice"] = voice
Line 1,095 ⟶ 1,384:
for _, str in pairs(inSeq) do
str = string_gsubstring.gsub(str, S, " ")
str = string.gsub(str, "^ *", "")
str = string.gsub(str, " *$", "")
local isRalik = dialect == "ralik"
if isRalik or dialect == "ratak" then
Line 1,124 ⟶ 1,415:
 
function export.bender(frame)
return table_concattable.concat(toBender(parse(frame.args[1], frame.args)), ", ")
end
 
function export.MOD(frame)
return toMOD(frame.args[1], frame.args)
end
 
function export.parse(frame)
return table_concattable.concat(parse(frame.args[1]), ", ")
end
 
function export.phonemic(frame)
return table_concattable.concat(toPhonemic(parse(frame.args[1])), ", ")
end
 
function export.phonetic(frame)
return table_concattable.concat(toPhonetic(parse(frame.args[1]), frame.args), ", ")
end