コンテンツにスキップ

モジュール:acn-IPA

出典: フリー多機能辞典『ウィクショナリー日本語版(Wiktionary)』

このモジュールについての説明文ページを モジュール:acn-IPA/doc に作成できます

-- UNDER CONSTRUCTION.
-- Start getting monosyllabic words to work first, then move onto polysyllabic words.

local export = {}

local m_IPA = require("モジュール:IPA")
local m_str_utils = require("モジュール:string utilities")
local m_a = require("モジュール:accent qualifier")
local m_table = require("モジュール:table")
local lang = require("モジュール:languages").getByCode("acn")


local gsub = m_str_utils.gsub
local len = m_str_utils.len
local match = m_str_utils.match
local sub = m_str_utils.sub
local find = m_str_utils.find
local char = m_str_utils.char
local upper = m_str_utils.upper
local lower = m_str_utils.lower

-- version of gsub() that discards all but the first return value
local function gsub1(term, foo, bar)
	local retval = gsub(term, foo, bar)
	return retval
end

-- version of gsub() that returns a 2nd argument boolean indicating whether
-- a substitution was made.
local function gsubb(term, foo, bar)
	local retval, nsubs = gsub(term, foo, bar)
	return retval, nsubs > 0
end

-- apply gsub1() repeatedly until no change
local function gsub_repeatedly(term, foo, bar)
	while true do
		local new_term = gsub1(term, foo, bar)
		if new_term == term then
			return term
		end
		term = new_term
	end
end

local function format_accent(qual)
	return m_a.format_qualifiers(lang, {qual})
end

local function squareb(text)
	return "[" .. text .. "]"
end

function IPA(text)
	local ipa = text
	
	-- Tones marked with final consonant letters; default is mid tone
	if not find(ipa, "[hs]%f[%A]") then
		ipa = gsub(ipa, "(%a)(%A)", "%1˧%2")
	else
		ipa = gsub(ipa, "h%f[%A]", "˦")
		ipa = gsub(ipa, "s%f[%A]", "˧˩")
	end
	if not find(ipa, "[˧ ˧˩]$") then
		ipa = ipa .. "˧"
	end
	
	-- Basic multigraphs
	ipa = gsub(ipa, "ph", "pʰ")
	ipa = gsub(ipa, "th", "tʰ")
	ipa = gsub(ipa, "ts", "tsʰ")
	ipa = gsub(ipa, "ch", "tʃʰ")
	ipa = gsub(ipa, "kh", "kʰ")
	ipa = gsub(ipa, "ng", "ŋ")
	ipa = gsub(ipa, "sh", "ʃ")
	ipa = gsub(ipa, "oeu", "ɯu")
	ipa = gsub(ipa, "oe", "ɯ")
	ipa = gsub(ipa, "uo", "uʌ")
	ipa = gsub(ipa, "ai", "ɑi")
	ipa = gsub(ipa, "au", "ɑu")
	
	-- Monographs
	ipa = gsub(ipa, "c", "cʰ")
	ipa = gsub(ipa, "g", "ɡ")
	ipa = gsub(ipa, "z", "dz")
	ipa = gsub(ipa, "j", "dʒ")
	ipa = gsub(ipa, "y", "j")
	ipa = gsub(ipa, "o", "ɔ")
	ipa = gsub(ipa, "e", "ɛ")
	ipa = gsub(ipa, "v", "aˑ")
	ipa = gsub(ipa, "q", "ʔ")
	
	-- Tense voice; marked with -h- after l, y, and n. The Inglises say it's different from creaky voice, but they still transcribe with creaky diacritics
	ipa = gsub(ipa, "([lnmŋjw])h([jw]?[aɑeɛioɔuɯ])", "%1%2̰")
	ipa = gsub(ipa, "([aɑeɛioɔuɯ]̰)([uioaɑeɛɔʌɯ])", "%1%2̰")
	
	-- Syllable breaks
	ipa = gsub(ipa, " ", ".")
	ipa = gsub(ipa, "-", ".")
	
	-- Assimilate n before coda k into a velar nasal
	ipa = gsub(ipa, "nk%f[%A]", "ŋk")
	
	-- Render medial -y- as palatalization
	ipa = gsub(ipa, "([ptkʰxcbdɡznʃʒŋl])j", "%1ʲ")

	return ipa
end

function export.show(frame)
	local parent_args = frame:getParent().args
	local params = {
	[1] = {},
	["lh"] = {},
	["lc"] = {},
	["lx"] = {},
	["xd"] = {},
	}
	local args = require("モジュール:parameters").process(parent_args, params)
	
	input = args[1] or mw.loadData("モジュール:headword/data").pagename
	kac_ipa = "/" .. IPA(input) .. "/"
	kac_ipa = m_IPA.format_IPA(lang, kac_ipa)
	ipa = "*" .. format_accent("ミャンマー") .. " " .. kac_ipa
	
	-- For Chinese dialects. 
	-- Their pronunciations do not neatly align with the Burmese dialect and its orthography; thus they must be specified manually
	
	if args["lh"] then
		ipa = ipa .. "\n* " .. format_accent("梁河県") .. " " .. m_IPA.format_IPA(lang, squareb(args["lh"]))
	end
	if args["lc"] then
		ipa = ipa .. "\n* " .. format_accent("隴川県") .. " " .. m_IPA.format_IPA(lang, squareb(args["lc"]))
	end
	if args["lx"] then
		ipa = ipa .. "\n* " .. format_accent("芒市") .. " " .. m_IPA.format_IPA(lang, squareb(args["lx"]))
	end
	if args["xd"] then
		ipa = ipa .. "\n* " .. format_accent("仙島") .. " " .. m_IPA.format_IPA(lang, squareb(args["xd"]))
	end
	
	return ipa
end

return export