Modul:lt-pron

Vikilug‘atdan olingan

Bu modul uchun Modul:lt-pron/doc nomli hujjat sahifasini yaratishingiz mumkin

local export = {}

local U = mw.ustring.char
local udecomp = mw.ustring.toNFD
local rsubn = mw.ustring.gsub
local sub = mw.ustring.sub
local rmatch = mw.ustring.match
local rfind = mw.ustring.find
local ugmatch = mw.ustring.gmatch
local ulen = mw.ustring.len

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

local ACUTE = U(0x0301) -- acute =  ́
local GRAVE = U(0x0300) -- grave =  ̀
local TILDE = U(0x0303) -- tilde =  ̃
local BREVE = U(0x0306) -- breve =  ̆
local MACRON = U(0x0304) -- macron =  ̄
local CARON = U(0x030C) -- caron =  ̌
local OGONEK = U(0x0328) -- ogonek =  ̨
local DOT = U(0x0307) -- dot above = ̇

local accents = "[" .. ACUTE .. GRAVE .. TILDE .. BREVE .. MACRON .. "]"
local diacritics = "[" .. ACUTE .. GRAVE .. TILDE .. BREVE .. MACRON .. CARON .. OGONEK .. DOT .. "]"
local vowels = "[aeiouy]"
local consonants_no_j = "[bcdfghklmnprstvzðþx]"
-- local consonants = "[" .. consonants_no_j .. "j]"

local lang = require("Module:languages").getByCode("lt")

function export.link(term)
	return require("Module:links").full_link{ term = term, lang = lang }
end

--[=[
Takes the orthographic representation to make it closer
to the phonological output by respelling and adding missing segments
]=]
local function respell(term)
	-- replace digraph consonants with temporary placeholders
	local subs = {
		["ch"] = "ç",
		["ts"] = "c",
		["dz"] = "ð",
		["dz" .. CARON] = "þ",
		["o" .. BREVE] = "ɔ"
	}
	term = rsub(term, ".[" .. CARON .. BREVE .. "hsz]?", subs)

	-- add missing /j/: ievà > jievà
	if rfind(term, "^i[" .. ACUTE .. GRAVE .. "]?e" .. TILDE .. "?") then
		term = "j" .. term
	end
	-- pãieškos > pãjieškos
	term = rsub(
		term,
		"(" .. vowels .. diacritics .. "*)" .. "(i[" .. ACUTE .. GRAVE .. "]?e" .. TILDE .. "?)",
		"%1j%2"
	)

	-- show palatalisation
	term = rsub(term, "i([aou]" .. accents .. "*)(.?)",
		function(vow, next_char)
			if next_char == "u" then
				return "i" .. vow .. next_char
			else
				return "ʲ" .. vow .. next_char
			end
		end
	)
	term = rsub(term, "(" .. consonants_no_j .. CARON .. "?)([iejy])", "%1ʲ%2")
	term = rsub(term, "(" .. consonants_no_j .. "+)(" .. consonants_no_j .. "ʲ)",
		function(cons, soft)
			local out = ""
			for c in ugmatch(cons, ".") do
				-- k does not become palatalised: krienas, apniūkti do not have kʲ
				if c == "k" then
					out = out .. c
				else
					out = out .. c .. "ʲ"
				end
			end
			return out .. soft
		end
	)

	return term
end

--[=[
Splits the term into its syllable boundaries
]=]
local function syllabify(term)
	term = rsub(term,
		"([aeioɔuy" .. ACUTE .. GRAVE .. TILDE .. MACRON .. OGONEK .. DOT ..
		"]*[^aeioɔuy]-)([sz]?" .. CARON .. "?ʲ?[ptkbdðþgçc]?" .. CARON .. "?ʲ?[lmnrvj]?ʲ?[aeioɔuy])",
		"%1.%2"
	)
	term = rsub(term, "^%.", "")
	term = rsub(term, "%.ʲ", "ʲ.")
	term = rsub(term, "%.([ptbdðþ]ʲ?)([mn])", "%1.%2")

	return term
end

