local export = {}
local okm_translit = require("Module:okm-translit")
local u = require("Module:string/char")
local format_IPA_full = require("Module:IPA").format_IPA_full
local lang_okm = require("Module:languages").getByCode("okm")
local tag_text = require("Module:script utilities").tag_text
local explode_utf8 = require("Module:string utilities").explode_utf8
local dgju = mw.loadData("Module:okm-pron/data").dgju
local pagename = mw.loadData("Module:headword/data").pagename
local tones = {
L = u(0x0300),
= "L!",
H = u(0x0301),
= "H!",
R = u(0x030C),
= "R!",
X = "",
}
local tt = [==[
# vowels
o ʌ
u ɨ
wʌ o
wɨ u
yʌ yo
yɨ yu
e ɘ
y j
# consonant modifiers
()h %1ʰ # aspirated
()%1 %1\u{0348} # tense
cc t\u{0348}\u{0361}s # special handling because tense diacritic needs to go in between
# special consonants
c t\u{0361}s
W β
G ɣ
OO j # TODO: decide on a convention? missing in Wikipedia key
x ʔ
ng ŋ
# superscript irregular tone classes
L! <sup>L!</sup>
H! <sup>H!</sup>
R! <sup>R!</sup>
]==]
tt = mw.ustring.gsub(tt, "%s*#+", "") -- remove comments
tt = mw.ustring.gsub(tt, "\n+", "\n") -- remove empty lines
tt = mw.ustring.gsub(tt, ], function(n) return u(tonumber(n, 16)) end) -- unicode escapes
tt = mw.text.trim(tt)
function pron(word, tone_raw, irreg)
local tr = okm_translit.tr(word, "okm")
if irreg == "t" then
tr = mw.ustring.gsub(tr, "t(?)ta", "T%1ta")
elseif irreg == "p" then
tr = mw.ustring.gsub(tr, "p(?)ta", "W%1ta")
elseif irreg == "s" then
tr = mw.ustring.gsub(tr, "s(?)ta", "z%1ta")
end
local tone = {}
for v in mw.ustring.gmatch(tone_raw, "!?") do -- this matches X! too, but should be fine
tone = v
end
local _, vowel_count = mw.ustring.gsub(tr, "", "")
local pron, idx, start = "", 1, 1
for i, c in ipairs(explode_utf8(tr)) do
if mw.ustring.match(c, "") ~= nil or i == mw.ustring.len(tr) then
local match = mw.ustring.sub(tr, start, i)
pron = pron .. match .. tones or "X"]
start = i + 1
idx = idx + 1
end
end
for line in mw.text.gsplit(tt, '\n') do
local _, __, pattern, repl = mw.ustring.find(line, '(.+)\t(.+)')
pron = mw.ustring.gsub(pron, pattern, repl)
pron = mw.ustring.gsub(pron, "%.", "") -- strip syllable separators
end
return mw.ustring.toNFC(pron)
end
function export.make(frame)
local parent_args = frame:getParent().args
local args = require("Module:parameters").process(parent_args, {
= { default = pagename, list = true },
= { list = true },
= { list = true },
= { default = pagename },
= { },
= { },
})
local items, items_ortho = {}, {}
for i, e in ipairs(args) do
items = {
pron = "⫽" .. pron(e, args, args) .. "⫽",
}
end
local list = "* " .. format_IPA_full({
lang = lang_okm,
q = { "Morphophonemic" },
items = items,
})
local dg
local dg_fragment = ""
if args then
dg = "
else
dg = ""
dg_fragment = "["
local dg_id = mw.text.split(args or "", ",")
local dg_ind = 1
local HangChars = require("Module:scripts").getByCode("Hang"):getCharacters()
for c in mw.text.gsplit(args, "") do
if dgju then
local dg_reading = dg_id and dgju)] or nil
if not dg_reading then
local count = 0
for _, _ in ipairs(dgju) do
count = count + 1
end
if count == 1 then
dg_reading = dgju
end
end
dg_ind = dg_ind + 1
if dg_reading then
dg_fragment = dg_fragment .. dg_reading
else
dg = dg .. tag_text(dg_fragment, lang_okm)
dg_fragment = ""
dg = dg .. "<strong class=\"error\">choose " .. tag_text(c, lang_okm) .. " reading "
for i, head in pairs(dgju) do
if i ~= 1 then
dg = dg .. ", "
end
dg = dg .. i .. "=" .. tag_text(head, lang_okm)
end
dg = dg .. " </strong>"
require('Module:debug/track')("okm-pron/unspecified DGJU reading")
end
elseif mw.ustring.match(c, "") then
dg_fragment = dg_fragment .. c
else
dg = nil
dg_fragment = nil
break
end
end
if dg_ind == 1 then
dg = nil
dg_fragment = nil
end
end
if dg then
dg_fragment = dg_fragment .. "]"
dg = dg .. tag_text(dg_fragment, lang_okm)
list = list .. "\n* ]: " .. dg
end
return list
end
return export