Module:User:Lunabunn/ko-pron

Hello, you have come here looking for the meaning of the word Module:User:Lunabunn/ko-pron. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Lunabunn/ko-pron, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Lunabunn/ko-pron in singular and plural. Everything you need to know about the word Module:User:Lunabunn/ko-pron you have here. The definition of the word Module:User:Lunabunn/ko-pron will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Lunabunn/ko-pron, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local export = {}

local data = mw.loadData("Module:User:Lunabunn/ko-pron/data")
local kt = require("Module:User:Lunabunn/ko-translit")
local gsub = kt.gsub
local shallowCopy = require("Module:table").shallowCopy

local ss = kt.syllable_start
local se = kt.syllable_end

function find_poss(form)
	local poss = {}
	local pos
	while true do
		pos, _, _ = mw.ustring.find(form, ss, (poss or 0) + 1)
		if pos then
			poss = pos
		else
			break
		end
	end
	return poss
end

export.gsub = gsub
export.find_poss = find_poss

function export.parse_params(parent_args)
	local args = require("Module:parameters").process(parent_args, {
		 = {},
		 = { type = "boolean" },
		 = {},
		 = {},
		 = {},
		 = { alias_of = "nn" },
		 = {},
	}, true)
	
	local params = {}
	for _, k in ipairs({ "l", "com", "nn", "bcred" }) do
		params = {}
		if args then for e in mw.text.gsplit(args, ",") do
			params = true
		end end
	end
	
	return params
end

function export.phonetic(text, params)
	-- syllable-level operations
	local temp = ""
	local init = 1
	local ind = 1
	while true do
		local a, b, cho, jung, jong = mw.ustring.find(text, ss .. "(-)(-)(*)" .. se, init)
		if not a then break end
		temp = temp .. mw.ustring.sub(text, init, a - 1)
		init = b + 1
		temp = temp .. ss
		
		-- compound tensing
		if params.com then cho = gsub(cho, "()", "%1%1") end
		-- nn
		if params.nn then cho = "n" end
		temp = temp .. cho
		
		-- uy > i for non-zero cho
		if cho ~= "G" and jung == "uy" then jung = "i" end
		temp = temp .. jung
		
		-- bcred (jong neutralization)
		if params.bcred then jong = data.neutral_coda or jong end
		temp = temp .. jong
		
		temp = temp .. se
		-- length
		if params.l then temp = temp .. "(ː)" end
		
		ind = ind + 1
	end
	text = temp .. mw.ustring.sub(text, init, mw.ustring.len(text))
	
	local forms = { text }
	
	-- vowel alternations
	-- ay~ey
	for _, form in ipairs(shallowCopy(forms)) do
		local neutralized = gsub(form, "^(-)(?)ay(*)$", "^%1%2ey%3$")
		if neutralized ~= form then table.insert(forms, neutralized) end
	end
	-- woay~wuey
	for _, form in ipairs(shallowCopy(forms)) do
		local neutralized = gsub(form, "^(-)woay(*)$", "^%1wuey%2$")
		if neutralized ~= form then table.insert(forms, neutralized) end
	end
	-- woy~<wuey
	for _, form in ipairs(shallowCopy(forms)) do
		local neutralized = gsub(form, "^(-)woy(*)$", "^%1wuey%2$")
		if neutralized ~= form then table.insert(forms, 1, neutralized) end
	end
	-- yey~ey
	for _, form in ipairs(shallowCopy(forms)) do
		local neutralized = gsub(form, "^(-)yey(*)$", "^%1ey%2$")
		if neutralized ~= form then table.insert(forms, neutralized) end
	end
	-- Guy~Gi
	for _, form in ipairs(shallowCopy(forms)) do
		local neutralized = gsub(form, "(#)Guy", "%1Gi")
		if neutralized ~= form then table.insert(forms, neutralized) end
	end
	
	-- internal changes
	for i = 1, #forms do
		-- null liaison
		forms = gsub(forms, "()%1(#)G()","%2%1%1%3") -- double
		forms = gsub(forms, "()h(#)G()", "%2%1h%3") -- aspirated
		forms = gsub(forms, "()h(#)G()","%2%1%3") -- h-cluster
		-- forms = gsub(forms, "G(#)G()", "%1ng%2") -- G > ng
		forms = gsub(forms, "()(#)G()", "%2%1%3") -- regular
		
		-- h liaison
		forms = gsub(forms, "()(#)h()", "%2%1h%3")
		forms = gsub(forms, "h(#)()()", "%1%2h%3")
		
		-- tensing part 1
		forms = gsub(forms, "lp(#)()", "l" .. "%1%2%2")
		forms = gsub(forms, "lth(#)()", "lth" .. "%1%2%2")
		
		-- coda neutralization
		forms = gsub(forms, "(*)$", function (e) return (data.neutral_coda or e) .. se end)
		
		-- tensing part 2
		forms = gsub(forms, "()(#)()", "%1%2%3%3")
		
		-- l>n
		forms = gsub(forms, "()(#)l", "%1%2n")
		
		-- nasalization
		forms = gsub(forms, "p(#)()", "m%1%2")
		forms = gsub(forms, "t(#)()", "n%1%2")
		forms = gsub(forms, "k(#)()", "G%1%2")
	end
	
	return forms
