Mòdul:it-lema

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]


Aquest mòdul presenta un lema en italià amb les indicacions de flexió i les categories corresponents ordenades. Actualment dóna suport a les plantilles {{it-nom}}, {{it-adj}} i {{it-verb}}. Vegeu la documentació de les plantilles per a la seva utilització.

El mòdul es recolza en Mòdul:it-general per a les funcions generals d'ordenació en italià. S'invoca amb una única funció flex amb l'argument apropiat. Exemple: {{#invoke:it-lema|flex|Substantius}}

Genera les formes en femení i en plural a partir d'unes regles vàlides en la majoria de casos. Genera també les etiquetes necessàries per a l'edició accelerada de formes flexionades.

local p = {}

local lang = {code = "it", name = "italià", sc = "Latn"}
local pos_functions = {}

-- Funció d'entrada per mostrar el lema flexionat, l'única que s'invoca des d'una plantilla
function p.flex(frame)
	local args = frame:getParent().args
	pagename = args.pagename
	if not pagename or pagename == "" then
		pagename = mw.title.getCurrentTitle().subpageText
	end
	
	local data = {lang = lang, heads = {}, genders = {}, inflections = {}, categories = {}}
	
	local headword = args.lema; if headword == "" then headword = nil end
	table.insert(data.heads, headword)
	local isLemma = frame.args['forma'] == nil and true or nil
	
	local poscat = frame.args[1] or error("Falta especificar la categoria lèxica com a primer paràmetre.")
	if pos_functions[poscat] then
		pos_functions[poscat].func(args, data, isLemma)
	else
		table.insert(data.categories, poscat .. " en " .. lang.name)
	end
	if args.cat and args.cat ~= "" then
		table.insert(data.categories, args.cat)
	end
	
	if args.bot then
		return require("Module:lema").make_bot_list(data.inflections)
	else
		return require("Module:lema").full_headword(data)
	end
end

-- Informació de flexió per a substantius
pos_functions["Substantius"] = {func = function(args, data, isLemma)
	
	--[[ Codis gènere-nombre:
		"m", "f", "mf"
		"m-p", "f-p", "mf-p" pluralia tantum
		"m-s", "f-s", "mf-s" només o normalment en singular
		"m-i", "f-i", "mf-i" invariable en nombre
		"m-?", "f-?". "mf-?" sense plural conegut
		"mp", "fp", "mfp"    flexionats en plural
	]]
	local genere = args[1] or ""
	local tipus = nil
	local gn = mw.text.split(genere, "-")
	if #gn > 1 then
		genere = gn[1]
		tipus = gn[2]
	end
	if genere == "" then
		table.insert(data.genders, "?")
	else
		local generes = mw.text.split(genere, "")
		table.insert(data.genders, table.concat(generes, "-")) -- conversió a "m", "f", "m-f", "m-p", "f-p", "m-f-p"
	end
	
    -- Categoria gramatical
    if mw.ustring.find(pagename, "[^ ]+ [^ ]+") then
    	if genere:find("p$") then
    		table.insert(data.categories, "Formes de locucions nominals en " .. lang.name)
    	else
			table.insert(data.categories, "Locucions nominals en " .. lang.name)
		end
    elseif genere == "mf" then
		table.insert(data.categories, "Substantius femenins i masculins en " .. lang.name)
	elseif genere == "mfp" then
		table.insert(data.categories, "Formes de substantius en plural en " .. lang.name)
    elseif genere == "m" then
        table.insert(data.categories, "Substantius masculins en " .. lang.name)
	elseif genere == "mp" then
		table.insert(data.categories, "Formes de substantius en plural en " .. lang.name)
	elseif genere == "f" then
		if isLemma then
       		table.insert(data.categories, "Substantius femenins en " .. lang.name)
       	else
       		table.insert(data.categories, "Formes de substantius en femení en " .. lang.name)
       	end
	elseif genere == "fp" then
		table.insert(data.categories, "Formes de substantius en plural en " .. lang.name)
	else
		if isLemma then
			table.insert(data.categories, "Substantius en " .. lang.name)
		else
			table.insert(data.categories, "Formes de substantius en " .. lang.name)
		end
    end
	
	-- Plural
	if not (tipus == "?" or genere == "mp" or genere == "fp" or genere == "mfp") then
		local plural = args.p; if plural == "" then plural = nil end
		if tipus == "i" then
			table.insert(data.inflections, {label = "plural invariable"})
		elseif tipus == "p" then
			table.insert(data.inflections, {label = "plurale tantum"})
		elseif tipus == "s" then
			if plural then
				table.insert(data.inflections, {label = "normalment en singular"})
			else
				table.insert(data.inflections, {label = "només en singular"})
			end
		end
		if plural or not tipus then
			local p, p2 = forma_plural_nominal(pagename, genere)
			plural = plural or p
			local plural2 = args.p2 or p2; if plural2 == "" then plural2 = nil end
			local plural_fem = args.pf or p2; if plural_fem == "" then plural_fem = nil end
			if genere == "mf" and plural_fem then
				table.insert(data.inflections, {label = "plural masculí", plural, accel = "plural-form-of gender-m"})
				table.insert(data.inflections, {label = "plural femení", plural_fem, accel = "plural-form-of gender-f"})
			else
				local infl_parts = {label = "plural", accel = "plural-form-of gender-" .. genere}
				table.insert(infl_parts, plural)
				if plural2 then
					table.insert(infl_parts, plural2)
				end
				table.insert(data.inflections, infl_parts)
			end
			if not mw.title.new(plural).exists or (plural2 and not mw.title.new(plural2).exists) or (plural_fem and not mw.title.new(plural_fem).exists) then
				table.insert(data.categories, "Termes en italià amb flexions a crear")
			end
		end
	end
	
	-- Femení
	local fem = args["f"]
	if fem == "" then
		fem = forma_femenina(pagename)
	end
	if fem then
		table.insert(data.inflections, {label = "femení", fem, accel = "femenina-form-of gender-f"})
    end
end
}

