Mòdul:la-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 l'enunciat d'un lema en llatí, incloent les categories corresponents ordenades. Dóna suport a les plantilles {{la-nom}}, {{la-verb}} i {{la-adj}}. Vegeu la documentació de les plantilles per a la seva utilització.

El mòdul es basa en Mòdul:lema pel format general d'un lema. S'invoca amb una única funció flex amb l'argument apropiat. Exemple: {{#invoke:la-lema|flex|Verbs}}

local p = {}

local lang = {code = "la", name = "llatí", sc = "Latn"}
local m_lema = require("Mòdul:lema")
local m_link = require("Mòdul:enllaç")
local pos_functions = {}

local function format_infl_classes(infl_classes)
	if #infl_classes < 1 then
		return ""
	end
	
	return "; ''" .. table.concat(infl_classes, "/") .. "''"
end

-- Format pels enunciats de llatí
local function format_la_enunciat(data, enunciat)
	if #enunciat > 0 then
		local headwords = {}
		for j, headword in ipairs(enunciat) do
			local data_enunciat = {}
			data_enunciat.lang = lang
			data_enunciat.heads = m_link.language_link({term = headword[1], alt = headword.alt, lang = lang}, false)
			data_enunciat.genders = headword.genders
			data_enunciat.categories = data.categories
			if j == #enunciat and not headword.label then
				data_enunciat.inflections = data.inflections
				table.insert(headwords, m_lema.full_headword(data_enunciat))
			else
				data_enunciat.inflections = {headword.label and {label=headword.label}}
				table.insert(headwords, m_lema.full_headword(data_enunciat))
			end
			data.categories = {}
		end
		return table.concat(headwords, ", ") .. format_infl_classes(enunciat.infl_classes)
	end
	
	return m_lema.full_headword(data) .. format_infl_classes(enunciat.infl_classes)
end
	
-- Treu una llista de formes per poder interpretar automàticament
local function make_bot_list(forms)
	local ret = ""
	
	for _, form in ipairs(forms) do
		if not (form.label:find("^1a") or form.label:find("^present")) then
			local form_title = m_link.sense_diacritics("la", form[1])
			ret = ret .. "* " .. form.label .. "=" .. form_title .. "(" .. form[1] .. ")\n"
		end
	end
	
	return ret
end

-- Funció d'entrada per mostrar l'enunciat del lema, 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 enunciat = {infl_classes = {}}
	local lema = args.lema; if lema == "" then lema = nil end
	
	local poscat = frame.args[1] or error("Falta especificar la categoria lèxica com a primer paràmetre.")
	if pos_functions[poscat] then
		local lema2 = pos_functions[poscat].func(args, data, enunciat)
		lema = lema or lema2
	else
		table.insert(data.categories, poscat .. " en llatí")
	end
	table.insert(data.heads, lema)
    
	if args.cat and args.cat ~= "" then
		table.insert(data.categories, args.cat)
	end
	
	if args.bot then
		if poscat == "Verbs" then
			return make_bot_list(enunciat)
		end
	else
		return format_la_enunciat(data, enunciat)
	end
end

pos_functions["Noms propis"] = {func = function(args, data, enunciat)
	local nominatiu = args[1]; if nominatiu == "" then nominatiu = pagename end
	local genitiu = args[2]; if genitiu == "" then genitiu = nil end
	local genere = args[3]; if genere == "" then genere = nil end
	
	table.insert(data.genders, (genere and genere or "?"))
	
	table.insert(data.categories, "Noms propis en llatí")
	
	if genitiu then
		table.insert(data.inflections, {label = "genitiu", genitiu})
	end
	
	return nominatiu
end
}

-- Informació per a substantius
pos_functions["Substantius"] = {func = function(args, data, enunciat)
	local nominatiu = args[1]; if nominatiu == "" then nominatiu = pagename end
	local genitiu = args[2]; if genitiu == "" then genitiu = nil end
	local genere = args[3]; if genere == "" then genere = nil end
	
	table.insert(data.genders, (genere and genere or "?"))
	
	if mw.ustring.find(pagename, "[^ ]+ [^ ]+") then
		table.insert(data.categories, "Locucions nominals en llatí")
	else
		table.insert(data.categories, "Substantius en llatí")
		if genitiu then
			table.insert(data.inflections, {label = "genitiu", genitiu})
		end
	end
	return nominatiu
end
}
	
