K wobsahej skočić

Modul:hsb-IPA

z Wikisłownika

Dokumentacija za tutón modul hodźi so na Modul:hsb-IPA/dokumentacija wutworić

local export = {}

local m_IPA = require("Modul:IPA")
local lang = require("Modul:languages").getByCode("hsb")
local rsub = mw.ustring.gsub
local rlower = mw.ustring.lower

local C = "[bdfɡɦxjkβmnpʀʃstvɥzʒʲ]"
local V = "[aɛeiɔouɪ]"
local T = "[pfsxkpʃst]"
local D = "[bvβdɡɦzʒ]"

local function rsub_repeatedly(term, foo, bar)
	while true do
		local new_term = rsub(term, foo, bar)
		if new_term == term then
			return term
		end
		term = new_term
	end
end

local di = {
	["ch"]="x",
	["dź"]="dʒ",
	["tř"]="tS",
	["wj"]="ɥ",
}

local phon = {
	["a"]="a",
	["b"]="b",
	["c"]="ts",
	["č"]="tʃ",
	["ć"]="tʃ",
	["d"]="d",
	["e"]="ɛ",
	["ě"]="ɪ",
	["f"]="f",
	["g"]="ɡ",
	["h"]="ɦ",
	["i"]="i",
	["j"]="j",
	["k"]="k",
	["l"]="l",
	["ł"]="w",
	["m"]="m",
	["n"]="n",
	["ń"]="jn",
	["o"]="ɔ",
	["ó"]="ʊ",
	["p"]="p",
	["q"]="kʰ",
	["r"]="ʀ",
	["ř"]="ʃ",
	["s"]="s",
	["š"]="ʃ",
	["t"]="t",
	["u"]="u",
	["w"]="w",
	["v"]="v",
	["y"]="ɨ",
	["z"]="z",
	["ž"]="ʒ",
}

local devoicing = {
    ["b"] = "p",
    ["d"] = "t",
    ["ɡ"] = "k",
    ["z"] = "s",
    ["v"] = "f",
    ["ʒ"] = "ʃ",
}

local voicing = {
    ["p"] = "b",
    ["t"] = "d",
    ["k"] = "ɡ",
    ["s"] = "z",
    ["f"] = "v",
    ["ʃ"] = "ʒ",
}

local function phonemic(text)
	text = rlower(text)
	
	text = rsub(text, " | ", "# | #")
	text = "##" .. rsub(text, " ", "# #") .. "##"
	
	-- basic phonology
	text = rsub(text, "ts", "tss")
	text = rsub(text, "..", di)
	text = rsub("1" .. text, "..", di)
	text = rsub("1" .. text, "..", di)
	text = rsub(text, "1", "")
	text = rsub(text, ".", phon)
	-- 
	text = rsub(text, "#x", "#kʰ")
	--
	text = rsub(text, "X", "x")
	--
	text = rsub(text, "#sx", "skʰ")
	--
	text = rsub(text, "#zɦ", "z")
	-- palatalisation
	text = rsub(text, "jʲ", "j")
	-- h
	text = rsub(text, "ɦ#", "")
	text = rsub(text, "ɦ("..C..")", "%1")
	-- ł
	text = rsub(text, "("..C..")w$", "%1")
	text = rsub(text, "("..C..")w("..C..")", "%1%2")
	-- w
	text = rsub(text, "("..C..")v$", "%1")
	text = rsub(text, "("..C..")v("..C..")", "%1%2")
		
	local function voice(sound, following)
		return voicing[sound] .. following
    end
    
    local function devoice(sound, following)
		return devoicing[sound] .. following
    end
    
    local function final_devoicing(sound)
		return devoicing[sound]
    end

	--v voicing
	text = rsub(text, "(" .. T .. ")v", "%1f")
	
	-- Final devoicing
	text = rsub_repeatedly(text, "(" .. D .. ")#", final_devoicing)
	
	text = rsub_repeatedly(text, "(" .. T .. ")(" .. D .. ")", voice)
	text = rsub_repeatedly(text, "(" .. D .. ")(" .. T .. ")", devoice)
	
	-- stress
	if mw.ustring.find(text, "'") == nil then
		text = "ˈ" .. text
	end
	text = rsub(text, "^(" .. C .. "+ʲ?)'", "'%1")
	text = rsub(text, " (" .. C .. "+ʲ?)'", " '%1")
	text = rsub(text, "(" .. C .. "ʲ?)'", "'%1")
	text = rsub(text, "t's", "'ts")
	text = rsub(text, "'", "ˈ")
	-- affricates
	text = rsub(text, "t([sʃ])", "t͡%1")
	text = rsub(text, "d([zʒ])", "d͡%1")
	-- suffixes
	text = rsub(text, "^ˈ%-", "")
	-- resolution
	text = rsub(text, "wʲ", "w")
	text = rsub(text, "jʲ", "j")
	-- tř
	text = rsub(text, "tS", "tʃ")
	
	text = rsub(text, "#", "")

	text = rsub(text, "-", "")
	
	return text
end


function export.IPA(frame)
	local words = {}
	
	for _, word in ipairs(frame:getParent().args) do
		table.insert(words, word)
	end
	
	if #words == 0 then
		words = {mw.title.getCurrentTitle().text}
	end
	
	local IPA_results = {}
	
	for _, word in ipairs(words) do
		table.insert(IPA_results, { pron = "/" .. phonemic(word) .. "/" })
	end
	
	return m_IPA.format_IPA_full { lang = lang, items = IPA_results }
end

return export