Vés al contingut

Mòdul:uk-trans

De Viccionari
Icona de documentació de mòdul Documentació del mòdul[mostra] [modifica] [refresca]

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]


Mòdul en proves, per a la transcripció automàtica de l'ucraïnès, segons Viccionari:Romanització de l'ucraïnès.

local p = {}

local u = mw.ustring.char
local GR = u(0x0300) -- grave =  ̀
local AC = u(0x0301) -- acute = ˊ
local DI = u(0x0308) -- diaeresis = ¨

local tab = {
	["А"]="A", ["Б"]="B", ["В"]="V", ["Г"]="H", ["Ґ"]="G", ["Д"]="D", ["Е"]="E", ["Є"]="Ie", ["Ж"]="J", ["З"]="Z", ["И"]="I", ["Й"]="I",
	["І"]="I", ["Ї"]="Ii", ["К"]="K", ["Л"]="L", ["М"]="M", ["Н"]="N", ["О"]="O", ["П"]="P", ["Р"]="R", ["С"]="S", ["Т"]="T", ["У"]="U",
	["Ф"]="F", ["Х"]="Kh", ["Ц"]="Ts", ["Ч"]="Tx", ["Ш"]="X", ["Щ"]="Sx", ["Ь"]="", ["Ю"]="Iu", ["Я"]="Ia",
	['а']='a', ['б']='b', ['в']='v', ['г']='h', ['ґ']='g', ['д']='d', ['е']='e', ['є']='ie', ['ж']='j', ['з']='z', ['и']='i', ['й']='i',
	['і']='i', ['ї']='ii', ['к']='k', ['л']='l', ['м']='m', ['н']='n', ['о']='o', ['п']='p', ['р']='r', ['с']='s', ['т']='t', ['у']='u',
	['ф']='f', ['х']='kh', ['ц']='ts', ['ч']='tx', ['ш']='x', ['щ']='sx', ['ь']='', ['ю']='iu', ['я']='ia', ["’"]="", ["'"]="",
	-- lletres arcaiques
	["Ё"]="Io", ['Ъ']='', ['Ы']='I', ['Ѣ']='I', ['Э']='E', ['Ѳ']='F', ['Ѵ']='I', ['Ѧ']='E',
	['ё']='io', ['ъ']='', ['ы']='i', ['ѣ']='i', ['э']='e', ['ѳ']='f', ['ѵ']='i', ['ѧ']='e'
}

-- Transliterates a single word. It should include stress marks.
local function wtr(cyr)
	cyr = mw.ustring.gsub(cyr, GR, AC)
	
	-- reducció de consonants duplicades
	local no_dobles = {"([Вв])в", "([Гг])г", "([Жж])ж", "([Кк])к", "([Хх])х", "([Цц])ц", "([Чч])ч", "([Шш])ш", "([Щщ])щ"}
	for i = 1, #no_dobles do
		cyr = mw.ustring.gsub(cyr, no_dobles[i], "%1")
	end
	
	local latin = mw.ustring.gsub(cyr, '.', tab)
	
	-- reducció vocàlica ii
	latin = mw.ustring.gsub(latin, "(i" .. AC .. "?)i", "%1")
	
	-- geminació ll
	latin = mw.ustring.gsub(latin, "ll", "l·l")
	
	-- correcció gue/gui
	latin = mw.ustring.gsub(latin, "([Gg])([ei])", "%1u%2")
	
	-- regles d'accentuació en català
	local char_acc = {["A"..AC]="À", ["E"..AC]="È", ["I"..AC]="Í", ["O"..AC]="Ò", ["U"..AC]="Ú",
		["a"..AC]="à", ["e"..AC]="è", ["i"..AC]="í", ["i"..DI]="ï", ["o"..AC]="ò", ["u"..AC]="ú", ["u"..DI]="ü"}
	local sil = mw.text.split(require("Mòdul:ca-general").sil(mw.ustring.gsub(latin, "." .. AC, char_acc)), '·')
	
	if #sil == 1 then -- monosíl·laba sense accent
		latin = mw.ustring.gsub(latin, AC, "")
	elseif mw.ustring.find(sil[#sil], "[ÀàÈèÍíÒòÚú]") then -- aguda
		if not (mw.ustring.find(latin, "[aeiou]" .. AC .. "s?$") or mw.ustring.find(latin, "[ei]" .. AC .. "n$")) then
			if not mw.ustring.find(cyr, "ю" .. AC) then -- hiatus except diphthong iu
				latin = mw.ustring.gsub(latin, "([aeoiu][iu])" .. AC, "%1" .. DI)
			end
			latin = mw.ustring.gsub(latin, "gui" .. DI, "gui")
			latin = mw.ustring.gsub(latin, AC, "")
		end
	elseif mw.ustring.find(sil[#sil-1], "[ÀàÈèÍíÒòÚú]") then -- plana
		if string.find(latin, "[aeiou]s?$") or string.find(latin, "[ei]n$") then
			if not string.find(latin, "[aeiou][iu]$") then
				latin = mw.ustring.gsub(latin, "([aeoiu][iu])" .. AC, "%1" .. DI)
				latin = mw.ustring.gsub(latin, "gui" .. DI, "gui")
				latin = mw.ustring.gsub(latin, AC, "")
			end
		end
	end
	
	-- accents oberts
	latin = mw.ustring.gsub(latin, ".[" .. AC .. DI .. "]", char_acc)
	
	-- correcció intervocàlica ss, ix
	latin = mw.ustring.gsub(latin, "([AEIOUaeiouÀÈÍÒÚàèíïòúü])s([aeiouàèíòú])", "%1ss%2")
	latin = mw.ustring.gsub(latin, "([AEOUaeouÀÈÒÚàèòúü])x", "%1ix")
	
	return latin
end

-- Transliterates text, a single word or phrase.
function p.tr(text)
	if type(text) == "table" then text = text.args[1] end
	local trwords = {}
	for word in mw.text.gsplit(text, '%s') do
		table.insert(trwords, wtr(word))
	end
	
	return table.concat(trwords, ' ')
end

return p