Mòdul:forma flexionada

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 per presentar definicions de formes flexionades, declinades o conjugades. Les definicions es presenten en cursiva i enllaçant al lema principal. Dóna suport a la família de plantilla "forma-" de la Categoria:Plantilles de definicions de flexió. Vegeu la documentació de les plantilles per a la seva utilització.

local p = {}

local m_links = require("Module:enllaç")

local inflection_tags = {
	-- Gènere
	["m"] = "masculí",
	["f"] = "femení",
	["n"] = "neutre",
	["c"] = "comú",
	
	-- Nombre
	["s"] = "singular",
	["p"] = "plural",
	["d"] = "dual",

	-- Gènere i nombre
	["ms"] = "masculí singular",
	["mp"] = "masculí plural",
	["fs"] = "femení singular",
	["fp"] = "femení plural",
	["ns"] = "neutre singular",
	["np"] = "neutre plural",
	
	-- Estat
	["def"] = "definit",
	["indef"] = "indefinit",
	
	-- Declinació
	["abl"] = "ablatiu",
	["abs"] = "absolutiu",
	["ac"] = "acusatiu",
	["al·l"] = "al·latiu",
	["aldir"] = "al·latiu direccional",
	["ben"] = "benefactiu",
	["caus"] = "causal",
	["com"] = "comitatiu",
	["dat"] = "datiu",
	["erg"] = "ergatiu",
	["gen"] = "genitiu",
	["genloc"] = "genitiu locatiu",
	["iness"] = "inessiu",
	["instr"] = "instrumental",
	["loc"] = "locatiu",
	["nom"] = "nominatiu",
	["partt"] = "partitiu",
	["prol"] = "prolatiu",
	["term"] = "terminatiu",
	["voc"] = "vocatiu",

	-- Conjugació
	-- Persona
	["1"] = "primera persona singular",
	["2"] = "segona persona singular",
	["3"] = "tercera persona singular",
	["4"] = "primera persona plural",
	["5"] = "segona persona plural",
	["6"] = "tercera persona plural",
 
	-- Temps
	["pres"] = "del present",
	["imperf"] = "de l'imperfet",
	["perf"] = "del perfet",
	["pret"] = "del pretèrit",
	["pass"] = "del passat",
	["fut"] = "del futur",
	["cond"] = "del condicional",

	-- Mode
	["imp"] = "de l'imperatiu",
	["ind"] = "d'indicatiu",
	["subj"] = "de subjuntiu",

	-- Veu
	["act"] = "actiu",
	["pas"] = "passiu",

	-- Impersonals
	["inf"] = "infinitiu",
	["part"] = "participi",
	["ger"] = "gerundi"
}

local pronoms = {}
pronoms["ca"] = {"jo", "tu", "[[ell]], [[ella]], [[vostè]]",
		"nosaltres", "[[vosaltres]], [[vós]]", "[[ells]], [[elles]], [[vostès]]"}
pronoms["de"] = {"ich", "du", "[[er]], [[sie]], [[es]]",
		"wir", "ihr", "sie"}
pronoms["fr"] = {"[[je]]/[[j']]", "tu", "[[il]], [[elle]], [[on]]",
		"nous", "vous", "[[ils]], [[elles]]"}
pronoms["it"] = {"io", "tu", "[[lui]]/[[lei]], [[esso]]/[[essa]]",
		"noi", "voi", "[[loro]], [[essi]]/[[esse]]"}
pronoms["oc"] = {"[[ieu]], [[jo]]", "tu", "[[el]]/[[eth]], [[ela]]/[[era]]",
		"[[nosautres]]/[[nosati]], [[nosautras]]/[[nosates]]", "[[vosautres]]/[[vosati]], [[vosautras]]/[[vosates]]", "[[eles]]/[[eri]], [[elas]]/[[eres]]"}
pronoms["pt"] = {"eu", "tu", "[[ele]], [[ela]], [[você]]",
		"nós", "vós", "[[eles]], [[elas]], [[vocês]]"}
pronoms["roa-oca"] = {"[[io]], [[yo]], [[jo]]", "tu", "[[él]], [[eyl]], [[ell]]",
		"[[nós]], [[nosaltres]]", "[[vós]], [[vosaltres]]", "[[éls]], [[eyls]], [[ells]]"}

local function get_terminfo(frame)
	local args = frame:getParent().args
	local iargs = frame.args
	
	local term = iargs["term"] or args[2]; if term == "" then term = nil end
	local alt = args["alt"]; if alt == "" then alt = nil end
	local langcode = iargs["lang"] or args[1]; if langcode == "" then langcode = nil end
	local sc = iargs["sc"] or args["sc"]; if sc == "" then sc = nil end
	local id = iargs["id"] or args["id"]; if id == "" then id = nil end
	local gloss = args["glossa"] or args["t"]; if gloss == "" then gloss = nil end
	local tr = args["tr"]; if tr == "" then tr = nil end
	
	if langcode and not require("Module:llengua").existeix(langcode) then
		error("Codi de llengua incorrecte")
	end
	
	local lang = require("Module:llengua").getByCode(langcode or "mul")
	
	return {term = term, alt = alt, lang = lang, sc = sc, id = id, gloss = gloss, tr = tr}
