Module:kl-pron

From Wiktionary, the free dictionary
Jump to navigation Jump to search
This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local gsub = mw.ustring.gsub
local lower = mw.ustring.lower

export.phonemic = function(frame)
	local params = { [1] = {} }

	local args = require("Module:parameters").process(frame:getParent().args, params)
	local word = ""
	if args[1] == nil or args[1] == "" then
		word = mw.title.getCurrentTitle().subpageText
	else
		word = args[1]
	end

	-- Make word lowercase
	word = lower(word)

	-- Phonemic changes
	local mapPL = {
		["nng"] = "ŋŋ",
		["ng"] = "ŋ",
		["g"] = "ɡ",
		["d"] = "t",
		["b"] = "p",
		["e"] = "i",
		["o"] = "u",
	}
	word = gsub(word, "n*.", mapPL)
	word = gsub(word, ".", mapPL)

	return "/" .. word .. "/ "
end

export.phonetic = function(frame)
	local params = { [1] = {} }

	local args = require("Module:parameters").process(frame:getParent().args, params)
	local word = ""
	if args[1] == nil or args[1] == "" then
		word = mw.title.getCurrentTitle().subpageText
	else
		word = args[1]
	end

	if word == "kl-IPA" then
		word = "avinngaq"
	end

	-- Make word lowercase
	word = lower(word)

	-- Trigraphs
	local map3L = { ["nng"] = "ŋ.ŋ" }

	-- Digraphs
	local map2L = { ["ng"] = "ŋ", ["aa"] = "aː", ["ee"] = "ɜː",
					["ii"] = "iː", ["oo"] = "ɔː", ["uu"] = "uː" }

	-- Process trigraphs first
	for k, v in pairs(map3L) do
		word = gsub(word, k, v)
	end

	-- Then process digraphs
	for k, v in pairs(map2L) do
		word = gsub(word, k, v)
	end

	local cons = {"m","n","p","t","k","q","v","s","g","r","l","j","b","d","ŋ"}

	-- Convert the cons table to a string pattern
	local consPattern = table.concat(cons, "|")

	-- Geminates and /t/-affrication
	word = gsub(word, "(" .. consPattern .. ")(" .. consPattern .. ")", "%2%2")

	local mapGL = { ["ll"] = "ɬ.ɬ", ["gg"] = "x.x", ["rr"] = "χ.χ",
					["rl"] = "ɬ.ɬ", ["rf"] = "f.f", ["rs"] = "s.s",
					["ff"] = "f.f", ["pp"] = "p.p", ["nn"] = "n.n",
					["mm"] = "m.m", ["tt"] = "t.t", ["qq"] = "q.q",
					["ss"] = "s.s", ["kk"] = "k.k", ["ts"] = "t.t͡s",
					["ti"] = "t͡si", ["rn"] = "n.n", ["rm"] = "m.m",
					["rp"] = "p.p", ["rt"] = "t.t", ["rk"] = "k.k",
					["vv"] = "f.f", ["jj"] = "j.j" }
	-- Monographs
	local map1L = { ["g"] = "ɣ", ["e"] = "ɜ", ["o"] = "ɔ", ["r"] = "ʁ",
					["d"] = "t", ["b"] = "p", ["'"] = "ˈ" }

	local vow = {"a", "e", "i", "o", "u"}

	--Syllabification Rules
	word = gsub(word, "([aeiou])ng([aeiou])", "%1.ng%2")
	word = gsub(word, "([aeiou])ng([aeiou])", "%1.ng%2")
	word = gsub(word, "([aeiou])ŋ([aeiou])", "%1.ŋ%2")
	word = gsub(word, "([aeiou])ŋ([aeiou])", "%1.ŋ%2")
	word = gsub(word, "([aeiou])([mnptkqvsgrljbd])([aeiou])", "%1.%2%3")
	word = gsub(word, "([aeiou])([mnptkqvsgrljbd])([aeiou])", "%1.%2%3")


	for I = 1, #word do
		local let0 = word:sub(I, I)
		local let1 = word:sub(I + 1, I + 1)
		local let2 = word:sub(I + 2, I + 2)
		if contains(let0, vow) and contains(let1, vow) and let0 ~= let1 then
			word = word:sub(1, I) .. "." .. word:sub(I + 1)
		end
	end

	-- Vowel uvularization
	word = gsub(word, "ːr([mnptkqvsgrljf])", "ʶːr%1")

	for let, res in pairs(map3L) do
		word = gsub(word, let, res)
	end

	for let, res in pairs(map2L) do
		word = gsub(word, let, res)
	end

	for let, res in pairs(mapGL) do
		word = gsub(word, let, res)
	end

	for let, res in pairs(map1L) do
		word = gsub(word, let, res)
	end

	word = gsub(word, "ː%.", "ː")

	-- Orthographic voiced stops
	word = gsub(word, "^g", "k")
	word = gsub(word, "b", "p")
	word = gsub(word, "d", "t")

	word = gsub(word, "ix.x", "iç.ç")
	word = gsub(word, "ax.x", "ax̟.x̟")

	word = gsub(word, "u.v", "u.ʷ")

	-- Uvularisation
	word = gsub(word, "ɑː([mnptksljf])", "ɑʶː%1")
	word = gsub(word, "ɔː([mnptksljf])", "ɔʶː%1")
	word = gsub(word, "ɜː([mnptksljf])", "ɜʶː%1")

	-- U
	word = gsub(word, "uː%.([ʁq])", "oː.%1")
	word = gsub(word, "u%.([ʁq])", "o.%1")
	word = gsub(word, "uː([ʁq])", "oː%1")
	word = gsub(word, "u([ʁq])", "o%1")
	word = gsub(word, "([ntsl])uː%.([ntsl])", "%1ʉː.%2")
	word = gsub(word, "([ntsl])u%.([ntsl])", "%1ʉ.%2")
	word = gsub(word, "([ntsl])uː([ntsl])", "%1ʉː%2")
	word = gsub(word, "([ntsl])u([ntsl])", "%1ʉ%2")
	word = gsub(word, "uː%.([mp])", "uː.%1")
	word = gsub(word, "u%.([mp])", "u.%1")
	word = gsub(word, "uː([mp])", "uː%1")
	word = gsub(word, "u([mp])", "u%1")
	word = gsub(word, "uː", "ʊː")
	word = gsub(word, "u", "ʊ")
	word = gsub(word, "^ʊː%.([^ʁq])", "uː.%1")
	word = gsub(word, "^ʊ%.([^ʁq])", "u.%1")
	word = gsub(word, "^ʊː([^ʁq])", "uː%1")
	word = gsub(word, "^ʊ([^ʁq])", "u%1")

	-- A
	word = gsub(word, "aː%.([ʁq])", "ɑː.%1")
	word = gsub(word, "a%.([ʁq])", "ɑ.%1")
	word = gsub(word, "aː([ʁq])", "ɑː%1")
	word = gsub(word, "a([ʁq])", "ɑ%1")
	word = gsub(word, "aː$", "aː")
	word = gsub(word, "a$", "a")
	word = gsub(word, "aː", "əː")
	word = gsub(word, "a", "ə")
	word = gsub(word, "^əː%.([^ʁq])", "aː.%1")
	word = gsub(word, "^ə%.([^ʁq])", "a.%1")
	word = gsub(word, "^əː([^ʁq])", "aː%1")
	word = gsub(word, "^ə([^ʁq])", "a%1")

	-- I
	word = gsub(word, "^iː%.([^ʁq])", "iː.%1")
	word = gsub(word, "^i%.([^ʁq])", "i.%1")
	word = gsub(word, "^iː([^ʁq])", "iː%1")
	word = gsub(word, "^i([^ʁq])", "i%1")
	word = gsub(word, "iː%.([ʁq])", "ɐː.%1")
	word = gsub(word, "i%.([ʁq])", "ɐ.%1")
	word = gsub(word, "iː([ʁq])", "ɐː%1")
	word = gsub(word, "i([ʁq])", "ɐ%1")
	word = gsub(word, "iː%.([mp])", "yː.%1")
	word = gsub(word, "i%.([mp])", "y.%1")
	word = gsub(word, "iː([mp])", "yː%1")
	word = gsub(word, "i([mp])", "y%1")
	word = gsub(word, "iː", "ɪː")
	word = gsub(word, "i", "ɪ")
	word = gsub(word, "^ɪː%.([^ʁq])", "iː.%1")
	word = gsub(word, "^ɪ%.([^ʁq])", "i.%1")
	word = gsub(word, "^ɪː([^ʁq])", "iː%1")
	word = gsub(word, "^ɪ([^ʁq])", "i%1")


	return "[" .. word .. "]"

end

function contains(key, set)
	for k0, val in pairs(set) do
	if val == key then
		return true
		end
	end
	return false
end

return export