-- Informació de flexió per a adjectius
pos_functions["Adjectius"] = {func = function(args, data, isLemma)
	-- Gènere: m (masculí), i (invariable)
	-- Gènere flexionats: f, mp, fp, ip
	local genere = args[1]; if genere == "" then genere = nil end
	local locucio = mw.ustring.find(pagename, "[ ']")
	if genere == nil then
		if locucio then
			genere = "loc"
		else
			genere = string.find(pagename, "e$") and "i" or "m"
		end
	elseif genere == "mf" then
		genere = "i"
	elseif genere == "mfp" then
		genere = "ip"
	end
	genere = string.gsub(genere, "([^%-])p$", "%1%-p") -- conversió a "m-p", "f-p", "i-p"
	table.insert(data.genders, genere)
	
	--[[ Plurals:
		p= plural masculí o plural de gènere invariable
		p2= segon plural masculí o invariable
		pf = plural femení
	]]
	local p, p2 = forma_plural(pagename, genere)
	local plural = args.p or p
	local plural2 = args.p2; if plural2 == nil then plural2 = p2 end
	local plural_fem = args.pf; if plural_fem == "" then plural_fem = nil end
	
	-- Gènere invariable
	if genere == "i" then
		table.insert(data.categories, "Adjectius en italià")
		table.insert(data.categories, "Adjectius invariables en " .. lang.name)
		if plural_fem == nil then plural_fem = p2 end
		if plural_fem ~= "" then
			table.insert(data.inflections, {label = "plural masculí", accel = "plural-form-of gender-m", plural})
			table.insert(data.inflections, {label = "plural femení", accel = "plural-form-of gender-f", plural_fem})
		elseif plural2 ~= "" then
			table.insert(data.inflections, {label = "plural", accel = "plural-form-of gender-i", plural, plural2})
		else
			table.insert(data.inflections, {label = "plural", accel = "plural-form-of gender-i", plural})
		end
	-- Doble gènere
	elseif genere == "m" then
		table.insert(data.categories, "Adjectius en " .. lang.name)
		local fem = args.f or forma_femenina(pagename)
		local pf, pf2 = forma_plural(fem, "f")
		plural_fem = plural_fem or pf
		table.insert(data.inflections, {label = "femení", accel = "femenina-form-of gender-f", fem})
		if plural_fem == plural then
			table.insert(data.inflections, {label = "plural invariable", accel = "plural-form-of gender-i", plural})
		else
			if plural2 == "" then
				table.insert(data.inflections, {label = "plural masculí", accel = "plural-form-of gender-m", plural})
			else
				table.insert(data.inflections, {label = "plural masculí", accel = "plural-form-of gender-m", plural, plural2})
			end
			table.insert(data.inflections, {label = "plural femení", accel = "plural-form-of gender-f origin-" .. fem, plural_fem})
		end
		if not mw.title.new(plural).exists or not mw.title.new(fem).exists or not mw.title.new(plural_fem).exists then
			table.insert(data.categories, "Termes en italià amb flexions a crear")
		end
	-- Formes flexionades
	elseif genere == "f" then
		table.insert(data.categories, "Formes d'adjectius en femení en " .. lang.name)
		local pf, pf2 = forma_plural(pagename, "f")
		plural_fem = plural_fem or pf
		table.insert(data.inflections, {label = "plural", accel = "plural-form-of gender-f", plural_fem})
	elseif genere == "m-p" or genere == "f-p" or genere == "i-p" then
		table.insert(data.categories, "Formes d'adjectius en plural en " .. lang.name)
	elseif genere == "loc" then
		table.insert(data.categories, "Locucions adjectivals en " .. lang.name)
	else
		table.insert(data.categories, "Adjectius en " .. lang.name)
	end
end
}

