local export = {}
local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("rsk")
local rsub = mw.ustring.gsub
local rlower = mw.ustring.lower
local rmatch = mw.ustring.gmatch
local rfind = mw.ustring.find
local rlast = require("Module:string/replace last").replace_last
local phon = {
="a", ="b", ="v", ="ɦ", ="ɡ",
="d", ="ɛ", ="jɛ", ="ʒ", ="z",
="i", ="ji", ="k", ="l", ="m",
="n", ="ɔ", ="p", ="r", ="s",
="t", ="u", ="f", ="x", ="ts",
="tʃ", ="ʃ", ="ʃtʃ",="ju", ="ja",
="ʲ", ="j",
}
local function phonetic(text)
text = rsub(text, " | ", "# | #")
text = "##" .. rsub(text, " ", "# #") .. "##"
text = rlower(text)
-- general phonology
text = rsub(text, "здж", "ждж")
text = rsub(text, "сч", "щ")
text = rsub(text, "тш", "ч")
text = rsub(text, "дш", "ч")
text = rsub(text, "дс", "ц")
text = rsub(text, "тс", "ц")
text = rsub(text, ".", phon)
-- palatalisation
text = rsub(text, "()j()", "%1ʲ%2")
-- voicing assimilation
local i = 0
text = rsub(text, "b#", "p#")
text = rsub(text, "v#", "w#")
text = rsub(text, "d(ʲ?)#", "t%1#")
text = rsub(text, "z#", "s#")
text = rsub(text, "zd#", "st#")
text = rsub(text, "zɡ#", "sk#")
text = rsub(text, "ʒdʒ#", "ʃtʃ#")
text = rsub(text, "ɡ#", "k#")
text = rsub(text, "ɦ#", "x#")
while i <= 10 do
text = rsub(text, "#vtʃ", "#fʃtʃ")
text = rsub(text, "#v()", "#f%1")
if rfind(text, "# #") then
text = rsub(text, "b# #()", "p# #%1")
text = rsub(text, "d# #()", "t# #%1")
text = rsub(text, "z# #()", "s# #%1")
text = rsub(text, "ʒ# #()", "ʃ# #%1")
text = rsub(text, "ɡ# #()", "k# #%1")
text = rsub(text, "ɦ# #()", "x# #%1")
text = rsub(text, "p# #()", "b# #%1")
text = rsub(text, "f# #()", "v# #%1")
text = rsub(text, "t# #()", "d# #%1")
text = rsub(text, "s# #()", "z# #%1")
text = rsub(text, "ʃ# #()", "ʒ# #%1")
text = rsub(text, "k# #()", "ɡ# #%1")
text = rsub(text, "x# #()", "ɦ# #%1")
else
text = rsub(text, "b()", "p%1")
text = rsub(text, "d()", "t%1")
text = rsub(text, "z()", "s%1")
text = rsub(text, "ʒ()", "ʃ%1")
text = rsub(text, "ɡ()", "k%1")
text = rsub(text, "ɦ()", "x%1")
text = rsub(text, "p()", "b%1")
text = rsub(text, "f()", "v%1")
text = rsub(text, "t()", "d%1")
text = rsub(text, "s()", "z%1")
text = rsub(text, "ʃ()", "ʒ%1")
text = rsub(text, "k()", "ɡ%1")
text = rsub(text, "x()", "ɦ%1")
end
i = i + 1
end
-- palatalisation
text = rsub(text, "()()ʲ", "%1ʲ%2ʲ")
text = rsub(text, "lnʲ", "lʲnʲ")
text = rsub(text, "n()ʲ", "nʲ%1ʲ")
text = rsub(text, "n()", "nʲ%1")
text = rsub(text, "n()()", "nʲ%1%2")
-- special cases -лчан(ь), -лче and -лчок and inflections
text = rsub(text, "ltʃan(????)#", "lʲtʃan%1#")
text = rsub(text, "ltʃɛ(???)#", "lʲtʃɛ%1#")
text = rsub(text, "ltʃa(???)#", "lʲtʃa%1#")
text = rsub(text, "ltʃ(?)k(???)#", "lʲtʃ%1k%2#")
text = rsub(text, "dʲ", "ɟ")
text = rsub(text, "tʲ", "c")
text = rsub(text, "lʲ", "ʎ")
text = rsub(text, "nʲ", "ɲ")
text = rsub(text, "ʲ", "")
-- gemination
text = rsub(text, "()ʃ", "ʃː")
text = rsub(text, "()ʒ", "ʒː")
text = rsub(text, "(?)t()", "t%2ː")
text = rsub(text, "(?)d()", "d%2ː")
text = rsub(text, "()()", "%2ː")
text = rsub(text, "()%1", "%1ː")
-- TODO: ʃs, ʒz assimilation?
-- v to w
text = rsub(text, "()v()", "%1w%2")
-- -me voicing
text = rsub(text, "tsmɛ#", "dzmɛ#")
text = rsub(text, "tʃmɛ#", "dʒmɛ#")
text = rsub(text, "pmɛ#", "bmɛ#")
text = rsub(text, "fmɛ#", "vmɛ#")
text = rsub(text, "tmɛ#", "dmɛ#")
text = rsub(text, "smɛ#", "zmɛ#")
text = rsub(text, "ʃmɛ#", "ʒmɛ#")
text = rsub(text, "kmɛ#", "ɡmɛ#")
text = rsub(text, "xmɛ#", "ɦmɛ#")
-- ignoring -shik for stress application
text = rsub(text, "ʃik#", "q#")
-- recoding -izm for stress application
text = rsub(text, "izm#", "y#")
local function splitString(text)
local items = {}
for item in rmatch(text, "#(+)#") do
table.insert(items, item)
end
return items
end
local function applyStress(items)
local processedItems = {}
for _, item in ipairs(items) do
item = rlast(item, "()", "X%1", 1)
item = rsub(item, "Xa", "A")
item = rsub(item, "Xɛ", "E")
item = rsub(item, "Xi", "I")
item = rsub(item, "Xɔ", "O")
item = rsub(item, "Xu", "U")
item = rlast(item, "()", "ˈ%1", 1)
item = rsub(item, "A", "a")
item = rsub(item, "E", "ɛ")
item = rsub(item, "I", "i")
item = rsub(item, "O", "ɔ")
item = rsub(item, "U", "u")
item = rsub(item, "()ˈ", "ˈ%1")
item = rsub(item, "tˈ()", "ˈt%1")
item = rsub(item, "dˈ()", "ˈd%1")
item = rsub(item, "()ˈ()", "ˈ%1%2")
item = rsub(item, "()ˈ()", "ˈ%1%2")
item = rsub(item, "()ˈ()", "ˈ%1%2")
item = rsub(item, "#(??)ˈ", "#ˈ%1")
item = rsub(item, "^(??)ˈ", "#ˈ%1")
-- gemination
item = rsub(item, "()()ːˈ", "ˈ%1%2ː")
item = rsub(item, "()ːˈ", "ˈ%1ː")
-- common consonant clusters
item = rsub(item, "()ˈr", "ˈ%1r")
item = rsub(item, "()ˈ()", "ˈ%1%2")
item = rsub(item, "(d?)ˈv", "ˈ%1v")
item = rsub(item, "(?)ˈ()", "ˈ%1%2")
item = rsub(item, "(?)ˈ()", "ˈ%1%2")
item = rsub(item, "(???)ˈj", "ˈ%1j")
item = rsub(item, "(?)ˈ(?)", "ˈ%1%2")
-- restoring -shik
item = rsub(item, "q", "ʃik")
-- restoring -izm
if rfind(item, "y") then
item = rsub(item, "ˈ", "")
item = rsub(item, "(??)y", "ˈ%1izm̩")
end
-- splitting prefixed forms ending in a consonant
item = rsub(item, "ɔˈ()()", "ɔ%1ˈ%2")
item = rsub(item, "ɔˈ()()", "ɔ%1ˈ%2")
item = rsub(item, "prɛˈ()()", "prɛ%1ˈ%2")
item = rsub(item, "prɛdˈlu", "prɛˈdlu")
item = rsub(item, "naˈ()()", "na%1ˈ%2")
item = rsub(item, "rɔˈ()()", "rɔ%1ˈ%2")
item = rsub(item, "bɛ()(??)ˈ", "bɛ%1ˈ%2")item = rsub(item, "bɛ()(??)ˈ", "bɛ%1ˈ%2")
item = rsub(item, "bɛˈ()", "bɛ%1ˈ")
if rfind(item, "`") then
item = rsub(item, "ˈ", "")
item = rsub(item, "`", "ˈ")
end
if not rfind(item, "ˈ", 1, true) then
item = "ˈ" .. item
end
table.insert(processedItems, item)
end
return processedItems
end
local function concatIndividualWords(items)
local result = "#"
for i, item in ipairs(items) do
result = result .. item .. "#"
if i < #items then
result = result .. " #"
end
end
return result
end
-- stress
local items = splitString(text)
local words = applyStress(items)
text = "#" .. concatIndividualWords(words) .. "#"
-- affricates
text = rsub(text, "dʃ", "t͡ʃ")
text = rsub(text, "tʃ", "t͡ʃ")
text = rsub(text, "dʒ", "d͡ʒ")
text = rsub(text, "ts", "t͡s")
text = rsub(text, "ds", "t͡s")
text = rsub(text, "dz", "d͡z")
-- final substitutions
text = rsub(text, "'", "")
text = rsub(text, "n()", "ŋ%1")
text = rsub(text, "#", "")
return text
end
function export.IPA(frame)
local words = {}
for _, word in ipairs(frame:getParent().args) do
table.insert(words, word)
end
if #words == 0 then
words = {mw.title.getCurrentTitle().text}
end
local IPA_results = {}
for _, word in ipairs(words) do
table.insert(IPA_results, { pron = "" })
end
return m_IPA.format_IPA_full { lang = lang, items = IPA_results }
end
return export