local export = {}
local m_IPA = require("Module:IPA")
local m_table = require("Module:table")
local lang = require("Module:languages").getByCode("gmh")
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("gmh-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̯",
= "yə̯",
= "p͡f",
= "p͡f",
= "ŋg",
= "x",
= "kw",
= "xt",
= "xs",
}
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ː",
= "aː",
= "æ",
= "æː",
= "e",
= "ɛ",
= "ɛː",
= "ɛː",
= "i",
= "iː",
= "iː",
= "o",
= "oː",
= "oː",
= "u",
= "uː",
= "uː",
= "ø",
= "øː",
= "y",
= "b",
= "p",
= "m",
= "w",
= "v",
= "d",
= "t",
= "t͡s̄",
= "s̠",
= "s̄",
= "n",
= "r",
= "l",
= "k",
= "k",
= "ɡ",
= "h",
= "ː",
= "ʔ"
}
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, "'") then
text = rsub(text, text, "ˈ" .. text)
end
text = rsub(text, "'", "ˈ")
text = rsub(text, "-", "");
text = rsub(text, "(e)(" .. C .. ")", "ə%2")
text = rsub(text, "(e)ˈ", "əˈ")
text = rsub(text, "(e)#", "ə#")
text = rsub(text, "(ˈ" .. C .. "*)(ə)", "%1e")
text = rsub(text, "(ˈ##" .. C .. "*)(ə)", "%1e")
-- suffixes
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("v", "v", "f")
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
results.qualifiers = {"before 13<sup>th</sup> CE"}
return "*" .. m_IPA.format_IPA_full { lang = lang, items = results }
end
return export