This is a private module sandbox of Zhnka, for his own experimentation. Items in this module may be added and removed at Zhnka's discretion; do not rely on this module's stability.
local export = {}
local m_IPA = require("Module:IPA")
local m_table = require("Module:table")
local lang = require("Module:languages").getByCode("hrx")
local U = mw.ustring.char
local rsub = mw.ustring.gsub
local rlower = mw.ustring.lower
local rfind = mw.ustring.find
local raised = U(0x031D)
local consonants = "bpmwfdtznɲrlkɡhvxjsʋʃs̄s̠ŋ"
local C = ""
local vowels = "aeɛiouæøyə"
local V = ""
local function track(page)
require("Module:debug").track("hrx-IPA/" .. page)
return true
end
local function rsub_repeatedly(term, foo, bar)
while true do
local new_term = rsub(term, foo, bar)
if new_term == term then
return term
end
term = new_term
end
end
local digraphs = {
= "yː",
= "ɛi̯",
= "iə̯",
= "ou̯",
= "uə̯",
= "øy̯",
= "ɛu̯",
= "uː",
= "k",
= "ŋ",
= "kʷ", "kv",
= "ʃ",
= "ʃk",
= "ʃp",
= "ʃt",
= "ŋ",
= "t͡s",
}
local function flatmap(items, fun)
local new = {}
for _, item in ipairs(items) do
local results = fun(item)
mw.logObject(results, "results")
for _, result in ipairs(results) do
table.insert(new, result)
end
mw.logObject(new, "new")
end
return new
end
local phon = {
= "a",
= "aː",
= "æ",
= "æː",
= "e",
= "ɛ",
= "ɛː",
= "i",
= "iː",
= "o",
= "oː",
= "u",
= "uː",
= "ø",
= "øː",
= "y",
= "p",
= "k",
= "v",
= "t͡s",
= "ks",
= "ɾ",
= "ː",
= "ʔ"
}
function export.phonemic(text, post)
text = rlower(text)
text = rsub(text, " | ", "# | #")
text = "##" .. rsub(text, " ", "# #") .. "##"
-- basic phonology
for digraph, replacement in pairs(digraphs) do
text = rsub(text, digraph, replacement)
end
text = rsub(text, ".", phon)
text = rsub(text, "'", "ˈ")
if not rfind(text, " ") and not rfind(text, "ˈ") then
text = rsub(text, text, "ˈ" .. text)
end
text = rsub(text, "-", "");
text = rsub(text, "t͡s#", "t̬͡s̬#")
text = rsub(text, "ks#", "̬ks̬#")
text = rsub(text, "#", "%1̬#")
text = rsub(text, "(c)()", "k%2")
text = rsub(text, "(c)()", "s%2")
text = rsub(text, "()(ch)", "%1x")
text = rsub(text, "()(ch)", "%1ç")
text = rsub(text, "(e)(" .. C .. ")", "ə%2")
text = rsub(text, "(e)#", "ə#")
text = rsub(text, "(ˈ" .. C .. "*)(ə)", "%1e")
text = rsub(text, "(ˈ##" .. C .. "*)(ə)", "%1e")
text = rsub(text, "^ˈ%-", "-")
local variants = {text}
local function flatmap_and_sub_pre(from, to1, to2)
variants =
flatmap(
variants,
function(item)
if rfind(item, from) then
local retval = {rsub_repeatedly(item, from, to1)}
if to2 then
m_table.insertIfNot(retval, rsub_repeatedly(item, from, to2))
end
return retval
else
return {item}
end
end
)
end
flatmap_and_sub_pre("#", "")
return variants
end
function export.IPA(frame)
local terms = {}
args = frame:getParent().args
local currentTitle = mw.title.getCurrentTitle().text
for _, term in ipairs(args) do
if term == currentTitle then track("redundant") end
table.insert(terms, term)
end
if #terms == 0 then
terms = {currentTitle}
end
local results = {}
for _, term in ipairs(terms) do
local phonemic = export.phonemic(term)
for _, variant in ipairs(phonemic) do
table.insert(results, {pron = "/" .. variant .. "/"})
end
end
return "*" .. m_IPA.format_IPA_full { lang = lang, items = results }
end
return export