Module:User:Trooper57/tpw-IPA
- This module lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • user page • user talk page • userspace
This is a private module sandbox of Trooper57, for his own experimentation. Items in this module may be added and removed at Trooper57's discretion; do not rely on this module's stability.
--shamelessly copied from Module:crk-IPA
local export = {}
local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("tpw")
local rsub = mw.ustring.gsub
local rlower = mw.ustring.lower
local rlen = mw.ustring.len
local rlast = require("Module:string/replace last").replace_last
local rfind = mw.ustring.find
local V = "[aáeéiouy]"
local C = "['bghîkmnprstûx^]"
local phon = {
["'"]="ʔ", ["b"]="β̞", ["k"]="k", ["g"]="ɡ", ["h"]="h", ["m"]="m", ["n"]="n", ["p"]="p", ["r"]="ɾ", ["s"]="s", ["t"]="t", ["x"]="ʃ",
["û"]="w", ["î"]="j", ["ŷ"]="ɨ̯",
["a"]="a", ["á"]="a", ["e"]="ɛ", ["é"]="ɛ", ["i"]="i", ["o"]="ɔ", ["u"]="u", ["y"]="ɨ",
}
local function phonetic(text)
text = rlower(text)
-- stress
local n
n = rsub(text, C, "")
n = rlen(n)
local i = 1
while i <= n do
if i == 3 then
text = rlast(text, "(" .. C .. ")(" .. V .. ")", "%1ˈ%2", 1)
elseif i % 2 ~= 0 then
text = rlast(text, "(" .. C .. ")(" .. V .. ")", "%1ˌ%2", 1)
else
text = rlast(text, "(" .. C .. ")(" .. V .. ")", "%1.%2", 1)
end
if i == n and i % 2 ~= 0 then
if i ==3 then text = rsub(text, "^(" .. V .. ")", "ˈ%1")
else text = rsub(text, "^(" .. V .. ")", "ˌ%1") end
end
i = i + 1
end
if rfind(text, "ˈ") == nil then
text = rsub(text, "ˌ", "ˈ")
end
text = rsub(text, "(" .. C .. ")([ˈˌ])", ".%2%1")
text = rsub(text, "(" .. C .. ")%.(" .. V .. ")", ".%1%2")
text = rsub(text, "^%.", "")
-- stops
text = rsub(text, "([aio])(%.?[ˈˌ]?)([ptk])([aio])", "%1%3%2%3%4")
text = rsub(text, "([ptk])%1", "%1ː")
-- general phonology
text = rsub(text, ".", phon)
-- labialisation and aspiration
text = rsub(text, "^([ptkm]s?)(%.?[ˈˌ]?)û", "%2%1ʷ")
text = rsub(text, "([ptkhsmnj]s?)(%.?[ˈˌ]?)û", "%2%1ʷ")
text = rsub(text, "h([ptk]s?)$", "ʰ%1")
text = rsub(text, "t%.s", ".ts")
text = rsub(text, "ɡ.w", "ɡʷ")
-- stylistic thingies
text = rsub(text, "%.([ˈˌ])", "%1")
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 = "[" .. phonetic(word) .. "]" })
end
return m_IPA.format_IPA_full { lang = lang, items = IPA_results }
end
return export