Module:Vi2ipa 2/dialects

From Wikipedia

Documentation for this module may be created at Module:Vi2ipa 2/dialects/doc

local Dialect = {}
function Dialect:new(object)
	object = object or {}
	for k, v in pairs(object) do
		if type(v) == "table" then setmetatable(v, {__index = self[k]}) end
	end
	setmetatable(object, self)
	self.__index = self
	
	object.initialConsonantsToIPA.dz = object.initialConsonantsToIPA.d
	object.initialConsonantsToIPA.z = object.initialConsonantsToIPA.d
	
	return object
end

---Table mapping initial consonant clusters to IPA transcriptions.
Dialect.initialConsonantsToIPA = {
	b = "ɓ", c = "k", ch = "ʨ", d = "z", ["đ"] = "ɗ", f = "f", g = "ɣ",
	gh = "ɣ", gi = "z", h = "h", j = "j", k = "k", kh = "x", l = "l", m = "m",
	n = "n", ng = "ŋ", ngh = "ŋ", nh = "ɲ", p = "p", ph = "f", q = "k", r = "ɹ",
	s = "ʂ", t = "t", th = "tʰ", tr = "tʂ", v = "v", w = "w", x = "s"
}

---Table mapping interior glide-vowel-glide sequences to IPA transcriptions, or
-- functions that return transcriptions for the given dialect, initial consonant
-- cluster, and final consonant cluster. Transcriptions include underscores as
-- placeholders for combining diacritics.
-- [[Wikipedia:wikt:vi:Đặc biệt:Tiền tố/Bản mẫu:vie-pron/VieWVG/]]
Dialect.interiorToIPA = {
	a = function (ci, cf)
		if cf == "ch" or cf == "nh" then return "ɐ_ːʲ" else return "ɐ_ː" end
	end, ai = "ɐ_ːj", ao = "ɐ_ːw", au = "ɐ_w", ay = "ɐ_j", e = "ɛ_",
	eo = "ɛ_w", i = function (ci, cf)
		if cf == "ch" or cf == "nh" then return "ɪ_"
		else return "i_" end
	end, ia = "i_ɜ", ie = "jɛ_", ieo = "jɛ_w", iu = "i_w",
	["iê"] = "iɜ_", ["iêu"] = "iɜ_w", o = function (ci, cf)
		if cf == "c" or cf == "ng" then return "ɐ_w"
		else return "ɔ_" end
	end, oa = "wa_", oai = "wɐ_ːj", oao = "wɐ_ːw", oay = "wɐ_j", ["oă"] = "wɐ",
	oe = "wɛ_", oeo = "wɛ_w", oi = "ɔ_j", oo = "ɔ_ː", u = "u_",
	ua = function (ci, cf)
		if ci == "q" then return "wa_"
		else return "u_ɜ" end
	end, uau = "wɐ_w", ui = function (ci, cf)
		if ci == "q" then return "wi_"
		else return "u_j" end
	end, uy = "wi_", uya = "wiɜ_", uyu = "wi_w", ["uyê"] = "wiɜ_", ["uâ"] = "wɜ_",
	["uây"] = "wɜ_j", ["uê"] = "we_", ["uêu"] = "we_w", ["uì"] = "wi_",
	["uô"] = "uɜ", ["uôi"] = "uɜ_j", ["uơ"] = "wə_ː", ["uơi"] = "wə_ːj",
	["â"] = "ɜ_", ["âu"] = "ɜ_w", ["ây"] = "ɜ_j", ["ê"] = "e_", ["êu"] = "e_w",
	["ô"] = "o_", ["ôi"] = "o_j", ["ôô"] = "o_ː", ["ùa"] = "u_ɜ", ["ùi"] = "u_j",
	["ă"] = "ɐ_", ["ơ"] = "ə_ː", ["ơi"] = "ə_ːj", ["ư"] = "ɨ_", ["ưa"] = "ɨ_ɜ",
	["ưi"] = "ɨ_j", ["ưu"] = "ɨ_w", ["ươ"] = "ɨɜ_", ["ươi"] = "ɨɜ_j",
	["ươu"] = "ɨɜ_w"
}

---Table mapping final consonant clusters to IPA transcriptions, or functions
-- that return transcriptions for the given dialect and glide-vowel-glide
-- sequence.
Dialect.finalConsonantsToIPA = {
	c = "k", ch = "k", m = "m", n = "n", ng = "ŋ", nh = "ŋ", p = "p", t = "t"
}

---Table mapping dialects to tables of VIQR tone representations to IPA tone
-- letter sequences.
Dialect.viqrTonesToIPA = {
	[""] = "˧˧", ["'"] = "˧˥", ["`"] = "˨˩", ["?"] = "˧˩˧", ["~"] = "˧˥",
	["."] = "˨˩"
}

Dialect.toneAttributes = {}

dialects = {}

NorthernDialect = Dialect:new({
	interiorToIPA = {["ưu"] = "i_w", ["ươu"] = "iɜ_w"},
	toneAttributes = {
		["`"] = {breathy = true}, ["?"] = {creaky = true},
		["~"] = {glottal = true, repeated = true},
		["."] = {creaky = true, glottal = true}
	}
})

dialects["Hà Nội"] = NorthernDialect:new({
	initialConsonantsToIPA = {r = "z", s = "s", tr = "ʨ"}
})

dialects["Hải Phòng"] = NorthernDialect:new({
	initialConsonantsToIPA = {d = "j", gi = "j", r = "z"}
})