-- Informació de verbs
pos_functions["Verbs"] = {func = function(args, data, enunciat)
	-- tipus d'enunciat: 5,4,3 formes p1-p2-i-pp-s amb p2,i opcionals; deponents sense supí
	local present1, present2, infinitiu, perfet, supi
	if args[5] then -- p1-p2-i-pp-s
		present1 = args[1]
		present2 = args[2]
		infinitiu = args[3]
		perfet = args[4]
		supi = args[5]
	elseif args[4] then
		if args[4]:find(" sum$") then -- deponent p1-p2-i-pp
			present1 = args[1]
			present2 = args[2]
			infinitiu = args[3]
			perfet = args[4]
		else -- normal p-i-pp-s
			present1 = args[1]
			infinitiu = args[2]
			perfet = args[3]
			supi = args[4]
		end
	elseif args[3] then -- 3 formes
		if args[3]:find(" sum$") then -- deponent p1-i-pp
			present1 = args[1]
			infinitiu = args[2]
			perfet = args[3]
		else -- normal p1-pp-s
			present1 = args[1]
			perfet = args[2]
			supi = args[3]
		end
	else
		present1 = args[1]
		require('Mòdul:utilitats').track("la-verb")
	end
	nota = args.nota; if nota == "" then nota = nil end
	if nota == nil and perfet ~= nil then
		if perfet:find(" sum$") then
			nota = "deponent"
		end
	end
	if present1 == "" or present1 == nil then present1 = pagename end
	if present2 == "" or present2 == "-" then present2 = nil end
	if infinitiu == "" or infinitiu == "-" then infinitiu = nil end
	if perfet == "" or perfet == "-" then perfet = nil end
	if supi == "" or supi == "-" then supi = nil end
	
	if pagename:find(" ") then
		table.insert(data.categories, "Locucions verbals en llatí")
	else
		table.insert(data.categories, "Verbs en llatí")
	end
	
	local nota_present = '<sup style="margin-left:0.3em; color:blue; cursor:help;" title="Com a enunciat verbal es tradueix per l\'infinitiu. Estrictament és la 1a persona singular del present d\'indicatiu actiu">?</sup>'
	if present2 then
		table.insert(enunciat, {label = "1a present" .. nota_present, present1})
		table.insert(enunciat, {label = "2a present", present2})
	else
		table.insert(enunciat, {label = "present" .. nota_present, present1})
	end
	if infinitiu then
		table.insert(enunciat, {label = "infinitiu", infinitiu})
	end
	if perfet then
		table.insert(enunciat, {label = "perfet", perfet:gsub(" sum$", ""), alt = perfet})
	end
	if supi then
		table.insert(enunciat, {label = "supí", supi})
	end
	if nota then
		table.insert(enunciat.infl_classes, nota)
	end
	
	-- Comprovació de flexions existents
	for _, form in ipairs(enunciat) do
		if not string.find(form[1], "[", 1, true) then
			local form_title = m_link.sense_diacritics(lang.code, form[1])
			if not mw.title.new(form_title).exists then
				table.insert(data.categories, "Termes en llatí amb flexions a crear")
				break
			end
		end
	end
	
	return present1
end
}

-- Informació d'adjectius
pos_functions["Adjectius"] = {func = function(args, data, enunciat)
	-- tipus d'enunciat: 3, 2, 1 terminacions
	if args[3] then
		table.insert(enunciat, {genders = {"m"}, args[1]})
		table.insert(enunciat, {genders = {"f"}, args[2]})
		table.insert(enunciat, {genders = {"n"}, args[3]})
	elseif args[2] then
		if args[2]:find("is$") then
			table.insert(data.genders, "m-f-n")
			table.insert(data.inflections, {label = "genitiu", args[2]})
		else
			table.insert(enunciat, {genders = {"m", "f"}, args[1]})
			table.insert(enunciat, {genders = {"n"}, args[2]})
		end
	else
		table.insert(data.genders, "?")
		table.insert(data.categories, "Manteniment plantilla la-adj")
	end
	
	if args.comp then
		table.insert(data.inflections, {label = "comparatiu", args.comp})
	end
	if args.sup then
		table.insert(data.inflections, {label = "superlatiu", args.sup})
	end
	
	if mw.ustring.find(pagename, "[^ ]+ [^ ]+") then
		table.insert(data.categories, "Locucions adjectivals en llatí")
		return nil
	else
		table.insert(data.categories, "Adjectius en llatí")
	end
	
	return args[1]
end
}

return p