Module:User:Thadh/sandbox

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of Thadh, for their own experimentation. Items in this module may be added and removed at Thadh's discretion; do not rely on this module's stability.


local export = {}

local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("inh")
local rsub = mw.ustring.gsub
local rlower = mw.ustring.lower

local V = "[aʌɛiɨɪouæɔʊ]̯?ː?"
local C = "[ptkʡʔbdgzʒfsʃxmnlrcɟħqʁwj]ʼ?ˤ?̥?͡?"

local iot = { ["я"]="jа", ["е"]="jэ", ["ё"]="jо", ["ю"]="у" }
local cons = { 
	["п"]="p", ["т"]="t", ["к"]="k", ["ӏ"]="ʡ", ["ъ"]="ʔ",
	["б"]="b", ["д"]="d", ["г"]="ɡ", ["з"]="z", ["ж"]="ʒ",
	["ф"]="f", ["с"]="s", ["ш"]="ʃ", ["х"]="x",
	["м"]="m", ["н"]="n", ["л"]="l", ["р"]="r",
}

local function phonetic(text)
	text = rlower(text)
	text = rsub(text, ".", iot)
	-- vowels
	text = rsub(text, "а̄", "a")
	text = rsub(text, "аь", "æ")
	text = rsub(text, "а", "ʌ")
	text = rsub(text, "ӭ", "ʌ")
	text = rsub(text, "э", "ɛ")
	text = rsub(text, "ӣ", "i")
	text = rsub(text, "и", "ɪ")
	text = rsub(text, "ы", "ɨ")
	text = rsub(text, "оа", "ɔ")
	text = rsub(text, "о", "o")
	text = rsub(text, "ӯ", "u")
	text = rsub(text, "у", "ʊ")
	-- semivowels
	text = rsub(text, "й", "j")
	text = rsub(text, "в", "w")
	-- consonants
	text = rsub(text, "([птцчк]ӏ", "%1ʼ")
	text = rsub(text, "ќӏ", "ќʼ")
	text = rsub(text, "къ", "кхʼ")
	text = rsub(text, "кх", "q")
	text = rsub(text, "ќ", "c")
	text = rsub(text, "ѓ", "ɟ")
	text = rsub(text, "хь", "ħ")
	text = rsub(text, "хӏ", "h")
	text = rsub(text, "гӏ", "ʁ")
	text = rsub(text, "рхӏ", "r̥")
	text = rsub(text, ".", cons)
	text = rsub(text, "([bdgɟwzʒʁmnlrj])ʡ", "%1ˤ")
	text = rsub(text, "ц", "t͡s")
	text = rsub(text, "ч", "t͡ʃ")
	-- phonetic vowels
	text = rsub(text, "i(" .. C .. "*" .. V .. ")", "iː%1")
	text = rsub(text, "i$", "iː")
	text = rsub(text, "u(" .. C .. "*" .. V .. ")", "uː%1")
	text = rsub(text, "u$", "uː")
	text = rsub(text, "ɛ(" .. C .. "*" .. V .. ")", "iɛ̯%1")
	text = rsub(text, "ɛ$", "iɛ̯")
	text = rsub(text, "o(" .. C .. "*" .. V .. ")", "uo̯%1")
	text = rsub(text, "o$", "uo̯")
	text = rsub(text, "æ(" .. C .. "*" .. V .. ")", "ɛ̯æː")
	text = rsub(text, "æ$", "ɛ̯æː")
	text = rsub(text, "a(" .. C .. "*" .. V .. ")", "aː%1")
	text = rsub(text, "a$", "aː")
	text = rsub(text, "ɔ(" .. C .. "*" .. V .. ")", "ɔa̯")
	text = rsub(text, "ɔ$", "ɔa̯")
	text = rsub(text, "([ɟcj])ɪ", "%1i")
	text = rsub(text, "ɪ([ɟcj])", "i%1")
	text = rsub(text, "(" .. V .. "*" .. C .. "*)(" .. V .. ")", "%1ə")
end