Module:nan-pron: difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
Justinrleung (talk | contribs) No edit summary |
No edit summary |
||
Line 545: | Line 545: | ||
["Quanzhou"] = { |
["Quanzhou"] = { |
||
["1"] = "1", ["2"] = " |
["1"] = "1", ["2"] = "4", ["3"] = "2", ["4A"] = "8A", ["4B"] = "4B", |
||
["5"] = "6", ["6"] = "6", ["7"] = "6", ["8A"] = "6", ["8B"] = "6", |
["5"] = "6", ["6"] = "6", ["7"] = "6", ["8A"] = "6", ["8B"] = "6", |
||
["3d"] = "1", ["4Bd"] = "1", ["5d"] = "7", ["7d"] = "7", ["8Bd"] = "7", |
["3d"] = "1", ["4Bd"] = "1", ["5d"] = "7", ["7d"] = "7", ["8Bd"] = "7", |
Revision as of 16:45, 20 June 2016
- The following documentation is located at Module:nan-pron/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox (diff)
This module does romanisation conversion, IPA conversion, etc. for Min Nan. See {{zh-pron}}
.
local export = {}
local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local match = mw.ustring.match
local len = mw.ustring.len
local psdb_initial = {
["p"] = "'p", ["ph"] = "ph", ["b"] = "'b",
["t"] = "'d", ["th"] = "'t",
["k"] = "'k", ["kh"] = "'q", ["g"] = "'g",
["chi"] = "c", ["ch"] = "z",
["chhi"] = "ch", ["chh"] = "zh",
["si"] = "s", ["s"] = "s",
["j"] = "j",
["l"] = "l", ["h"] = "'h",
["m"] = "m", ["n"] = "n", ["ng"] = "ng",
[""] = "'"
}
local function psdb_final(text)
local basic_psdb = {
--single vowel tone 12357
["a1"] = "af", ["a2"] = "ar", ["a3"] = "ax", ["a5"] = "aa", ["a7"] = "a",
["i1"] = "y", ["i2"] = "ie", ["i3"] = "ix", ["i5"] = "ii", ["i7"] = "i",
["u1"] = "w", ["u2"] = "uo", ["u3"] = "ux", ["u5"] = "uu", ["u7"] = "u",
["e1"] = "ef", ["e2"] = "ea", ["e3"] = "ex", ["e5"] = "ee", ["e7"] = "e",
["oo1"] = "of", ["oo2"] = "or", ["oo3"] = "ox", ["oo5"] = "oo", ["oo7"] = "o",
["o1"] = "oy", ["o2"] = "oir", ["o3"] = "oix", ["o5"] = "ooi", ["o7"] = "oi",
["ng1"] = "'ngf", ["ng2"] = "'ngr", ["ng3"] = "'ngx", ["ng5"] = "'ngg", ["ng7"] = "'ng",
["m1"] = "'mf", ["m2"] = "'mr", ["m3"] = "'mx", ["m5"] = "'mm", ["m7"] = "'m",
--double vowel tone 12357
["ai1"] = "ay", ["ai2"] = "ae", ["ai3"] = "aix", ["ai5"] = "aai", ["ai7"] = "ai",
["au1"] = "aw", ["au2"] = "ao", ["au3"] = "aux", ["au5"] = "aau", ["au7"] = "au",
["ia1"] = "iaf", ["ia2"] = "iar", ["ia3"] = "iax", ["ia5"] = "iaa", ["ia7"] = "ia",
["iau1"] = "iaw", ["iau2"] = "iao", ["iau3"] = "iaux", ["iau5"] = "iaau", ["iau7"] = "iau",
["io1"] = "ioy", ["io2"] = "ioir", ["io3"] = "ioix", ["io5"] = "iooi", ["io7"] = "ioi",
["iu1"] = "iw", ["iu2"] = "iuo", ["iu3"] = "iux", ["iu5"] = "iuu", ["iu7"] = "iu",
["oa1"] = "oaf", ["oa2"] = "oar", ["oa3"] = "oax", ["oa5"] = "oaa", ["oa7"] = "oa",
["oai1"] = "oay", ["oai2"] = "oae", ["oai3"] = "oaix", ["oai5"] = "oaai", ["oai7"] = "oai",
["oe1"] = "oef", ["oe2"] = "oea", ["oe3"] = "oex", ["oe5"] = "oee", ["oe7"] = "oe",
["ui1"] = "uy", ["ui2"] = "uie", ["ui3"] = "uix", ["ui5"] = "uii", ["ui7"] = "ui",
--nasal vowel tone 12357
--nasal ending tone 12357
["ian1"] = "iefn", ["ian2"] = "iern", ["ian3"] = "iexn", ["ian5"] = "ieen", ["ian7"] = "ien",
["iong1"] = "iofng", ["iong2"] = "iorng", ["iong3"] = "ioxng", ["iong5"] = "ioong", ["iong7"] = "iong",
--stopped single vowel tone 48
["op4"] = "ob", ["op8"] = "op",
["ot4"] = "od", ["ot8"] = "ot",
["ok4"] = "og", ["ok8"] = "ok",
--stopped double vowel tone 48
["iop4"] = "iob", ["iop8"] = "iop",
["iot4"] = "iod", ["iot8"] = "iot",
["iok4"] = "iog", ["iok8"] = "iok",
}
text = gsub(text, "[一二三四五六七八]", {["一"] = "1", ["二"] = "2", ["三"] = "3", ["四"] = "4", ["五"] = "5", ["六"] = "6", ["七"] = "7", ["八"] = "8"})
if match(text, "ⁿ[12357]$") then
local basic = gsub(text, "ⁿ", "")
basic = gsub(basic, "^o([12357])$", "oo%1")
if basic_psdb[basic] then
return "v" .. basic_psdb[basic]
end
elseif match(text, ".[mn]g?[12357]$") and not match(text, "^ian[12357]$") and not match(text, "^iong[12357]$") then
local basic = gsub(text, "[mn]g?([12357])$", "%1")
local ending = match(text, "([mn]g?)[12357]$")
basic = gsub(basic, "^o([12357])$", "oo%1")
if basic_psdb[basic] then
return basic_psdb[basic] .. ending
end
elseif match(text, "[ptkh]ⁿ?4$") and not match(text, "^i?o[ptk]4$") then
local basic = gsub(text, "[ptkh](ⁿ?)4$", "%1") .. "7"
local ending = match(text, "([ptkh])ⁿ?4$")
ending = gsub(ending, "[ptkh]",{p = "b", t = "d", k = "g", h = "q"})
if match(basic, "ⁿ") then
basic = gsub(basic, "ⁿ", "")
basic = gsub(basic, "^o([12357])$", "oo%1")
if basic_psdb[basic] then
return "v" .. basic_psdb[basic] .. ending
end
else
if basic_psdb[basic] then
return basic_psdb[basic] .. ending
end
end
elseif match(text, "[ptkh]ⁿ?8$") and not match(text, "^i?o[ptk]8$") then
local basic = gsub(text, "[ptkh](ⁿ?)8$", "%1") .. "7"
local ending = match(text, "([ptkh])ⁿ?8$")
if match(basic, "ⁿ") then
basic = gsub(basic, "ⁿ", "")
basic = gsub(basic, "^o([12357])$", "oo%1")
if basic_psdb[basic] then
return "v" .. basic_psdb[basic] .. ending
end
else
if basic_psdb[basic] then
return basic_psdb[basic] .. ending
end
end
else
return basic_psdb[text]
end
end
function export.poj_check_invalid(text)
text = text .. "-"
local correct = text
correct = gsub(correct, "o[áàâāéèêē][-/ ]", function (a)
return gsub(a, "o[áàâāéèêē]", {
["oá"] = "óa", ["oà"] = "òa", ["oâ"] = "ôa", ["oā"] = "ōa",
["oé"] = "óe", ["oè"] = "òe", ["oê"] = "ôe", ["oē"] = "ōe",
})
end
)
correct = gsub(correct, "[óòôō][ae][mnptkh]g?", function (a)
return gsub(a, "[óòôō][ae]", {
["óa"] = "oá", ["òa"] = "oà", ["ôa"] = "oâ", ["ōa"] = "oā",
["óe"] = "oé", ["òe"] = "oè", ["ôe"] = "oê", ["ōe"] = "oē",
})
end
)
correct = gsub(correct, "o̍[ae]", {["o̍a"] = "oa̍", ["o̍e"] = "oe̍"})
correct = gsub(correct, "([oóòôō])[o·]", "%1͘")
correct = gsub(correct, "-$", "")
if match(text, "[óòôō][ae][mnptkh]g?") then
error("invalid poj \"" .. gsub(text, "-$", "") .. "\": correct poj is \"" .. correct .. "\"")
end
if match(text, "o[áàâāéèêē][-/ ]") then
error("invalid poj \"" .. gsub(text, "-$", "") .. "\": correct poj is \"" .. correct .. "\"")
end
if match(text, "o̍[ae]") then
error("invalid poj \"" .. gsub(text, "-$", "") .. "\": correct poj is \"" .. correct .. "\"")
end
if match(text, "([oóòôō])[o·]") then
error("invalid poj \"" .. gsub(text, "-$", "") .. "\": correct poj is \"" .. correct .. "\"")
end
return gsub(text, "-$", "")
end
function export.poj_to_tl_conv(text)
if type(text) == "table" then text = text.args[1] end
text = gsub(text, "仔", "á")
text = gsub(text, "%(([^%)]+)%)", "%1-%1-%1")
text = gsub(text, "e̍?k",{["e̍k"] = "i̍k", ["ek"] = "ik"})
text = gsub(text, "[eéèêēě]ng",{["eng"] = "ing", ["éng"] = "íng", ["èng"] = "ìng", ["êng"] = "îng", ["ēng"] = "īng", ["ěng"] = "ǐng"})
text = gsub(text, "o([ae])̍", "o%1̍")
text = gsub(text, "[oóòôōǒ][ae]",{["oa"] = "ua", ["óa"] = "uá", ["òa"] = "uà", ["ôa"] = "uâ", ["ōa"] = "uā", ["ǒa"] = "uǎ", ["oe"] = "ue", ["óe"] = "ué", ["òe"] = "uè", ["ôe"] = "uê", ["ōe"] = "uē", ["ǒe"] = "uě"})
text = gsub(text, "o([áàâāǎéèêēě])", "u%1")
text = gsub(text, "[úùûūǔ]i",{["úi"] = "uí", ["ùi"] = "uì", ["ûi"] = "uî", ["ūi"] = "uī", ["ǔi"] = "uǐ"})
text = gsub(text, "([oóòôōǒOÓÒÔŌǑ]̍?)͘", "%1o")
text = string.gsub(text, "u̍i", "ui̍")
text = string.gsub(text, "(h?)ⁿ", "nn%1")
text = string.gsub(text, "[Cc]h",{["ch"] = "ts", ["Ch"] = "Ts"})
text = gsub(text,'/([^ ])',' / %1')
return text
end
function export.poj_check_syllable(initial, final, loc)
local validInitials = {
["Quanzhou"] = {
["p"] = 1, ["ph"] = 1, ["m"] = 1, ["b"] = 1,
["t"] = 1, ["th"] = 1, ["n"] = 1, ["l"] = 1,
["ch"] = 1, ["chh"] = 1, ["s"] = 1,
["k"] = 1, ["kh"] = 1, ["ng"] = 1, ["g"] = 1, ["h"] = 1, [""] = 1,
},
["Xiamen"] = {
["p"] = 1, ["ph"] = 1, ["m"] = 1, ["b"] = 1,
["t"] = 1, ["th"] = 1, ["n"] = 1, ["l"] = 1,
["ch"] = 1, ["chh"] = 1, ["s"] = 1,
["k"] = 1, ["kh"] = 1, ["ng"] = 1, ["g"] = 1, ["h"] = 1, [""] = 1,
},
["Zhangzhou"] = {
["p"] = 1, ["ph"] = 1, ["m"] = 1, ["b"] = 1,
["t"] = 1, ["th"] = 1, ["n"] = 1, ["l"] = 1,
["ch"] = 1, ["chh"] = 1, ["j"] = 1, ["s"] = 1,
["k"] = 1, ["kh"] = 1, ["ng"] = 1, ["g"] = 1, ["h"] = 1, [""] = 1,
},
["Taipei"] = {
["p"] = 1, ["ph"] = 1, ["m"] = 1, ["b"] = 1,
["t"] = 1, ["th"] = 1, ["n"] = 1, ["l"] = 1,
["ch"] = 1, ["chh"] = 1, ["s"] = 1,
["k"] = 1, ["kh"] = 1, ["ng"] = 1, ["g"] = 1, ["h"] = 1, [""] = 1,
},
["Kaohsiung"] = {
["p"] = 1, ["ph"] = 1, ["m"] = 1, ["b"] = 1,
["t"] = 1, ["th"] = 1, ["n"] = 1, ["l"] = 1,
["ch"] = 1, ["chh"] = 1, ["j"] = 1, ["s"] = 1,
["k"] = 1, ["kh"] = 1, ["ng"] = 1, ["g"] = 1, ["h"] = 1, [""] = 1,
}
}
local validFinals = {
["Quanzhou"] = {
["a"] = 1, ["ah"] = 1, ["ahⁿ"] = 1, ["ai"] = 1, ["aih"] = 1, ["aiⁿ"] = 1, ["ak"] = 1,
["am"] = 1, ["an"] = 1, ["aⁿ"] = 1, ["ang"] = 1, ["ap"] = 1, ["at"] = 1,
["au"] = 1, ["auh"] = 1, ["auhⁿ"] = 1, ["auⁿ"] = 1, ["e"] = 1, ["eh"] = 1,
["eng"] = 1, ["er"] = 1, ["erh"] = 1, ["erm"] = 1, ["i"] = 1, ["ia"] = 1,
["iah"] = 1, ["iahⁿ"] = 1, ["iak"] = 1, ["iam"] = 1, ["ian"] = 1, ["iaⁿ"] = 1, ["iang"] = 1,
["iap"] = 1, ["iat"] = 1, ["iau"] = 1, ["iauh"] = 1, ["iauhⁿ"] = 1, ["iauⁿ"] = 1,
["ih"] = 1, ["ihⁿ"] = 1, ["im"] = 1, ["in"] = 1, ["iⁿ"] = 1, ["io"] = 1,
["ioh"] = 1, ["iok"] = 1, ["iong"] = 1, ["ip"] = 1, ["ir"] = 1, ["it"] = 1,
["iu"] = 1, ["iuh"] = 1, ["iuⁿ"] = 1, ["m"] = 1, ["mh"] = 1, ["ng"] = 1,
["ngh"] = 1, ["o"] = 1, ["o͘"] = 1, ["oa"] = 1, ["oah"] = 1, ["oai"] = 1,
["oaihⁿ"] = 1, ["oan"] = 1,["oaⁿ"] = 1, ["oang"] = 1, ["oat"] = 1, ["oe"] = 1,
["oeh"] = 1, ["oh"] = 1, ["o͘h"] = 1, ["ohⁿ"] = 1, ["ok"] = 1, ["oⁿ"] = 1,
["ong"] = 1, ["u"] = 1, ["uh"] = 1, ["ui"] = 1, ["uih"] = 1, ["uiⁿ"] = 1,
["un"] = 1, ["ut"] = 1,
},
["Xiamen"] = {
["a"] = 1, ["ah"] = 1, ["ahⁿ"] = 1, ["ai"] = 1, ["aih"] = 1, ["aiⁿ"] = 1, ["ak"] = 1,
["am"] = 1, ["an"] = 1, ["aⁿ"] = 1, ["ang"] = 1, ["ap"] = 1, ["at"] = 1, ["au"] = 1,
["auh"] = 1, ["auhⁿ"] = 1, ["auⁿ"] = 1, ["e"] = 1, ["eh"] = 1, ["ehⁿ"] = 1,
["ek"] = 1, ["eⁿ"] = 1, ["eng"] = 1, ["i"] = 1, ["ia"] = 1, ["iah"] = 1,
["iahⁿ"] = 1, ["iak"] = 1, ["iam"] = 1, ["ian"] = 1, ["iaⁿ"] = 1, ["iang"] = 1,
["iap"] = 1, ["iat"] = 1, ["iau"] = 1, ["iauh"] = 1, ["iauhⁿ"] = 1,
["iauⁿ"] = 1, ["ih"] = 1, ["ihⁿ"] = 1, ["im"] = 1, ["in"] = 1, ["iⁿ"] = 1,
["io"] = 1, ["ioh"] = 1, ["iok"] = 1, ["iong"] = 1, ["ip"] = 1,
["it"] = 1, ["iu"] = 1, ["iuh"] = 1, ["iuⁿ"] = 1, ["m"] = 1, ["mh"] = 1,
["ng"] = 1, ["ngh"] = 1, ["o"] = 1, ["o͘"] = 1, ["oa"] = 1, ["oah"] = 1, ["oai"] = 1,
["oaihⁿ"] = 1, ["oaiⁿ"] = 1, ["oan"] = 1, ["oaⁿ"] = 1, ["oat"] = 1, ["oe"] = 1,
["oeh"] = 1, ["oehⁿ"] = 1, ["oh"] = 1, ["o͘h"] = 1, ["ohⁿ"] = 1, ["ok"] = 1,
["oⁿ"] = 1, ["ong"] = 1, ["u"] = 1, ["uh"] = 1, ["ui"] = 1, ["uih"] = 1,
["uiⁿ"] = 1, ["un"] = 1, ["ut"] = 1,
},
["Zhangzhou"] = {
["a"] = 1, ["ah"] = 1, ["ahⁿ"] = 1, ["ai"] = 1, ["aih"] = 1, ["aiⁿ"] = 1, ["ak"] = 1,
["am"] = 1, ["an"] = 1, ["aⁿ"] = 1, ["ang"] = 1, ["ap"] = 1, ["at"] = 1, ["au"] = 1,
["auh"] = 1, ["auhⁿ"] = 1, ["auⁿ"] = 1, ["e"] = 1, ["ee"] = 1, ["eeh"] = 1,
["eehⁿ"] = 1, ["eh"] = 1, ["ek"] = 1, ["eⁿ"] = 1, ["eng"] = 1, ["i"] = 1,
["ia"] = 1, ["iah"] = 1, ["iahⁿ"] = 1, ["iak"] = 1, ["iam"] = 1, ["ian"] = 1, ["iaⁿ"] = 1,
["iang"] = 1, ["iap"] = 1, ["iat"] = 1, ["iau"] = 1, ["iauh"] = 1, ["iauhⁿ"] = 1,
["iauⁿ"] = 1, ["ih"] = 1, ["ihⁿ"] = 1, ["im"] = 1, ["in"] = 1, ["iⁿ"] = 1, ["io"] = 1,
["ioh"] = 1, ["io͘h"] = 1, ["iok"] = 1, ["io͘"] = 1, ["ioⁿ"] = 1, ["iong"] = 1, ["ip"] = 1,
["it"] = 1, ["iu"] = 1, ["iuh"] = 1, ["m"] = 1, ["mh"] = 1, ["ng"] = 1,
["ngh"] = 1, ["o"] = 1, ["o͘"] = 1, ["oa"] = 1, ["oah"] = 1, ["oai"] = 1,
["oaihⁿ"] = 1, ["oan"] = 1, ["oaⁿ"] = 1, ["oat"] = 1, ["oe"] = 1, ["oeh"] = 1, ["oh"] = 1,
["o͘h"] = 1, ["ohⁿ"] = 1, ["ok"] = 1, ["om"] = 1, ["oⁿ"] = 1, ["ong"] = 1,
["op"] = 1, ["u"] = 1, ["uh"] = 1, ["ui"] = 1, ["uiⁿ"] = 1, ["un"] = 1, ["ut"] = 1,
},
["Taipei"] = {
["a"] = 1, ["ah"] = 1, ["ahⁿ"] = 1, ["ai"] = 1, ["aih"] = 1, ["aiⁿ"] = 1, ["ak"] = 1,
["am"] = 1, ["an"] = 1, ["aⁿ"] = 1, ["ang"] = 1, ["ap"] = 1, ["at"] = 1, ["au"] = 1,
["auh"] = 1, ["auhⁿ"] = 1, ["auⁿ"] = 1, ["e"] = 1, ["eh"] = 1, ["ehⁿ"] = 1,
["ek"] = 1, ["eng"] = 1, ["i"] = 1, ["ia"] = 1, ["iah"] = 1, ["iahⁿ"] = 1,
["iak"] = 1, ["iam"] = 1, ["ian"] = 1, ["iaⁿ"] = 1, ["iang"] = 1, ["iap"] = 1, ["iat"] = 1,
["iau"] = 1, ["iauh"] = 1, ["iauhⁿ"] = 1, ["iauⁿ"] = 1, ["ih"] = 1, ["ihⁿ"] = 1,
["im"] = 1, ["in"] = 1, ["iⁿ"] = 1, ["io"] = 1, ["ioh"] = 1, ["iok"] = 1, ["iong"] = 1,
["ip"] = 1, ["it"] = 1, ["iu"] = 1, ["iuh"] = 1, ["iuⁿ"] = 1, ["m"] = 1,
["mh"] = 1, ["ng"] = 1, ["ngh"] = 1, ["o"] = 1, ["o͘"] = 1, ["oa"] = 1,
["oah"] = 1, ["oai"] = 1, ["oaihⁿ"] = 1, ["oan"] = 1, ["oaⁿ"] = 1, ["oat"] = 1, ["oe"] = 1,
["oeh"] = 1, ["oh"] = 1, ["o͘h"] = 1, ["ohⁿ"] = 1, ["ok"] = 1, ["om"] = 1,
["oⁿ"] = 1, ["ong"] = 1, ["op"] = 1, ["u"] = 1, ["uh"] = 1, ["ui"] = 1,
["uih"] = 1, ["uiⁿ"] = 1, ["un"] = 1, ["ut"] = 1,
},
["Kaohsiung"] = {
["a"] = 1, ["ah"] = 1, ["ahⁿ"] = 1, ["ai"] = 1, ["aih"] = 1, ["aiⁿ"] = 1, ["ak"] = 1,
["am"] = 1, ["an"] = 1, ["aⁿ"] = 1, ["ang"] = 1, ["ap"] = 1, ["at"] = 1, ["au"] = 1,
["auh"] = 1, ["auhⁿ"] = 1, ["auⁿ"] = 1, ["e"] = 1, ["eh"] = 1, ["ehⁿ"] = 1,
["ek"] = 1, ["eⁿ"] = 1, ["eng"] = 1, ["i"] = 1, ["ia"] = 1, ["iah"] = 1,
["iahⁿ"] = 1, ["iak"] = 1, ["iam"] = 1, ["ian"] = 1, ["iaⁿ"] = 1, ["iang"] = 1, ["iap"] = 1,
["iat"] = 1, ["iau"] = 1, ["iauh"] = 1, ["iauhⁿ"] = 1, ["iauⁿ"] = 1, ["ih"] = 1,
["ihⁿ"] = 1, ["im"] = 1, ["in"] = 1, ["iⁿ"] = 1, ["io"] = 1, ["ioh"] = 1, ["iok"] = 1,
["iong"] = 1, ["ip"] = 1, ["it"] = 1, ["iu"] = 1, ["iuh"] = 1, ["iuⁿ"] = 1,
["m"] = 1, ["mh"] = 1, ["ng"] = 1, ["ngh"] = 1, ["o"] = 1, ["o͘"] = 1,
["oa"] = 1, ["oah"] = 1, ["oai"] = 1, ["oaihⁿ"] = 1, ["oaiⁿ"] = 1, ["oan"] = 1,
["oaⁿ"] = 1, ["oat"] = 1, ["oe"] = 1, ["oeh"] = 1, ["oh"] = 1, ["o͘h"] = 1, ["ohⁿ"] = 1,
["ok"] = 1, ["om"] = 1, ["oⁿ"] = 1, ["ong"] = 1, ["op"] = 1, ["u"] = 1,
["uh"] = 1, ["ui"] = 1, ["uiⁿ"] = 1, ["un"] = 1, ["ut"] = 1,
}
}
if not (validInitials[loc][initial] and validFinals[loc][final]) then
--error("The syllable " .. initial .. "+" .. final .. " does not appear to be a valid " .. loc .. " POJ syllable.")
return "[[Category:Min Nan terms needing attention|*]]"
end
return nil
end
function export.generate_all(text)
local location_list = {
["hc"] = "Hsinchu",
["kh"] = "Kaohsiung",
["km"] = "Kinmen",
["lk"] = "Lukang",
["mg"] = "Magong",
["qz"] = "Quanzhou",
["sx"] = "Sanxia",
["tc"] = "Taichung",
["tn"] = "Tainan",
["tp"] = "Taipei",
["xm"] = "Xiamen",
["yl"] = "Yilan",
["zz"] = "Zhangzhou",
}
local location_alias = {
["xz"] = "hc", ["sj"] = "hc", ["st"] = "hc",
["kx"] = "kh",
["gm"] = "km", ["jm"] = "km", ["qm"] = "km",
["lg"] = "lk",
["mk"] = "mg",
["cj"] = "qj",
["ss"] = "sx", ["sk"] = "sx",
["tz"] = "tc", ["tj"] = "tc",
["tl"] = "tn",
["em"] = "xm", ["am"] = "xm", ["hm"] = "hm",
["il"] = "yl",
["lc"] = "zz",
["tt"] = "tc (Taichung) or qz (Quanzhou)",
["cc"] = "zz (Zhangzhou) or qz (Quanzhou)",
["cz"] = "zz (Zhangzhou) or qz (Quanzhou)"
}
local location_link = {
["Hsinchu"] = "''[[w:Hsinchu|Hsinchu]]''",
["Kaohsiung"] = "''[[w:Kaohsiung|Kaohsiung]]''",
["Kinmen"] = "''[[w:Kinmen|Kinmen]]''",
["Lukang"] = "''[[w:Lukang|Lukang]]''",
["Magong"] = "''[[w:Magong|Magong]]''",
["Quanzhou"] = "''[[w:Quanzhou dialect|Quanzhou]]''",
["Sanxia"] = "''[[w:Sanxia|Sanxia]]''",
["Taichung"] = "''[[w:Taichung|Taichung]]''",
["Tainan"] = "''[[w:Tainan|Tainan]]''",
["Taipei"] = "''[[w:Taipei|Taipei]]''",
["Xiamen"] = "''[[w:Amoy dialect|Xiamen]]''",
["Yilan"] = "''[[w:Yilan|Yilan]]''",
["Zhangzhou"] = "''[[w:Zhangzhou dialect|Zhangzhou]]''",
}
local IPA_available = {
["Quanzhou"] = true,
["Xiamen"] = true,
["Zhangzhou"] = true,
["Taipei"] = true,
["Kaohsiung"] = true,
}
local formatting = {
LV_two = {
leading = "\n** <small>(\'\'[[w:Hokkien|Hokkien]]\'\'",
trailing = ")</small>",
},
POJ = {
leading = "\n*** <small>''[[w:Pe̍h-ōe-jī|Pe̍h-ōe-jī]]''</small>: <font face=\"Consolas\">",
trailing = "</font>",
},
TL = {
leading = "\n*** <small>''[[w:Tâi-lô|Tâi-lô]]''</small>: <font face=\"Consolas\">",
trailing = "</font>",
},
PSDB = {
leading = "\n*** <small>''[[w:Phofsit Daibuun|Phofsit Daibuun]]''</small>: <font face=\"Consolas\">",
trailing = "</font>",
},
IPA = {
leading = "\n*** <small>[[Wiktionary:International Phonetic Alphabet|IPA]] (",
trailing = ")</small>: ",
}
}
local IPA_available_list = { "Taipei", "Zhangzhou" }
-- To be changed to { "Quanzhou", "Xiamen", "Zhangzhou", "Taipei", "Kaohsiung" } once all multi-pronunciation items in [[Category:Min Nan terms needing attention]] have been reviewed.
if type(text) == "table" then text, loc = text.args[1], text.args["loc"] end
export.poj_check_invalid(text)
if match(mw.title.getCurrentTitle().text, "[子仔]") and (match(text, "[%- /]á[%- /]") or match(text, "^á[%- /]") or match(text, "^á$") or match(text, "[%- /]á$")) and not (mw.title.getCurrentTitle().text == "仔" or mw.title.getCurrentTitle().text == "明仔早")then
text = gsub(text, "([%- /])á([%- /])", "%1仔%2")
text = gsub(text, "^á([%- /])", "仔%1")
text = gsub(text, "^á$", "仔")
text = gsub(text, "([%- /])á$", "%1仔")
error("Please change POJ to " .. text .. ".")
end
local all_readings = {}
output_text = {}
for reading in mw.text.gsplit(text, "/", true) do
if match(reading, ":") then
local reading_part = mw.text.split(reading, ":")
all_readings[reading_part[2]] = {}
for location_abbrev in mw.text.gsplit(reading_part[1], ",") do
if location_alias[location_abbrev] then
error("Invalid Min Nan location code: " .. location_abbrev .. ", maybe you meant: " .. location_alias[location_abbrev])
end
table.insert(all_readings[reading_part[2]], location_list[location_abbrev])
end
else
all_readings[reading] = IPA_available_list
end
end
if not match(text, ":") then
table.insert(output_text, formatting.LV_two.leading .. formatting.LV_two.trailing ..
formatting.POJ.leading .. export.poj_display(text) .. formatting.POJ.trailing ..
formatting.TL.leading .. export.poj_to_tl_conv(text) .. formatting.TL.trailing)
if not match(text, "%-%-") and not match(text, "[,.?!]") then
local psdb_hash = export.poj_to_psdb_conv(text)
if not match(psdb_hash, "error") then
table.insert(output_text, formatting.PSDB.leading .. psdb_hash .. formatting.PSDB.trailing)
end
for _, IPA_location in ipairs(IPA_available_list) do
table.insert(output_text, formatting.IPA.leading .. location_link[IPA_location] .. formatting.IPA.trailing)
local reading_IPA_hash = {}
for poj_reading in mw.text.gsplit(text, "/") do
table.insert(reading_IPA_hash, export.generate_IPA(poj_reading, IPA_location))
end
table.insert(output_text, table.concat(reading_IPA_hash, ", "))
if #reading_IPA_hash > 1 then
table.insert(output_text, "[[Category:Min Nan terms needing attention|*]]")
end
end
end
else
for poj_reading, location_set in pairs(all_readings) do
table.insert(output_text, formatting.LV_two.leading)
local location_hash = {}
for _, location_name in ipairs(location_set) do
table.insert(location_hash, location_link[location_name])
end
table.insert(output_text, ": " .. table.concat(location_hash, ", ") .. formatting.LV_two.trailing)
table.insert(output_text, formatting.POJ.leading .. export.poj_display(poj_reading) .. formatting.POJ.trailing ..
formatting.TL.leading .. export.poj_to_tl_conv(poj_reading) .. formatting.TL.trailing)
if not match(poj_reading, "%-%-") and not match(poj_reading, "[,.?!]") then
local psdb_hash = export.poj_to_psdb_conv(poj_reading)
if not match(psdb_hash, "error") then
table.insert(output_text, formatting.PSDB.leading .. psdb_hash .. formatting.PSDB.trailing)
end
for _, location_name in ipairs(location_set) do
if IPA_available[location_name] then
table.insert(output_text, formatting.IPA.leading .. location_link[location_name] ..
formatting.IPA.trailing .. export.generate_IPA(poj_reading, location_name))
end
end
end
end
end
return table.concat(output_text)
end
function export.generate_IPA(text, location)
-- (Wyang) I can't seem to find an example where 'triple' is used.. The code is below:
--if match(p[i], "%(") then
-- p[i] = gsub(p[i], "[%(%)]", "")
-- triple[i] = true
--end
--if triple[i] then
-- if tone[i] == "一" then
-- ipa[i] = (initial[i] .. final[i] .. "一至七 " .. initial[i] .. final[i] .. "一至七 " .. initial[i] .. final[i] .. (i == #tone and "一" or "一至七"))
-- elseif tone[i] == "二" then
-- ipa[i] = (initial[i] .. final[i] .. "二至一 " .. initial[i] .. final[i] .. "二至一 " .. initial[i] .. final[i] .. (i == #tone and "二" or "二至一"))
-- elseif tone[i] == "三" then
-- ipa[i] = (initial[i] .. final[i] .. "三至二 " .. initial[i] .. final[i] .. "三至二 " .. initial[i] .. final[i] .. (i == #tone and "三" or "三至二"))
-- elseif tone[i] == "四A" then
-- ipa[i] = (initial[i] .. final[i] .. "四至八 " .. initial[i] .. final[i] .. "四至八 " .. initial[i] .. final[i] .. (i == #tone and "四" or "四至八"))
-- elseif tone[i] == "四B" then
-- final[i] = gsub(final[i], "ʔ", "(ʔ)")
-- ipa[i] = (initial[i] .. final[i] .. "四至二 " .. initial[i] .. final[i] .. "四至二 " .. initial[i] .. final[i] .. (i == #tone and "四" or "四至二"))
-- elseif tone[i] == "五" then
-- if loc == "Quanzhou" or loc == "Taipei" then
-- ipa[i] = (initial[i] .. final[i] .. "五 " .. initial[i] .. final[i] .. "五至三 " .. initial[i] .. final[i] .. (i == #tone and "五" or "五至三"))
-- else
-- ipa[i] = (initial[i] .. final[i] .. "五 " .. initial[i] .. final[i] .. "五至七 " .. initial[i] .. final[i] .. (i == #tone and "五" or "五至七"))
-- end
-- elseif tone[i] == "七" then
-- ipa[i] = (initial[i] .. final[i] .. "七至一 " .. initial[i] .. final[i] .. "七至三 " .. initial[i] .. final[i] .. (i == #tone and "七" or "七至三"))
-- elseif tone[i] == "八A" then
-- ipa[i] = (initial[i] .. final[i] .. "八至四 " .. initial[i] .. final[i] .. "八至四 " .. initial[i] .. final[i] .. (i == #tone and "八" or "八至四"))
-- elseif tone[i] == "八B" then
-- final[i] = gsub(final[i], "ʔ", "(ʔ)")
-- ipa[i] = (initial[i] .. final[i] .. "八至五 " .. initial[i] .. final[i] .. "八至三 " .. initial[i] .. final[i] .. (i == #tone and "八" or "八至三"))
-- end
--end
if type(text) == "table" then text, location = text.args[1], text.args["loc"] end
local split_tone = {
["ā"] = "a".."̄", ["ē"] = "e".."̄", ["ī"] = "i".."̄", ["ō"] = "o".."̄", ["ū"] = "u".."̄",
["á"] = "a".."́", ["é"] = "e".."́", ["í"] = "i".."́", ["ó"] = "o".."́", ["ú"] = "u".."́", ["ḿ"] = "m".."́", ["ń"] = "n".."́",
["à"] = "a".."̀", ["è"] = "e".."̀", ["ì"] = "i".."̀", ["ò"] = "o".."̀", ["ù"] = "u".."̀", ["ǹ"] = "n".."̀",
["ǎ"] = "a".."̌", ["ě"] = "e".."̌", ["ǐ"] = "i".."̌", ["ǒ"] = "o".."̌", ["ǔ"] = "u".."̌", ["ň"] = "n".."̌",
["â"] = "a".."̂", ["ê"] = "e".."̂", ["î"] = "i".."̂", ["ô"] = "o".."̂", ["û"] = "u".."̂",
}
local tone_from_mark = {
[""] = "1",
["́"] = "2",
["̀"] = "3",
["p"] = "4A", ["t"] = "4A", ["k"] = "4A",
["h"] = "4B",
["̂"] = "5",
["̌"] = "6",
["̄"] = "7",
["̍p"] = "8A", ["̍t"] = "8A", ["̍k"] = "8A",
["̍h"] = "8B",
}
local initial_ipa = {
["p"] = "p", ["ph"] = "pʰ", ["m"] = "m", ["b"] = "b",
["t"] = "t", ["th"] = "tʰ", ["n"] = "n", ["l"] = "l",
["ch"] = "t͡s", ["chh"] = "t͡sʰ", ["j"] = "d͡z", ["s"] = "s",
["k"] = "k", ["kh"] = "kʰ", ["ng"] = "ŋ", ["g"] = "g",
["h"] = "h", [""] = "",
}
local palatal = { ["s"] = "ɕ", ["z"] = "ʑ" }
local final_ipa = {
["a"] = "a", ["ah"] = "aʔ", ["ahⁿ"] = "ãʔ", ["ai"] = "aɪ", ["aih"] = "aiʔ", ["aiⁿ"] = "ãɪ",
["ak"] = "ak̚", ["am"] = "am", ["an"] = "an", ["aⁿ"] = "ã",
["ang"] = "aŋ", ["ap"] = "ap̚", ["at"] = "at̚",
["au"] = "aʊ", ["auh"] = "aʊʔ", ["auhⁿ"] = "ãʊʔ", ["auⁿ"] = "ãʊ",
["e"] = "e", ["ee"] = "ɛ", ["eeh"] = "ɛʔ", ["eehⁿ"] = "ɛ̃ʔ",
["eh"] = "eʔ", ["ehⁿ"] = "ẽʔ", ["ek"] = "iɪk̚", ["eⁿ"] = "ẽ",
["eng"] = "iɪŋ", ["er"] = "ə", ["erh"] = "əʔ", ["erm"] = "əm",
["i"] = "i", ["ia"] = "ia", ["iah"] = "iaʔ", ["iahⁿ"] = "iãʔ", ["iak"] = "iak̚",
["iam"] = "iam", ["ian"] = "iɛn", ["iaⁿ"] = "iã", ["iang"] = "iaŋ", ["iap"] = "iap̚", ["iat"] = "iat̚",
["iau"] = "iaʊ", ["iauh"] = "iaʊʔ", ["iauhⁿ"] = "iãʊʔ", ["iauⁿ"] = "iãʊ",
["ih"] = "iʔ", ["ihⁿ"] = "ĩʔ", ["im"] = "im", ["in"] = "in", ["iⁿ"] = "ĩ",
["io"] = "iɤ", ["ioh"] = "iɤʔ", ["io͘h"] = "iɔʔ", ["io͘"] = "iɔ",
["iok"] = "iɔk̚", ["ioⁿ"] = "iɔ̃", ["iong"] = "iɔŋ",
["ip"] = "ip̚", ["ir"] = "ɯ", ["it"] = "it̚",
["iu"] = "iu", ["iuh"] = "iuʔ", ["iuⁿ"] = "iũ",
["m"] = "m̩", ["mh"] = "m̩ʔ",
["ng"] = "ŋ̍", ["ngh"] = "ŋ̍ʔ",
["o"] = "ɤ", ["o͘"] = "ɔ", ["oa"] = "ua", ["oah"] = "uaʔ", ["oai"] = "uai",
["oaihⁿ"] = "uãiʔ", ["oaiⁿ"] = "uãi", ["oan"] = "uan", ["oaⁿ"] = "uã",
["oang"] = "uaŋ", ["oat"] = "uat̚",
["oe"] = "ue", ["oeh"] = "ueʔ", ["oehⁿ"] = "uẽʔ",
["oh"] = "ɤʔ", ["o͘h"] = "ɔʔ", ["ohⁿ"] = "ɔ̃ʔ",
["ok"] = "ɔk̚", ["om"] = "ɔm", ["oⁿ"] = "ɔ̃", ["ong"] = "ɔŋ", ["op"] = "ɔp̚",
["u"] = "u", ["uh"] = "uʔ", ["ui"] = "ui", ["uih"] = "uiʔ",
["uiⁿ"] = "uĩ", ["un"] = "un", ["ut"] = "ut̚",
["Zhangzhou-eⁿ"] = "ɛ̃", ["Kaohsiung-o"] = "ɤ",
}
local tone_sandhi = {
-- (Wyang) I'm not sure about the 'Xd' ones, when tone X is followed by the diminutive 仔.
["Quanzhou"] = {
["1"] = "1", ["2"] = "4", ["3"] = "2", ["4A"] = "8A", ["4B"] = "4B",
["5"] = "6", ["6"] = "6", ["7"] = "6", ["8A"] = "6", ["8B"] = "6",
["3d"] = "1", ["4Bd"] = "1", ["5d"] = "7", ["7d"] = "7", ["8Bd"] = "7",
},
["Xiamen"] = {
["1"] = "7", ["2"] = "1", ["3"] = "2", ["4A"] = "8A", ["4B"] = "2",
["5"] = "7", ["7"] = "3", ["8A"] = "3", ["8B"] = "3",
["3d"] = "1", ["4Bd"] = "1", ["5d"] = "7", ["7d"] = "7", ["8Bd"] = "7",
},
["Zhangzhou"] = {
["1"] = "7", ["2"] = "1", ["3"] = "2", ["4A"] = "9", ["4B"] = "2",
["5"] = "7", ["7"] = "3", ["8A"] = "3", ["8B"] = "3",
["3d"] = "1", ["4Bd"] = "1", ["5d"] = "7", ["7d"] = "7", ["8Bd"] = "7",
},
["Taipei"] = {
["1"] = "7", ["2"] = "1", ["3"] = "2", ["4A"] = "8A", ["4B"] = "2",
["5"] = "3", ["7"] = "3", ["8A"] = "4A", ["8B"] = "3",
["3d"] = "1", ["4Bd"] = "1", ["5d"] = "7", ["7d"] = "7", ["8Bd"] = "7",
},
["Kaohsiung"] = {
["1"] = "7", ["2"] = "1", ["3"] = "2", ["4A"] = "8A", ["4B"] = "2",
["5"] = "7", ["7"] = "3", ["8A"] = "4A", ["8B"] = "3",
["3d"] = "1", ["4Bd"] = "1", ["5d"] = "7", ["7d"] = "7", ["8Bd"] = "7",
},
}
local tone_value = {
["Quanzhou"] = {
["1"] = "33", ["2"] = "554", ["3"] = "41", ["4A"] = "5", ["4B"] = "5",
["5"] = "24", ["6"] = "22", ["7"] = "41", ["8A"] = "24", ["8B"] = "24",
},
["Xiamen"] = {
["1"] = "44", ["2"] = "53", ["3"] = "21", ["4A"] = "32", ["4B"] = "32",
["5"] = "24", ["7"] = "22", ["8A"] = "4", ["8B"] = "4",
},
["Zhangzhou"] = {
["1"] = "44", ["2"] = "53", ["3"] = "21", ["4A"] = "32", ["4B"] = "32",
["5"] = "13", ["7"] = "22", ["8A"] = "121", ["8B"] = "121", ["9"] = "5",
},
["Taipei"] = {
["1"] = "44", ["2"] = "53", ["3"] = "11", ["4A"] = "32", ["4B"] = "32",
["5"] = "24", ["7"] = "33", ["8A"] = "4", ["8B"] = "4",
},
["Kaohsiung"] = {
["1"] = "44", ["2"] = "41", ["3"] = "21", ["4A"] = "32", ["4B"] = "32",
["5"] = "23", ["7"] = "33", ["8A"] = "4", ["8B"] = "4",
},
}
local function get_tone(text)
tone = gsub(text, "^[^́̀̂̌̄̍ptkh]+([́̀̂̌̄̍]?)[^́̀̂̌̄̍ptkh]*([ptkh]?)ⁿ?", function(tone_symbol, coda)
return tone_from_mark[tone_symbol .. coda] end)
return tone
end
local formatting = {
leading = "<span class=\"IPA\">/",
trailing = "/</span>"
}
local tone_superscript = { [1] = "¹", [2] = "²", [3] = "³", [4] = "⁴", [5] = "⁵", ["-"] = "⁻" }
local word_result = {}
local attention = {}
text = gsub(mw.ustring.lower(text), ".", split_tone)
for word in mw.text.gsplit(text, " ") do
local initial, final, tone, diminutive, sandhi, result = {}, {}, {}, {}, {}, {}
syllables = mw.text.split(word, "-")
for index, syllable in ipairs(syllables) do
if syllable == "仔" then
syllable = "a".."́"
diminutive[index] = true
end
local original_syllable = syllable
syllable = gsub(syllable, "[́̀̂̌̄̍]", "")
if not match(syllable, "[aeiou]") then
final[index] = match(syllable, "^[ckmnpst]?h?h?(ngh?)$") or match(syllable, "^h?(mh?)$")
initial[index] = syllable ~= final[index] and sub(syllable, 1, len(syllable) - len(final[index])) or "" --original code: "ʔ"
else
initial[index] = match(syllable, "^[bcgjklmnpst]?[gh]?h?")
final[index] = sub(syllable, len(initial[index]) + 1, -1)
end
tone[index] = get_tone(sub(original_syllable, len(initial[index]) + 1, -1))
table.insert(attention, export.poj_check_syllable(initial[index], final[index], location))
initial[index] = initial_ipa[initial[index]]
if match(initial[index], "[sz]ʰ?") and (match(final[index], "^i") or match(final[index], "^e[kn]")) then
initial[index] = gsub(initial[index], "[sz]", palatal)
end
final[index] = final_ipa[location..final[index]] or final_ipa[final[index]]
or error("Cannot recognise " .. final[index] .. ".")
if index < #syllables then
final[index] = gsub(final[index], "ʔ", "(ʔ)")
end
end
for index, syllable in ipairs(syllables) do
sandhi[index] = tone_value[location][tone[index]]
local sandhi_hash = tone_sandhi[location][tone[index]..(diminutive[index+1] and "d" or "")] or
tone_sandhi[location][tone[index]]
if index < #syllables and sandhi_hash ~= tone[index] then
sandhi[index] = sandhi[index] .. "-" .. tone_value[location][sandhi_hash]
end
table.insert(result, initial[index] .. final[index] .. sandhi[index])
end
table.insert(word_result, table.concat(result, " "))
end
return (gsub(formatting.leading .. table.concat(word_result, " ") ..
formatting.trailing, "[12345%-]", tone_superscript)) .. table.concat(attention)
end
function export.poj_to_psdb_conv(text)
if type(text) == "table" then text = text.args[1] end
local readings = mw.text.split(mw.ustring.lower(text), "/",true)
for i = 1,#readings,1 do
local parts = mw.text.split(readings[i], " ", true)
for j = 1, #parts, 1 do
local initial = {}
local final = {}
local psdb = {}
local tone = {}
local tonesandhi = {}
local neutral = {}
parts[j] = gsub(parts[j], "%-%-", "-0")
p = mw.text.split(parts[j], "-",true)
local ar = {}
local triple = {}
for i = 1,#p,1 do
if match(p[i], "仔") then
p[i] = gsub(p[i], "仔", "á")
ar[i] = true
end
if match(p[i], "%(") then
p[i] = gsub(p[i], "[%(%)]", "")
triple[i] = true
end
if match(p[i], "^0") then
p[i] = gsub(p[i], "0", "")
neutral[i] = true
end
p[i] = gsub(p[i], "ớ", "óo")
p[i] = gsub(p[i], "ờ", "òo")
p[i] = gsub(p[i], "ơ̂", "ôo")
p[i] = gsub(p[i], "ơ̄", "ōo")
p[i] = gsub(p[i], "ơ̍", "o̍o")
p[i] = gsub(p[i], "ơ", "oo")
p[i] = gsub(p[i], "͘", "o")
p[i] = gsub(p[i], "[̍̂̄̀]",{["̍"] = "捌", ["̂"] = "伍", ["̄"] = "柒", ["̀"] = "叁"})
if match(p[i], "[aeiou][捌]?[ptkh]") or match(p[i], "[^aeiou][mn][捌]?g?[ptkh]") then
if match(p[i], "捌") then
tone[i] = "八"
else
tone[i] = "四"
end
elseif match(p[i], "[áíúéóḿń貳]") then
tone[i] = "二"
elseif match(p[i], "[àìùèòǹ叁]") then
tone[i] = "三"
elseif match(p[i], "[âîûêô伍]") then
tone[i] = "五"
elseif match(p[i], "[āīūēō柒]") then
tone[i] = "七"
else
tone[i] = "一"
end
p[i] = gsub(p[i], "[áíúéóḿńàìùèòǹâîûêôāīūēō貳叁伍柒捌]",{["á"] = "a", ["í"] = "i", ["ú"] = "u", ["é"] = "e", ["ó"] = "o", ["ḿ"] = "m", ["ń"] = "n", ["貳"] = "", ["à"] = "a", ["ì"] = "i", ["ù"] = "u", ["è"] = "e", ["ò"] = "o", ["ǹ"] = "n", ["叁"] = "", ["â"] = "a", ["î"] = "i", ["û"] = "u", ["ê"] = "e", ["ô"] = "o", ["伍"] = "", ["ā"] = "a", ["ī"] = "i", ["ū"] = "u", ["ē"] = "e", ["ō"] = "o", ["柒"] = "", ["捌"] = ""})
if sub(p[i],1,3) == "chh" then
initial[i] = "chh"
final[i] = sub(p[i],4,-1)
elseif sub(p[i],1,1) == "m" then
if sub(p[i],2,2) == "h" then
initial[i] = ""
final[i] = "mh"
elseif sub(p[i],2,2) == "" then
initial[i] = ""
final[i] = "m"
else
initial[i] = "m"
final[i] = sub(p[i],2,-1)
end
elseif sub(p[i],1,2) == "ng" then
if sub(p[i],3,3) == "h" then
initial[i] = ""
final[i] = "ngh"
elseif sub(p[i],3,3) == "" then
initial[i] = ""
final[i] = "ng"
else
initial[i] = "ng"
final[i] = sub(p[i],3,-1)
end
elseif gsub(sub(p[i],1,2), "[ptkc]h", "") == "" then
initial[i] = sub(p[i],1,2)
final[i] = sub(p[i],3,-1)
elseif gsub(sub(p[i],1,1), "[npbtkgjshl]", "") == "" then
initial[i] = sub(p[i],1,1)
final[i] = sub(p[i],2,-1)
else
initial[i] = ""
final[i] = p[i]
end
if match(initial[i], "^chh?$") or initial[i] == "s" then
if match(final[i], "^i") then
initial[i] = initial[i] .. "i"
end
end
end
for i = 1,#p,1 do
if tone[i] == "一" then
tonesandhi[i] = "七"
elseif tone[i] == "二" then
tonesandhi[i] = "一"
elseif tone[i] == "三" then
tonesandhi[i] = ar[i+1] and "一" or "二"
elseif tone[i] == "四" then
tonesandhi[i] = "八"
elseif tone[i] == "五" then
tonesandhi[i] = "七"
elseif tone[i] == "七" then
tonesandhi[i] = ar[i+1] and "七" or "三"
elseif tone[i] == "八" then
tonesandhi[i] = "四"
end
if triple[i] then
local tonesandhi1 = nil
if tone[i] == "五" then
tonesandhi1 = "五"
elseif tone[i] == "七" then
tonesandhi1 = "一"
end
psdb[i] = (psdb_initial[initial[i]] or "error")
..(psdb_final(final[i]..(tonesandhi1 or tonesandhi[i])) or "error")
..psdb_initial[initial[i]]
..psdb_final(final[i]..tonesandhi[i])
..psdb_initial[initial[i]]
..psdb_final(final[i]..(i == #tone and tone[i] or tonesandhi[i]))
else
psdb[i] = (psdb_initial[initial[i]] or "error")
..(psdb_final(final[i]..(i == #tone and tone[i] or tonesandhi[i])) or "error")
end
if neutral[i] then
psdb[i] = "~" .. (psdb_initial[initial[i]] or "error")
..(psdb_final(final[i].."七") or "error")
end --psdb[i] = p[i]
end
parts[j] = table.concat(psdb, "")
end
readings[i] = table.concat(parts, " ")
readings[i] = gsub(readings[i], "'+", "'")
readings[i] = gsub(readings[i], "^'", "")
readings[i] = gsub(readings[i], "([^a-z])'", "%1")
readings[i] = gsub(readings[i], "([^pbdtkqgczsjlmnh])'([aeiouwy])", "%1%2")
readings[i] = gsub(readings[i], "([^aeiouwy])'([ptkbdqmn])", "%1%2")
readings[i] = gsub(readings[i], "([^aeiouwyn])'g", "%1g")
readings[i] = gsub(readings[i], "([^aeiouwypcz])'h", "%1h")
end
return (gsub(table.concat(readings, ", "),'/([^ ])',' / %1'))
end
function export.poj_display(text)
if type(text) == "table" then text = text.args[1] end
text = gsub(text, "仔", "á")
local readings = mw.text.split(text, "/")
for i = 1, #readings do
readings[i] = gsub(readings[i], "[%a,]+:", "")
readings[i] = gsub(readings[i], "%(([^%)]+)%)", "%1-%1-%1")
if not mw.ustring.match(readings[i]," ") then
readings[i] = "[[" .. readings[i] .. "#Min Nan|" .. readings[i] .. "]]"
end
end
text = table.concat(readings, " / ")
return text
end
local pengim_to_ipa_two_letters_above = {
["gh"] = "ɡ", ["bh"] = "β", ["ng"] = "ŋ",
["ao"] = "au",
}
local pengim_to_ipa_one_letter = {
--initials
["m"] = "m", ["n"] = "n",
["b"] = "p", ["d"] = "t", ["g"] = "k",
["p"] = "pʰ", ["t"] = "tʰ", ["k"] = "kʰ",
["s"] = "s", ["h"] = "h",
["r"] = "d͡z",
["z"] = "t͡s",
["c"] = "t͡sʰ",
["l"] = "l",
--vowels
["a"] = "a",
["ê"] = "e",
["e"] = "ɯ",
["i"] = "i",
["o"] = "o",
["u"] = "u",
--tones
["1"] = "³³⁻²³",
["2"] = "⁵²⁻³⁵",
["2"] = "⁵²⁻²¹",
["3"] = "²¹³⁻⁵⁵",
["4"] = "²⁻⁴",
["5"] = "⁵⁵⁻¹¹",
["6"] = "³⁵⁻¹¹",
["7"] = "¹¹",
["8"] = "⁴⁻²",
}
local pengim_to_ipa_fix = {
["β"] = "b",
["p([²⁴⁻]+[ -/])"] = "p̚%1",
["k([²⁴⁻]+[ -/])"] = "k̚%1",
["h([²⁴⁻]+[ -/])"] = "ʔ%1",
}
local pengim_to_ipa_nasal = {
["a"] = "ã",
["e"] = "ẽ", -- ê
["ɯ"] = "ɯ̃", -- e
["i"] = "ĩ",
["o"] = "õ",
["u"] = "ũ",
["n"] = "",
}
function export.pengim_to_ipa_conv(text)
local result = ""
for key,val in pairs(pengim_to_ipa_two_letters_above) do
text = gsub(text, key, val)
end
text = gsub(text, "([234]) ([^12345678 ]+)2$", "%1 %22")
local length = len(text)
for i = 1, length do
local char = sub(text,i,i)
local replaced = false
for key, val in pairs(pengim_to_ipa_one_letter) do
if char == key then
result = result .. val
replaced = true
break
end
end
if not replaced then
result = result .. char
end
end
result = result .. "/"
for key,val in pairs(pengim_to_ipa_fix) do
result = gsub(result, key, val)
end
result = gsub(result, "[aeiouɯ]+nʔ?[¹²³⁴⁵⁻]+[ -/]", function (a)
return gsub(a, ".", pengim_to_ipa_nasal)
end)
result = gsub(result, "(⁻[¹²³⁴⁵]+)/", function(a) return (a ~= "⁻²¹" and "/" or a .. "/") end)
result = gsub(result, "/$", "")
result = gsub(result, "/", "/, /")
return "/" .. result .. "/"
end
function export.pengim_display(text)
text = gsub(text, "([1-8])/", "%1 / ")
text = gsub(text, "([1-8])", "<sup>%1</sup>") -- note: originally ([1-8-]+) but it seems like websites have the final tone within parentheses, if at all
return text
end
return export