end

function export.format(lang, raw, forms, ipa_arr, rom_arr)
	local output = ""
	local format_IPA_full = require("Module:IPA").format_IPA_full
	local tag_text = require("Module:script utilities").tag_text
	
	for _, ipa in ipairs(ipa_arr) do
		ipa.lang = ipa.lang or lang
		ipa.separator = ipa.separator or " ~ "
		local phonos = ""
		if ipa.audio then
			phonos = "&nbsp;" .. mw.getCurrentFrame():callParserFunction("#tag", {"phonos", "", file = ipa.audio})
		end
		output = output .. "* " .. format_IPA_full(ipa) .. phonos .. "\n"
	end
	
	local ph = {}
	local base = mw.text.split(kt.raw_swap(raw), "")
	for _, f in ipairs(forms) do
		local form = ""
		for i, c in ipairs(mw.text.split(kt.raw_swap(f), "")) do
			if base == c then
				form = form .. "<span>" .. c .. "</span>"
			else
				form = form .. "<b>" .. c .. "</b>"
			end
		end
		ph = form
	end
	
	output = output
		.. "* <span class='" .. lang:getCode() .. "-pron__ph'>"
		.. "Phonetic hangul: "
		.. tag_text("", lang)
		.. "</span>\n"
	
	output = output
		.. "{| class='" .. lang:getCode() .. "-pron mw-collapsible mw-collapsed mw-made-collapsible'\n"
		.. "! colspan=2 | Romanizations<sup><small>]</small></sup>&nbsp;\n"
	for _, rom in ipairs(rom_arr) do
		output = output
			.. "|-\n"
			.. "! " .. rom .. "\n"
			.. "| <span class='IPA'>" .. rom .. "</span>\n"
	end
	output = output .. "|}"
	
	return output
end

function export.pron(text, params, ipa)
	local phonetic = export.phonetic(kt.raw(text), params)
	if ipa then
		for i = 1, #phonetic do
			for line in mw.text.gsplit(data.ipa_tt, "\n") do
				local _, __, pattern, repl = mw.ustring.find(line, "(.+)\t(.+)")
				phonetic = gsub(phonetic, pattern, repl)
			end
		end
		for i, form in ipairs(shallowCopy(phonetic)) do
			-- y~ɥi
			local normalized = gsub(form, "y", "ɥi")
			if normalized ~= form then
				table.insert(phonetic, i, normalized)
			end
		end
	end
	for i = 1, #phonetic do
		if ipa then
			phonetic = mw.ustring.gsub(phonetic, "", "") -- strip syllable separators
			phonetic = " .. "]"
		else
			phonetic = kt.raw_swap(phonetic)
		end
	end
	return table.concat(phonetic, ipa and " ~ " or "/")
end

return export