Content deleted Content added
Please don't overwrite my changes to this module without even leaving an edit summary |
[w] off-glide tweak |
||
(9 intermediate revisions by the same user 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 MERGED_VOWELS = false
local PARENTHETICAL_EPENTHESIS = true
local PHONETIC_DETAILS = false
local W_OFF_GLIDES = true
local ASYLL = "̯"
Line 18 ⟶ 20:
local C1_ = "pbtdSZszkgmnNrlyYhH_"
local C1 = "["..C1_.."]"
local
local C = ".["..C2_.."]"
local V_ = "aEeiAV7MQOou"
local V = "["..V_.."]"
Line 29 ⟶ 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 38 ⟶ 42:
end
-- Intended to work the same as JavaScript's Object.assign() function.
local function assign(target, ...)
local args = { ... }
Line 51 ⟶ 56:
local function fastTrim(text)
return string.match(text, "^%s*(.-)%s*$")
end
Line 135 ⟶ 124:
local PARSE_PSEUDO_GLIDE = {
["y"] = "0",
["h"] = "0h",
["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)
Line 155 ⟶ 188:
-- Recognize "y_", "h_", "w_", "_y", "_h", "_w" as pseudo-glides.
text = string.gsub(text, "_*([hwy])_+", PARSE_PSEUDO_GLIDE)
text = string.gsub(text, "_+([hwy])", PARSE_PSEUDO_GLIDE)
Line 179 ⟶ 209:
-- Convert multigraphs to pseudo-X-SAMPA format.
text = string.gsub(text, "[klmnr0]g?[hw]?", PARSE_C_CH_CW)
if string.find(text, "g") then
Line 208 ⟶ 215:
-- Convert remaining sequences to pseudo-X-SAMPA format.
text = string.gsub(text, ".", PARSE_REMAINING)
Line 282 ⟶ 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 296 ⟶ 286:
["lG"] = "ļ",
["lw"] = "ļ°",
["e"] = "ȩ"
})
local BENDER_MOD = assign({}, BENDER_MED, {
Line 307 ⟶ 297:
["lG"] = "ḷ",
["lw"] = "ḷʷ",
["e"] = "ẹ"
})
local BENDER_DEFAULT = assign({}, BENDER_MOD, {
Line 315 ⟶ 305:
["lG"] = "ļ",
["lw"] = "ļʷ",
["e"] = "ȩ"
})
local BENDER_MAPS = {
["1968"] = BENDER_1968,
["med"] = BENDER_MED,
["mod"] = BENDER_MOD
}
Line 369 ⟶ 359:
["hj"] = "j", ["hG"] = "ɰ", ["hw"] = "w",
["_j"] = "", ["_G"] = "", ["_w"] = "",
["a"] = "æ",
["E"] = "ɛ",
["e"] = "e",
["i"] = "i",
["I"] = "i"
}
if false then
Line 411 ⟶ 401:
local F2_BACK = 2
local F2_ROUND = 3
local F2 = {
["j"] = F2_FRONT, ["G"] = F2_BACK, ["w"] = F2_ROUND } local FRONT_VOWEL = {}
Line 430 ⟶ 424:
end
local function maxF1(a, b, c)
if
return VOWEL[math.max(
elseif b then
return VOWEL[math.max(F1[a], F1[b])][F2_FRONT]
else
return
end
end
Line 451 ⟶ 447:
else
if isRalik then
return "hj"..maxF1(vowel, "E")..conson.._..conson..__..vowel
else
return conson..maxF1(vowel, "E").._..conson..__..vowel
end
end
Line 513 ⟶ 509:
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
Line 519 ⟶ 516:
local rwv_X = { AOou, AOou, QOou }
local hwv_X = { AV7M, AOou, QOou }
local hwvtX = { AV7M,
-- [F2[secondaryL]][F2[secondaryR]][f1]
local _Xv__ = { _jv_X, _Gv_X, _wv_X }
Line 526 ⟶ 523:
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]
Line 544 ⟶ 542:
}
local h_vX_ = {
["p"] = hXv__, ["t"] = hXvt_, ["k"] =
["m"] = hXv__, ["n"] = hXv__, ["N"] =
["r"] = hXvr_, ["l"] = hXv__
}
Line 603 ⟶ 601:
["r"] = "r",
["l"] = "l",
["Hj"] = "j",
["HG"] = "ʔ",
["Hw"] = "w",
Line 771 ⟶ 770:
-- Glides always trigger epenthesis, even neighboring other glides.
text = string_gsub2(text, "([aEei])( *h)(.)( *)(h)%3( *)([aEei])",
function(vowelL, _, secondary, __, primaryR, ___, vowelR)
if secondary == "w" then
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")
Line 821 ⟶ 828:
text = string_gsub2(text, "(.)( *..)v( *.. *)(.)",
function(vowelL, consonL, consonR, vowelR)
return vowelL..consonL..
maxF1(vowelL, vowelR, "E").."@".. consonR..vowelR end
)
Line 832 ⟶ 841:
text = string_gsub2(text, "([jGw])( *)/([aEei])(@? *.)%1",
function(secondary, _, vowel, infix)
return (
secondary.._..VOWEL[F1[vowel]][F2[secondary]].. infix..secondary
)
end
)
Line 839 ⟶ 850:
if diphthongs then
text = string_gsub2(text, "(.)([jGw])( *)/([aEei])(@?)( *)(.)([jGw])",
function(
primaryL, secondaryL, _, vowel, epenth, __, primaryR, secondaryR
Line 950 ⟶ 960:
end
)
-- Change certain vowels in a special environment from round to front.
text =
function(prefix,
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.gsub(text, "(
function(prefix, vowel, suffix)
return prefix..FRONT_VOWEL[vowel]..suffix
Line 975 ⟶ 983:
-- Tag certain glide-vowel-non-glide sequences for special reflexes.
text = string.gsub(text, "(
text = string.gsub(text, "^ *(h[jw] *)("..V.." *[ptkmnNrl])", "%1/%2")
text = string.gsub(text, "(@ *h[jw] *)("..V.." *[ptkmnNrl])", "%1/%2")
text = string.gsub(text,
"([EeiAV7MOou]
text = string.gsub(text, "([iMu] *hj *)([EeV7] *[kN]G)", "%1/%2")
text = string.gsub(text,
"(hj *[aEei]@? *hw *)("..V.." *[ptkmnNrl])", "%1/%2")
Line 989 ⟶ 998:
text = string.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
Line 1,013 ⟶ 1,032:
if not diphthongs then
-- Opportunistically front
text = string.gsub(text, "(hj *)([A7M])( *[kN]G *[kN]?G? *"..V..")",
function(prefix, vowel, suffix)
return prefix..FRONT_VOWEL[vowel]..suffix
end
)
-- Surface certain glides.
Line 1,022 ⟶ 1,044:
text = string.gsub(text, "^ *h(j *[AV7MQOou])", "H%1")
text = string.gsub(text, "([ptkmnNrl]..@ *)h(w *[Oou])", "%1H%2")
text = string.gsub(text, "([ptkmnNrl]..@ *)h(j *"..V..")", "%1H%2")
text = string.gsub(text, "([AV7MQOou]@? *)h(j *[AV7MQOou])", "%1H%2")
text = string.gsub(text, "([aEeiAV7M])(@? *)hw( *)([QOou])",
Line 1,055 ⟶ 1,076:
-- Protect word-final epenthetic vowels after non-glides
-- from the next operation.
text = string.gsub(text, "([ptkmnNrl]
-- De-epenthesize vowels if they still neighbor unsurfaced glides.
Line 1,066 ⟶ 1,087:
"("..V..")( *.[jGw])(.)@( *.[jGw] *)("..V..")",
function(vowelL, infixL, vowel, infixR, vowelR)
return (
vowelL..infixL.. VOWEL[F1[maxF1(vowelL, vowelR, "E")]][F2[vowel]].."/@"..
infixR..vowelR
)
end
)
Line 1,089 ⟶ 1,112:
if vowelL ~= "" then
if vowelR ~= "" then
F2[vowelL
then
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^"..__
Line 1,106 ⟶ 1,135:
)
--
text =
-- Collapse this epenthetic vowel and surfaced glide into a semi-vowel.
text = string.gsub(text, "([aEei])@( *)%1%^", "%2%1^")
end
Line 1,246 ⟶ 1,278:
if W_OFF_GLIDES then
-- Add [
subst = function(primary, _, epenth)
if epenth == "" then
Line 1,263 ⟶ 1,295:
text = string.gsub(text, "([pbm])G( *[aEei])(@?)", subst)
end
text = string.gsub(text, "([
-- 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, "(
end
end
if
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 =
text = string.gsub(text, " +", false and "_" or "")
|