Module:crk-IPA

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

Plains Cree pronunciation module, used by {{crk-IPA}}.


local export = {}

local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("crk")
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 = "[aioâîôê]"
local C = "[ptckwyhsmn^]"

local phon = {
	["p"]="p", ["t"]="t", ["k"]="k", ["c"]="ts",
	["w"]="w", ["y"]="j", ["h"]="h", ["s"]="s",
	["m"]="m", ["n"]="n",
	["a"]="a", ["i"]="i", ["o"]="o",
	["â"]="aː", ["î"]="iː", ["ô"]="oː", ["ê"]="eː"
}

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)
	-- vowels
	text = rsub(text, "i", "ɪ")
	text = rsub(text, "ɪ([wj])", "i%1")
	text = rsub(text, "ɪː", "iː")
	text = rsub(text, "o", "ʊ")
	text = rsub(text, "ʊː", "oː")
	text = rsub(text, "a", "ʌ")
	text = rsub(text, "ʌː", "ɑː")
	-- fricatives
	text = rsub(text, "h$", "")
	-- labialisation and aspiration
	text = rsub(text, "^([ptkm]s?)(%.?[ˈˌ]?)w", "%2%1ʷ")
	text = rsub(text, "([ptkhsmnj]s?)(%.?[ˈˌ]?)w", "%2%1ʷ")
	text = rsub(text, "h([ptk]s?)$", "ʰ%1")
	text = rsub(text, "t%.s", ".ts")
	text = rsub(text, "ts", "t͡s")
	-- 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, IPA_results)
end

return export