local export = {}
--[=[
Author: saph (User:Saph668)
Implements {{niv-IPA}}.
]=]--
local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("niv")
local sc = require("Module:scripts").getByCode("Cyrl")
local m_para = require("Module:parameters")
local m_a = require("Module:accent qualifier")
local utilities = require("Module:niv-utilities")
local gsub = mw.ustring.gsub
local rlower = mw.ustring.lower
local correspondences = {
='a', ='v', ='je',
='jo', ='ɡ', ='d',
='i', ='j',
='k', ='l',
='m', ='n',
='o', ='p', ='r',
='s', ='t',
='u', ='f', ='x',
='ɤ', ='e', ='ju',
='ja', ='z', ='b',
}
local decode = {
= "ɣ", = "ʁ", = "ɢ",
= "ŋ", = "χ", = "cʰ",
= "r̥", = "h",
= "q", = "w"
}
local vowel = ""
local C = ""
local fv = ""
local pv = ""
local function pron(text)
text = rlower(text)
text = utilities.encipher(text)
text = text:gsub("P", "pʰ")
:gsub("T", "tʰ")
:gsub("K", "kʰ")
:gsub("q", "qʰ")
text = gsub(text, ".", decode)
text = gsub(text, "ни", "ɲi")
text = gsub(text, "ди", "ɟi")
text = gsub(text, "ти", "ci")
text = gsub(text, "р̌", "r̥")
text = gsub(text, ".", correspondences)
text = text:gsub("(" .. C .. ")(?)je", "%1%2e")
text = gsub(text, "nj", "ɲ")
text = gsub(text, "dj", "ɟ")
text = gsub(text, "tj", "c")
return text
end
local function toIPA(text)
text = gsub(text, "\'", "")
text = gsub(text, "—", "")
text = gsub(text, ",", "‿")
text = gsub(text, "ⁿ", "")
return text
end
local function phon(text)
-- universal phonetic pronunciation
local mutation_u = {
= 'v', = 'r', = 'z',
= 'ɣ', = 'ʁ'
}
local mutation_a = {
= 'f', = 'r̥', = 's',
= 'x', = 'χ'
}
local voicing = {
= 'b', = 'd', = 'ɟ',
= 'ɡ', = 'ɢ'
}
local spirantisation = {
= 'x', = 'χ'
}
local boundary = ","
text = pron(text)
text = utilities.encipher(text)
text = gsub(text, ".", correspondences)
text = gsub(text, "(" .. vowel .. ")f(" .. vowel .. ")", "%1v%2")
text = gsub(text, "(" .. vowel .. ")s(" .. vowel .. ")", "%1z%2")
text = gsub(text, "\'", "ˈ")
text = gsub(text, "—", "\203\144")
for u,v in pairs(voicing) do
text = gsub(text, "()" .. boundary .. u, "%1" .. boundary .. v)
end
for u,v in pairs(spirantisation) do
text = gsub(text, u .. "()", v .. "%1")
end
for u,v in pairs(mutation_a) do
text = gsub(text, "(" .. pv .. ")" .. boundary .. u, "%1" .. boundary .. "" .. v)
text = gsub(text, "(" .. fv .. ")" .. boundary .. v, "%1" .. boundary .. "" .. u)
end
for u,v in pairs(mutation_u) do
text = gsub(text, "(" .. pv .. ")" .. boundary .. u, "%1" .. boundary .. "" .. v)
text = gsub(text, "(" .. fv .. ")" .. boundary .. v, "%1" .. boundary .. "" .. u)
end
text = text:gsub("", "")
text = gsub(text, ",", "\226\128\191\203\136")
text = gsub(text, "a\203\144", "i")
text = gsub(text, "r\204\165", "r\204\165\203\148")
return text
end
local function yphon(text)
-- phonetic pronunciation among younger speakers
text = phon(text)
text = text:gsub("pʰ", "P")
:gsub("tʰ", "T")
:gsub("kʰ", "K")
:gsub("qʰ", "Q")
:gsub("r\204\165\203\148", "R")
for i in text:gmatch(C) do mw.logObject(i) end
text = gsub(text, "^(" .. C .. ")(?)()(" .. C .. "?)(" .. C .. "?)(" .. C .. "?)$", "%1\202\178%2%3%4%5")
text = text:gsub("P", "pʰ")
:gsub("T", "tʰ")
:gsub("K", "kʰ")
:gsub("Q", "qʰ")
:gsub("R", "r\204\165\203\148")
return text
end
local function ophon(text)
-- phonetic pronunciation among older speakers
-- empty for now
text = phon(text)
return text
end
local function fphon(text)
-- phonetic pronunciation in fast speech
text = phon(text)
local boundary = "\226\128\191\203\136"
local voicing = {
= "v",
= "z"
}
local spirantisation = {
= "χ" .. boundary .. "x",
= "χ" .. boundary .. "ʁ",
= "χ" .. boundary .. "χ"
}
text = text:gsub("r\204\165\203\148", "R")
text = gsub(text, "(" .. vowel .. ")" .. "()" .. "()", "%1\203\144" .. "" .. "%3")
text = text:gsub("R", "r\204\165\203\148")
for u,v in pairs(spirantisation) do
text = gsub(text, u, v)
end
for u,v in pairs(voicing) do
text = gsub(text, u .. boundary .. "()", v .. boundary .. "%1")
end
return text
end
function export.make(frame)
local args = m_para.process(frame:getParent().args, {
= { list = true, default = mw.loadData("Module:headword/data").pagename },
})
local results = {}
local results_y = {}
local results_o = {}
local results_f = {}
for i, term in ipairs(args) do
local phonemic = {}
local phonetic = {}
local yphonetic = {}
local ophonetic = {}
local fphonetic = {}
local words = mw.text.split(term, ".", true)
phonemic = pron(words)
phonetic = phon(words)
yphonetic = yphon(words)
ophonetic = ophon(words)
fphonetic = fphon(words)
phonemic = table.concat(phonemic, " ")
phonetic = table.concat(phonetic, " ")
yphonetic = table.concat(yphonetic, " ")
ophonetic = table.concat(ophonetic, " ")
fphonetic = table.concat(fphonetic, " ")
phonemic = toIPA(phonemic)
phonetic = toIPA(phonetic)
yphonetic = toIPA(yphonetic)
ophonetic = toIPA(ophonetic)
fphonetic = toIPA(fphonetic)
table.insert(results, { pron = "/" .. phonemic .. "/" })
if phonetic ~= phonemic and gsub(phonetic, "ˈ", "") ~= phonemic then
if not phonetic:match("ˈ") then
phonetic = gsub(phonetic, "^", "ˈ")
end
if not yphonetic:match("ˈ") then
yphonetic = gsub(yphonetic, "^", "ˈ")
end
if not ophonetic:match("ˈ") then
ophonetic = gsub(ophonetic, "^", "ˈ")
end
if not fphonetic:match("ˈ") then
fphonetic = gsub(fphonetic, "^", "ˈ")
end
table.insert(results, { pron = "" })
end
if yphonetic ~= phonetic and gsub(yphonetic, "ˈ", "") ~= phonemic then
table.insert(results_y, { pron = "" })
end
if ophonetic ~= phonetic and gsub(ophonetic, "ˈ", "") ~= phonemic then
table.insert(results_o, { pron = "" })
end
if fphonetic ~= phonetic and gsub(fphonetic, "ˈ", "") ~= phonemic then
table.insert(results_f, { pron = "" })
end
end
local show =
"*" .. m_IPA.format_IPA_full { lang = lang, items = results }
local hide = show .. "\n"
local sections = {}
if #results_y > 0 then
table.insert(sections, m_a.format_qualifiers(lang, {"younger speakers"}) .. " " .. m_IPA.format_IPA_full { lang = lang, items = results_y })
end
if #results_o > 0 then
table.insert(sections, m_a.format_qualifiers(lang, {"older speakers"}) .. " " .. m_IPA.format_IPA_full { lang = lang, items = results_o })
end
if #results_f > 0 then
table.insert(sections, m_a.format_qualifiers(lang, {"in faster speech"}) .. " " .. m_IPA.format_IPA_full { lang = lang, items = results_f })
end
if #sections > 0 then
hide = hide .. "**" .. table.concat(sections, "\n**")
end
if hide == show .. "\n" then
return show
else
return '\n<div class="vsSwitcher" data-toggle-category="pronunciations">'
.. '<span class="vsToggleElement"></span>'
.. '<div class="vsShow">\n'
.. show
.. '\n</div><div class="vsHide">\n'
.. hide
.. '</div></div>\n<span></span>'
end
end
return export