--[=[
Render phonemic pronunciation
]=]
local function phonemic(term)
	-- consonants
	local subs = {
		["c" .. CARON] = "t͡ʃ",
		["c"] = "t͡s",
		["ç"] = "x",
		["þ"] = "d͡ʒ",
		["ð"] = "d͡z",
		["g"] = "ɡ",
		["h"] = "ɣ",
		["qu"] = "kv",
		["q"] = "k",
		["s" .. CARON] = "ʃ",
		["z" .. CARON] = "ʒ"
	}
	term = rsub(term, ".[" .. CARON .. "u]?", subs)

	-- consonant allophones
	term = rsub(term, "ʃʲ", "ɕ")
	term = rsub(term, "ʒʲ", "ʑ")
	term = rsub(term, "l([^ʲ])", "ɫ%1")
	term = rsub(term, "n(ʲ?.?[kɡ])", "ŋ%1")

	-- vowels
	term = rsub(term,
		"^([^%." .. ACUTE .. GRAVE .. TILDE .. "]-[" .. ACUTE .. GRAVE .. TILDE .. "])",
		"ˈ%1"
	)
	term = rsub(term,
		"%.([^%." .. ACUTE .. GRAVE .. TILDE .. "]-[" .. ACUTE .. GRAVE .. TILDE .. "])",
		"ˈ%1"
	)
	term = rsub(term, "ia" .. ACUTE .. "u", "æ̂ʊ")
	term = rsub(term, "iau" .. TILDE .. "?", "ɛʊ")
	term = rsub(term, "au" .. TILDE .. "?", "ɐʊ̯")
	term = rsub(term, "a" .. ACUTE .. "i", "ɐ̂ɪ")
	term = rsub(term, "ai" .. TILDE .. "?", "ɐɪ")
	term = rsub(term, "e" .. ACUTE .. "i", "ɛ̂ɪ")
	term = rsub(term, "ei" .. TILDE .. "?", "ɛɪ")
	term = rsub(term, "a" .. ACUTE .. "u", "âʊ")
	term = rsub(term, "au" .. TILDE .. "?", "ɒʊ")
	term = rsub(term, "e" .. ACUTE .. "u", "ɛ̂ʊ")
	term = rsub(term, "eu" .. TILDE .. "?", "ɛʊ")
	term = rsub(term, "i" .. ACUTE .. "e", "îə")
	term = rsub(term, "ie" .. TILDE .. "?", "iə")
	term = rsub(term, "u" .. ACUTE .. "o", "ûə")
	term = rsub(term, "uo" .. TILDE .. "?", "uə")
	term = rsub(term, "u" .. ACUTE .. "i", "ʊ̂ɪ")
	term = rsub(term, "ui" .. TILDE .. "?", "ʊɪ")
	term = rsub(term, "o" .. ACUTE .. "u", "ɔ̂ɪ")
	term = rsub(term, "u" .. ACUTE .. "u", "ɔ̂ʊ")

	term = rsub(term, "a", "ɐ")
	term = rsub(term, "ɐ" .. ACUTE, "âː")
	term = rsub(term, "ɐ" .. TILDE, "aː")

	term = rsub(term, "e", "ɛ")
	term = rsub(term, "ɛ" .. DOT, "eː")
	term = rsub(term, "ɛ" .. OGONEK, "æː")

	term = rsub(term, "i", "ɪ")
	term = rsub(term, "ɪ" .. OGONEK, "iː")

	term = rsub(term, "y", "iː")

	term = rsub(term, "u", "ʊ")
	term = rsub(term, "ʊ" .. MACRON, "uː")
	term = rsub(term, "ʊ" .. OGONEK, "uː")

	term = rsub(term, "o" .. TILDE .. "?", "oː")
	term = rsub(term, "ʲaː", "ʲæː")
	term = rsub(term, "ʲɐ", "ʲɛ")

	term = rsub(term, "ː" .. ACUTE, "̂ː") -- acutes = stressed + circumflex tone
	term = rsub(term, TILDE, "") -- tilde = stressed + long
	term = rsub(term, GRAVE, "") -- grave = stressed + short
	
	term = rsub(term, "([ʲj])a(" .. OGONEK .. "?)", "%1e%2")
	return term
end

function export.phonemic(text)
	local syll = syllabify(respell(udecomp(text)))

	return udecomp(phonemic(syll))
end	

function export.test_respell(frame)
	local args = require("Module:parameters").process(frame:getParent().args, {[1] = {default = ""}})
	local syll = syllabify(respell(udecomp(args[1])))

	return syll .. " → /" .. phonemic(syll) .. "/"
end

function export.show(frame)
	local params = {
		[1] = {default = mw.title.getCurrentTitle().text}
	}
	local args = require("Module:parameters").process(frame:getParent().args, params)

	local term = mw.ustring.lower(args[1])

	return term
end

return export