Mòdul:eo-general

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]


Funcions generals per l’esperanto.

-- Funcions generals per esperanto

local export = {}

--[[ 
Sil·labificació

    marcatge intern: vocals 0, obertures 1, codes 2
    síl·laba: ·(1*)0(2*)·
]]
function export.sil(mot)
    if type(mot) == "table" then
    	mot = mot.args[1]
    	accent = mot.args[2]
    end
    if mot == "" or mot == nil then
        mot = mw.title.getCurrentTitle().text
    end
    local sil = mw.ustring.lower(mot)
    -- diftongs decreixents
    sil = mw.ustring.gsub(sil, "[aáeéoóuú]j", "02")
    sil = mw.ustring.gsub(sil, "[aáeé]ŭ", "02")
    -- Nuclis vocàlics
    sil = mw.ustring.gsub(sil, "[aáeéiíoóuú]", "0")
    -- Obertures inseparables
    sil = string.gsub(sil, "s[kp][lr]", "111")
    sil = mw.ustring.gsub(sil, "[sŝ]tr", "111")
    sil = mw.ustring.gsub(sil, "ŝpr", "111")
    sil = mw.ustring.gsub(sil, "[bfgkpŝ][lr]", "11")
    sil = string.gsub(sil, "[dt]r", "11")
    sil = string.gsub(sil, "s[cklnptv]", "11") -- sm?
    sil = mw.ustring.gsub(sil, "ŝ[mnptv]", "11")
    sil = string.gsub(sil, "[gk][nv]", "11")
    sil = mw.ustring.gsub(sil, "[ĉfnv]j", "11")
    -- Obertures inicials
    sil = mw.ustring.gsub(sil, "^%l", "1")
    sil = mw.ustring.gsub(sil, "^2%l", "11")
    -- Obertures simples
    sil = mw.ustring.gsub(sil, "%l0", "10")
    -- Codes finals
    sil = mw.ustring.gsub(sil, "%l$", "2")
    sil = mw.ustring.gsub(sil, "%l2$", "22")
    -- Codes interiors
    sil = mw.ustring.gsub(sil, "%l([12])", "2%1")
    -- Separació de síl·labes
    local anterior = ""
    local motSil = {}
    for i = 1, mw.ustring.len(mot) do
        actual = mw.ustring.sub(sil, i, i)
        if (actual == "0" or actual == "1") and (anterior == "0" or anterior == "2") then
            table.insert(motSil, "·")
        end
        table.insert(motSil, mw.ustring.sub(mot, i, i))
        anterior = actual
    end
    return table.concat(motSil)
end

function export.accent(mot)
    if type(mot) == "table" then mot = mot.args[1] end -- des de plantilles via invoke o des de mòduls via require
    if mot == "" or mot == nil then
        mot = mw.title.getCurrentTitle().text
    end
    if mw.ustring.find(mot, "[áéíóú]") then
    	return mot
    end
    local accentuar = {["a"]="á", ["e"]="é", ["i"]="í", ["o"]="ó", ["u"]="ú"}
    local vocals = 0
    for i = mw.ustring.len(mot), 1, -1 do
        local lletra = mw.ustring.sub(mot, i, i)
        if mw.ustring.find(lletra, "[aeiou]") then
            vocals = vocals + 1
            if vocals == 2 then
                local accentuat = mw.ustring.gsub(lletra, ".", accentuar) .. mw.ustring.sub(mot, i+1)
                if i>1 then
                    accentuat = mw.ustring.sub(mot, 1, i-1) .. accentuat
                end
                return accentuat
            end
        end
    end
    if not mw.ustring.find(mot, "[áéíóú]") then
        mot = mw.ustring.gsub(mot, "[aeiou]", accentuar, 1)
    end
    return mot
end

-- Pronunciació
function export.pron(frame)
    local mot = frame.args[1] or mw.title.getCurrentTitle().subpageText
    if mw.ustring.find(mot, "ˈ") then
    	return mot
    end
    mot = mw.ustring.lower(mot)
    mot = export.accent(mot)
    mot = export.sil(mot)

	local lletra_afi = {
		["á"] = "a",
		["é"] = "e",
 		["í"] = "i",
  		["ó"] = "o",
		["ú"] = "u",
		["c"] = "t͡s",
		["ĉ"] = "t͡ʃ",
 		["g"] = "ɡ",
  		["ĝ"] = "d͡ʒ",
		["ĥ"] = "x",
		["ĵ"] = "ʒ",
		["ŝ"] = "ʃ",
		["ŭ"] = "w",
	}

	mot = mw.ustring.gsub(mot, "d·z", "·d͡z")
	mot = mw.ustring.gsub(mot, "dz", "d͡z")
    -- accent
    if mw.ustring.find(mot, "[áéíóú]") then
        mot = mw.ustring.gsub(mot, "·(%l-[áéíóú])", "ˈ%1")
    else
        mot = mw.ustring.gsub(mot, "·(%l-)·(%l-)$", "ˈ%1·%2")
    end
    if not mw.ustring.find(mot, "ˈ") then
    	if mw.ustring.find(mot, "·") then -- plurisíl·lab
        	mot = "ˈ" .. mot
        end
    end
    mot = mw.ustring.gsub(mot, ".", lletra_afi)
    mot = mw.ustring.gsub(mot, "·", ".")
    return mot
end

return export