end

local function get_categories(frame, lang)
	local args = frame:getParent().args
	local iargs = frame.args
	
	local cat = iargs["cat"] or args["cat"]; if cat == "" then cat = nil end
	local cat2 = iargs["cat2"] or args["cat2"]; if cat2 == "" then cat2 = nil end
	
	local categories = {}
	if cat then table.insert(categories, cat) end
	if cat2 then table.insert(categories, cat2) end
	
	local ret = ""
	if #categories > 0  then
		ret = require("Module:utilitats").format_categories(categories, lang, nil)
	end
	
	return ret
end
	
function p.format_t(text, terminfo, categories)
	if not terminfo.term then
		if mw.title.getCurrentTitle().nsText == "Plantilla" then
			terminfo.term = "terme"
		else
			error("No hi ha cap terme per enllaçar-hi.")
		end
	end
	
	if not text then
		error("No s'ha proporcionat cap definició.")
	end
	
	return
		"<i>" .. text .. "</i> "
		.. m_links.full_link(terminfo, "negreta", nil)
		.. categories
end

function p.form_of_t(frame)
	local text = frame.args[1]; if text == "" then text = nil end
	local terminfo = get_terminfo(frame)
	local categories = get_categories(frame, terminfo.lang)
	
	return p.format_t(text, terminfo, categories)
end

function p.inflection_t(frame)
	local args = frame:getParent().args
	local terminfo = get_terminfo(frame)
	local categories = get_categories(frame, terminfo.lang)
	
	local inflections = {}
	local i = 3
	local infl = args[i] or 'forma declinada'
	
	while infl do
		if infl ~= "" then
			table.insert(inflections, inflection_tags[infl] or infl)
			local person = tonumber(infl)
			-- tonumber("inf") returns number infinite instead of expected nil
			if person and person < 7 and pronoms[terminfo.lang.code] then
				table.insert(inflections, "(" .. m_links.language_link({term = pronoms[terminfo.lang.code][person], lang = terminfo.lang}) .. ")")
			end
		end
		
		i = i + 1
		infl = args[i]
	end
	local ret = table.concat(inflections, " ")
	ret = string.gsub(ret, " , ", ", ")
	return p.format_t(ret .. " de", terminfo, categories)
end

function p.form_eo_t(frame)
	local terminfo = get_terminfo(frame)
	local categories = get_categories(frame, terminfo.lang)
	
	local args = frame:getParent().args
	local text = args[2]; if text == "" then text = nil end
	terminfo.term = args[1] or mw.title.getCurrentTitle().subpageText
	
	if not text then
		if terminfo.term:find("j$") then
			text = 'forma plural'
			terminfo.term = terminfo.term:gsub("j$", "")
		elseif terminfo.term:find("jn$") then
			text = 'acusatiu plural'
			terminfo.term = terminfo.term:gsub("jn$", "")
		elseif terminfo.term:find("n$") then
			text = 'acusatiu'
			terminfo.term = terminfo.term:gsub("n$", "")
		elseif terminfo.term:find("as$") then
			text = 'present'
			terminfo.term = terminfo.term:gsub("as$", "i")
		elseif terminfo.term:find("is$") then
			text = 'passat'
			terminfo.term = terminfo.term:gsub("is$", "i")
		elseif terminfo.term:find("os$") then
			text = 'futur'
			terminfo.term = terminfo.term:gsub("os$", "i")
		elseif terminfo.term:find("us$") then
			text = 'condicional'
			terminfo.term = terminfo.term:gsub("us$", "i")
		elseif terminfo.term:find("u$") then
			text = 'volitiu'
			terminfo.term = terminfo.term:gsub("u$", "i")
		elseif terminfo.term:find("t[aoe]$") then
			text = 'participi'
			if terminfo.term:find("nt[aoe]$") then
				text = text .. " actiu"
			else
				text = text .. " passiu"
			end
			if terminfo.term:find("to$") then
				text = text .. " nominal"
			elseif terminfo.term:find("te$") then
				text = text .. " adverbial"
			end
			if terminfo.term:find("an?t[aoe]$") then
				text = text .. " present"
			elseif terminfo.term:find("in?t[aoe]$") then
				text = text .. " passat"
			elseif terminfo.term:find("on?t[aoe]$") then
				text = text .. " futur"
			end
			terminfo.term = terminfo.term:gsub("[aio]n?t[aoe]$", "i")
		else
			text = 'forma desconeguda'
		end
	end
	
	return p.format_t(text .. " de", terminfo, categories)
end

return p