Module:luh-pron

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

This module is experimental.
The details of its operation have not yet been fully decided upon. Do not deploy widely until the module is finished.

This module does romanisation (雷州话拼音方案 devised by 蔡叶青) to IPA conversion for Leizhou Min. See {{zh-pron}}.


local export = {}
local m_string_utils = require("Module:string utilities")

local find = m_string_utils.find
local match = m_string_utils.match
local split = mw.text.split
local gsplit = mw.text.gsplit
local gsub = m_string_utils.gsub

local initial_ipa = {
	 = "p",  = "pʰ",  = "m",  = "b",
	 = "t",  = "tʰ",  = "n",  = "l",
	 = "k",  = "kʰ",  = "ŋ",  = "h",
	 = "t͡s",  = "t͡sʰ",  = "s",  = "z",
	 = "t͡s",  = "t͡sʰ",  = "s",
	 = ""
}

local final_ipa = {
	 = "i",  = "u",
	 = "a",  = "ia",  = "ua",
	 = "ɔ",  = "iɔ",
	 = "ɛ",  = "iɛ",  = "uɛ",
	 = "ai",  = "uai",
	 = "au",  = "iau",
	 = "ɛu",  = "iu",
	 = "ɔi",  = "ui",
	 = "am",  = "iam",  = "m̩",
	 = "em",  = "im",
	 = "aŋ",  = "iaŋ",  = "uaŋ",
	 = "eŋ",  = "ieŋ",  = "ŋ̍",
	 = "ɔŋ",  = "iɔŋ",
	 = "iŋ",  = "uŋ",
	 = "ap̚",  = "iap̚",
	 = "ep̚",  = "ip̚",
	 = "ak̚",  = "iak̚",  = "uak̚",
	 = "ek̚",  = "iek̚",  = "uek̚",
	 = "ik̚",  = "uk̚",
	 = "ɔk̚",  = "iɔk̚",
}

local tone_chao = {
	 = "³⁵",  = "³¹",  = "²¹",  = "⁵",
	 = "²²",  = "³³",  = "⁵⁵",  = "²"
}

-- find the sandhied tone of the first syllable in a two-syllable word
-- returns nil if the tone of the first syllable does not change
local function tone_sandhi(tone1, tone2)
	if tone1 == "1" then
		return "6"
	elseif (tone1 == "2" and match(tone2, "")) or (tone1 == "3" and match(tone2, "")) then
		return "7"
	end
end

-- convert Leizhounese Pinyin to IPA
function export.ipa(text)
	if type(text) == "table" then
		text = text.args
	end
	
	local result = {}
	
	for word in gsplit(text, "/") do
		local syllables = split(word, " ")
		local initial, final, tone, block, sandhi, ipa = {}, {}, {}, {}, {}, {}
		for i, syllable in ipairs(syllables) do
			initial, final, tone, block = match(syllable, "^(??)(??g?)()(#?)$")
		
			-- check z/c/s vs. j/q/x
			if (find(initial, "^$") and find(final, "^i")) or (find(initial, "^$") and find(final, "^")) then
				error("Invalid Leizhou pinyin input \"" .. syllable .. "\": initial " .. initial .. " cannot go with final " .. final .. ".")
			end	
			
			-- check checked tones
			if (find(final, "$") and find(tone, "^$")) or ((find(final, "$") or find(final, "ng$")) and find(tone, "^$")) then
				error("Invalid Leizhou pinyin input \"" .. syllable .. "\": final " .. final .. " cannot go with tone " .. tone .. ".")
			end
		end
		
		for i=1,#syllables,1 do
			if i+1 <= #syllables and block ~= "#" then
				sandhi = tone_sandhi(tone, tone)
			end
		end
		
		for i=1,#syllables,1 do
			actual_tone = tone_chao] .. (sandhi and "⁻" .. tone_chao] or "")
			ipa = initial_ipa] .. final_ipa] .. actual_tone
		end
		table.insert(result, table.concat(ipa, " "))
	end
	
	return "/" .. table.concat(result, "/, /") .. "/"
end

function export.rom(text)
	text = gsub(text, "/", " / ")
	text = gsub(text, '(+)', '<sup>%1</sup>')
	text = gsub(text, '#', '')
	return text
end

return export