function forma_femenina(base)
    local fem = base
    fem = mw.ustring.gsub(fem, "a$", "essa")
    fem = mw.ustring.gsub(fem, "[eo]$", "a") -- algunes excepcions fan -essa
    fem = mw.ustring.gsub(fem, "tora$", "trice") -- amb algunes excepcions
    return fem
end

-- Informació de verbs
pos_functions["Verbs"] = {func = function(args, data, isLemma)
	local tipus = args[1] or ""
	local titol = pagename
	formaPron = tipus:find("p")
	locucio = titol:find(" ")
	
	if locucio then
		table.insert(data.categories, "Locucions verbals en " .. lang.name)
	elseif formaPron then
		table.insert(data.categories, "Verbs pronominals en " .. lang.name)
	else
		table.insert(data.categories, "Verbs en " .. lang.name)
	end
	
	tipus = string.gsub(tipus, "[^atipm-]", "")
	
	if tipus ~= "" then
		local totsTipus = mw.text.split(tipus, "")
		for i, tipusx in ipairs(totsTipus) do
			if tipusx ~= "-" then
				table.insert(data.genders, "v" .. tipusx)
			end
		end
	end
	
	local flexPron = args["p"]; if flexPron == "" then flexpron = nil end
	local defectiu = args.defectiu; if defectiu ~= nil then defectiu = true end
	
	if defectiu then
		table.insert(data.inflections, {label = "defectiu"})
	end
	
	if flexPron then
		table.insert(data.inflections, {label = "pronominal", flexPron})
	end
	
end
}

-- Forma plural
function forma_plural_nominal(headword, gen)
	if headword:find("[^ ]+ [^ ]+") then
		local preposicions = {" a ", " al ", " allo ", " con ", " da ", " del ", " della ", " dello ", " dell'", " di ", " fra ",
			" in ", " per ", " senza ", " sotto ", " su ", " tra "}
		for i, prep in ipairs(preposicions) do
			offset = mw.ustring.find(headword, prep, 1, true)
			if offset then
				local part1 = mw.ustring.sub(headword, 1, offset-1)
				local part2 = mw.ustring.sub(headword, offset)
				local plural = forma_plural_nominal(part1, gen)
				return plural .. part2
			end
		end
		local plurals = {}
		for part in mw.text.gsplit(headword, " ", true) do
			local partplural = forma_plural(part, gen)
			table.insert(plurals, partplural)
		end
		return table.concat(plurals, " ")
	else
		return forma_plural(headword, gen)
	end
end

function forma_plural(mot, genere)
    local plural = mot
    local plural2 = ""
    if mw.ustring.find(mot, "a$") and genere == "m" then
        plural = mw.ustring.gsub(mot, "a$", "i")
    elseif mw.ustring.find(mot, "a$") and (genere == "mf" or genere == "i") then -- ista
        plural = mw.ustring.gsub(mot, "a$", "i")
        plural2 = mw.ustring.gsub(mot, "a$", "e")
    elseif mw.ustring.find(mot, "a$") then
        plural = mw.ustring.gsub(plural, "([cg])a$", "%1he") -- inclusió h servil
        plural = mw.ustring.gsub(plural, "([^aàeèéiìoòóuù][cg])ia$", "%1e") --eliminació i servil
        plural = mw.ustring.gsub(plural, "a$", "e")
    elseif mw.ustring.find(mot, "[^i]e$") then -- ie és invariable
        plural = mw.ustring.gsub(mot, "e$", "i")
        -- TODO: algunes excepcions fan -ore o -ione
    elseif mw.ustring.find(mot, "o$") then
        plural = mw.ustring.gsub(plural, "fico$", "fici") -- excepció, n'hi ha alguna més
        plural = mw.ustring.gsub(plural, "([cg])o$", "%1hi") -- inclusió h servil
        plural = mw.ustring.gsub(plural, "io$", "i") --eliminació i servil
        plural = mw.ustring.gsub(plural, "o$", "i")
    end
    -- altrament, si no acaba en [aeo], és invariable
    -- TODO: els monosíl·labs també són invariables
    return plural, plural2
end

-- Funcions exportables per a proves
function p.fem(frame)
	return forma_femenina(frame.args[1])
end
 
function p.plural(frame)
	return forma_plural(frame.args[1])
end

return p