Mòdul:es-general

De Viccionari
Salta a la navegació Salta a la cerca
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 castellà.

local export = {}

-- Clau d'ordenació per a categories
local senseDiacritics = {
    ["Á"] = "A", ["á"] = "a",
    ["É"] = "E", ["é"] = "e",
    ["Í"] = "I", ["í"] = "i",
    ["Ó"] = "O", ["ó"] = "o",
    ["Ú"] = "U", ["ú"] = "u", ["Ü"] = "U", ["ü"] = "u",
    ["Ñ"] = "n", ["ñ"] = "n",
    ["-"] = ""}

function export.ordena(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
    local clau           -- format complet: "clau1!clau2!mot"
    local clau1          -- clau primària: en minúscules i sense diacrítics
    local clau2          -- clau secundària: prioritat minúscules > majúscules
    local motLower = mw.ustring.lower(mot)
    clau1 = mw.ustring.gsub(motLower, ".", senseDiacritics)
    if clau1 == mot then
        return clau1
    end
    clau2 = mw.ustring.gsub(mot, ".", senseDiacritics)
    if clau2 ~= clau1 then
        clau = clau1 .. "!" .. clau2 .. "!" .. mot
    else
        clau = clau1 .. "!" .. mot
    end
    return clau
end

function export.cat_ortografia(frame)
	-- categorització per característiques ortogràfiques: invers, palíndroms
	local pagename = mw.title.getCurrentTitle().text
	local namespace = mw.title.getCurrentTitle().nsText
	local ret = ""
	if namespace == "" then
		local motNet = mw.ustring.gsub(mw.ustring.lower(pagename), ".", senseDiacritics)
		local motInvers = motNet:reverse()
		if not pagename:find("[ .]") then -- sense locucions ni abreviatures
			ret = "[[Categoria:Diccionari invers en castellà|" .. motInvers .. "]]"
		end
		-- palímdroms traslladat a [[Mòdul:palíndroms]
		--if string.gsub(motInvers, " ", "") == string.gsub(motNet, " ", "") and string.len(motNet) > 1 and not pagename:find("%.") then
		--	ret = ret .. "[[Categoria:Palíndroms en castellà" .. (motNet == pagename and "" or "|" .. motNet) .. "]]"
		--end
	end
	return ret
end

--[[ 
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] 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
    local sil = mw.ustring.lower(mot)
    -- Prefixos que trenquen regles
    -- prefixos ab-(r), post-(r) són ambigus
    sil = mw.ustring.gsub(sil, "^subr", "1021")
    sil = mw.ustring.gsub(sil, "^superr", "101021")
    sil = mw.ustring.gsub(sil, "^hiperr", "101021")
    sil = mw.ustring.gsub(sil, "^interr", "021021")
    sil = mw.ustring.gsub(sil, "^ciberr", "101021")
    -- Triftongs
    sil = mw.ustring.gsub(sil, "[iuü][aáeé][iu]", "022")
    -- Diftongs
    sil = mw.ustring.gsub(sil, "[gq][uü]([aáeéiíoó])", "11%1")
    sil = mw.ustring.gsub(sil, "[aáeéoó][iu]", "02")
    sil = mw.ustring.gsub(sil, "[iuü][aáeéoó]", "02")
    sil = mw.ustring.gsub(sil, "iu", "02")
    sil = mw.ustring.gsub(sil, "ui", "02")
    -- Nuclis vocàlics
    sil = mw.ustring.gsub(sil, "[aáeéiíoóuúü]", "0")
    -- Obertures
    sil = mw.ustring.gsub(sil, "[bcfgkp][lr]", "11")
    sil = mw.ustring.gsub(sil, "[drt]r", "11")
    sil = mw.ustring.gsub(sil, "ll", "11")
    sil = mw.ustring.gsub(sil, "ch", "11")
    sil = mw.ustring.gsub(sil, "^%l[%l1]", "11")
    sil = mw.ustring.gsub(sil, "%l0", "10")
    -- Codes
    sil = mw.ustring.gsub(sil, "%l", "2")
    -- 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
            motSil = motSil .. "·"
        end
        motSil = motSil .. mw.ustring.sub(mot,i,i)
        anterior = actual
    end
    return motSil
end

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

    -- dígrafs
    mot = mw.ustring.gsub(mot, "ch", "tʃ")
    mot = mw.ustring.gsub(mot, "ll", "ʎ")
    mot = mw.ustring.gsub(mot, "^p([st])", "%1")
    mot = mw.ustring.gsub(mot, "^gn", "n")
    mot = mw.ustring.gsub(mot, "qu?", "k")
    mot = mw.ustring.gsub(mot, "st·", "s·")
    -- lletra y
    mot = mw.ustring.gsub(mot, "^hie", "ye")
    mot = mw.ustring.gsub(mot, "^i([ao])", "y%1")
    mot = mw.ustring.gsub(mot, "y$", "i")
    mot = mw.ustring.gsub(mot, "y·", "i·")
    -- consonants
    local fon = {["b"] = "β", ["v"] = "β", ["d"] = "ð", ["g"] = "ɣ", ["h"] = "",
    	["ñ"] = "ɲ", ["r"] = "ɾ", ["y"] = "ʝ", ["z"] = "θ"}
    mot = mw.ustring.gsub(mot, ".", fon)
    mot = mw.ustring.gsub(mot, "^β", "b")
    mot = mw.ustring.gsub(mot, "([mn]·)β", "%1b")
    mot = mw.ustring.gsub(mot, "c([eéií])", "θ%1")
    mot = mw.ustring.gsub(mot, "c", "k")
    mot = mw.ustring.gsub(mot, "^ð", "d")
    mot = mw.ustring.gsub(mot, "([mnl]·)ð", "%1d")
    mot = mw.ustring.gsub(mot, "^x", "s")
    mot = mw.ustring.gsub(mot, "(·?)x", "k%1s")
    mot = mw.ustring.gsub(mot, "ɣ([eéií])", "x%1")
    mot = mw.ustring.gsub(mot, "ɣu([eéií])", "ɣ%1")
    mot = mw.ustring.gsub(mot, "^ɣ", "ɡ")
    mot = mw.ustring.gsub(mot, "([mn]·)ɣ", "%1ɡ")
    mot = mw.ustring.gsub(mot, "j", "x")
    mot = mw.ustring.gsub(mot, "n·f", "ɱ·f")
    mot = mw.ustring.gsub(mot, "n(·[bp])", "m%1")
    mot = mw.ustring.gsub(mot, "n(·[kɡx])", "ŋ%1")
    mot = mw.ustring.gsub(mot, "n·ʝ", "ɲ·ʝ")
    mot = mw.ustring.gsub(mot, "^ɾ", "r")
    mot = mw.ustring.gsub(mot, "([βlnst]·)ɾ", "%1r")
    mot = mw.ustring.gsub(mot, "ɾɾ", "r")
    mot = mw.ustring.gsub(mot, "ɾ·ɾ", "ɾ·r")
    mot = mw.ustring.gsub(mot, "s(·[βðɣmnɲlʎr])", "z%1")
    mot = mw.ustring.gsub(mot, "t·", "ð·")
    mot = mw.ustring.gsub(mot, "tʃ", "t͡ʃ")
    mot = mw.ustring.gsub(mot, "w", "gw")
    -- vocals
    mot = mw.ustring.gsub(mot, "ü", "w")
    mot = mw.ustring.gsub(mot, "i([aáeéoóuú])", "j%1")
    mot = mw.ustring.gsub(mot, "u([aáeéoóií])", "w%1")
    -- accent
    local mente = mw.ustring.find(mot, "·men·te$")
    if mente then
        mot = mw.ustring.sub(mot, 1, -8)
    end
    if mw.ustring.find(mot, "[áéíóú]") then
        mot = mw.ustring.gsub(mot, "·(%l-[áéíóú])", "ˈ%1")
    elseif mw.ustring.find(mot, "[nsaeiou]$") then
        mot = mw.ustring.gsub(mot, "·(%l-)·(%l-)$", "ˈ%1·%2")
    else
        mot = mw.ustring.gsub(mot, "·(%l-)$", "ˈ%1")
    end
    if not mw.ustring.find(mot, "ˈ") then -- monosíl·lab o accent en la primera
        mot = "ˈ" .. mot
    end
    mot = mw.ustring.gsub(mot, ".", senseDiacritics)
    if mente then
        mot = mw.ustring.gsub(mot, "ˈ", "ˌ") .. "ˈmen.te"
    end
    return '/' .. mw.ustring.gsub(mot, "·", ".") .. '/'
end

return export