local NorthCentralDialect = Dialect:new({
	initialConsonantsToIPA = {d = "g"},
	viqrTonesToIPA = {["`"] = "˧˧", ["?"] = "˧˩", ["."] = "˨˨"}
})

dialects["Vinh"] = NorthCentralDialect:new({
	viqrTonesToIPA = {[""] = "˧˥", ["'"] = "˩˩", ["~"] = "˩˧"},
	toneAttributes = {["~"] = {creaky = true}}
})

dialects["Thanh Chương"] = NorthCentralDialect:new({
	viqrTonesToIPA = {[""] = "˧˥", ["'"] = "˩˩", ["~"] = "˧˩"},
	toneAttributes = {["."] = {creaky = true}}
})

dialects["Hà Tĩnh"] = NorthCentralDialect:new({
	viqrTonesToIPA = {[""] = "˧˥˧", ["'"] = "˩˧", ["~"] = "˨˨"},
	toneAttributes = {
		["'"] = {creaky = true}, ["?"] = {creaky = true, glottal = true},
		["~"] = {creaky = true}, ["."] = {creaky = true}
	}
})

dialects["Huế"] = Dialect:new({
	initialConsonantsToIPA = {d = "j", gi = "j", v = "j"},
	interiorToIPA = {
		oa = function (ci, cf)
			if cf == "ch" or cf == "nh" then return "wa_ʲ"
			else return "wa_" end
		end
	},
	finalConsonantsToIPA = {
		ch = "t", n = function (ci, gvg)
			if gvg == "ê" or gvg == "i" then return "n"
			else return "ŋ" end
		end,
		t = function (ci, gvg)
			if gvg == "ê" or gvg == "i" then return "t"
			else return "k" end
		end
	},
	viqrTonesToIPA = {
		[""] = "˧˥", ["'"] = "˩˧", ["`"] = "˧˧", ["?"] = "˧˩˨", ["~"] = "˧˩˨",
		["."] = "˨˨"
	},
	toneAttributes = {["'"] = {creaky = true}, ["."] = {creaky = true}}
})

SouthernDialect = Dialect:new({
	initialConsonantsToIPA = {d = "j", gi = "j", q = "", v = "j"},
	interiorToIPA = {
		i = function (ci, cf)
			if cf == "ch" or cf == "nh" or cf == "n" or cf == "t" then return "ɨ_"
			else return "i_" end
		end,
		oa = function (ci, cf)
			if cf == "ch" or cf == "nh" then return "wa_ʲ"
			else return "wa_" end
		end,
		["uô"] = "wɜ"
	},
	finalConsonantsToIPA = {
		ch = "t", n = function (ci, gvg)
			if gvg == "ê" or gvg == "i" then return "n"
			else return "ŋ" end
		end,
		nh = function (ci, gvg)
			if gvg == "ê" or gvg == "i" then return "n"
			else return "ŋ" end
		end,
		t = function (ci, gvg)
			if gvg == "i" then return "t"
			else return "k" end
		end
	},
	viqrTonesToIPA = {["?"] = "˨˩˦", ["~"] = "˨˩˦", ["."] = "˨˩˨"}
})

dialects["Quy Nhơn"] = SouthernDialect:new({
	initialConsonantsToIPA = {
		kh = function (gvg, cf)
			if gvg:sub(1, 2) == "oa" or gvg:sub(1, 2) == "oe" then return "f"
			else return "x" end
		end,
		ng = function (gvg, cf)
			-- /w/ would be deleted as part of "oai".
			if gvg == "oai" then return "kw" else return "ŋ" end
		end,
		[""] = function (gvg, cf)
			if gvg == "ơi" then return "kw" else return "" end
		end
	},
	interiorToIPA = {
		a = function (ci, cf)
			if #cf < 1 then return "ɛ_ɐ" else return "ɐ_ː" end
		end,
		o = function (ci, cf)
			if cf == "c" or cf == "ng" then return "ɐ_w"
			elseif cf == "m" then return "o_"
			else return "ɔ_" end
		end,
		oo = function (ci, cf)
			if cf == "m" then return "o_ː" else return "ɔ_ː" end
		end,
		["ă"] = "ɒ_", ["ê"] = function (ci, cf)
			if cf == "p" then return "i_" else return "e_" end
		end,
		["iêu"] = "i_w",
		["ôi"] = "ɜ_w", ["ươi"] = "ɨ_", ["uôi"] = "u_j"
	},
	finalConsonantsToIPA = {
		t = function (ci, gvg)
			if gvg == "o" or gvg == "ô" or gvg == "ôô" or gvg == "u" then
				return "t"
			else return "k" end
		end
	}
})
dialects["Quy Nhơn"].interiorToIPA.oa = dialects["Quy Nhơn"].interiorToIPA.a
dialects["Quy Nhơn"].interiorToIPA.oai = dialects["Quy Nhơn"].interiorToIPA.ai
dialects["Quy Nhơn"].interiorToIPA.oao = dialects["Quy Nhơn"].interiorToIPA.ao
dialects["Quy Nhơn"].interiorToIPA.oay = dialects["Quy Nhơn"].interiorToIPA.ay
dialects["Quy Nhơn"].interiorToIPA.oe = dialects["Quy Nhơn"].interiorToIPA.e
dialects["Quy Nhơn"].interiorToIPA.oeo = dialects["Quy Nhơn"].interiorToIPA.eo

dialects["Sài Gòn"] = SouthernDialect:new()

return dialects