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 la capçalera d’una entrada en francès.

local p = {}

local lang = {code = "fr", name = "francès", 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 or mw.title.getCurrentTitle().subpageText
	
	local data = {lang = lang, heads = {}, genders = {}, inflections = {}, categories = {}}
	local lema = args.lema; if lema == "" then lema = nil end
	table.insert(data.heads, lema)
	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](args, data, isLemma)
	else
		table.insert(data.categories, poscat .. " en " .. lang.name)
	end
	
	if args.cat then
		table.insert(data.categories, args.cat)
	end
	
	if args.bot then
		return require("Mòdul:lema").make_bot_list(data.inflections)
	else
		return require("Mòdul:lema").full_headword(data)
	end
end

-- Substantius i la seva flexió
pos_functions["Substantius"] = 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" or genere == "fm" 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
		table.insert(data.categories, "Substantius en " .. lang.name)
	end
	
	-- Plural
	if not (tipus == "?" or genere == "mp" or genere == "fp" or genere == "mfp") then
		local plural = args[2] or 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 incomptable"})
			else
				table.insert(data.inflections, {label = "incomptable"})
			end
		end
		if plural or not tipus then
			plural = plural or forma_plural_nominal(pagename)
			local plural2 = args.p2; if plural2 == "" then plural2 = nil end
			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)
			if not mw.title.new(plural).exists or (plural2 and not mw.title.new(plural2).exists) then
				table.insert(data.categories, "Termes en francès amb flexions a crear")
			end
		end
	end
	
	-- Femení
	local fem = args["f"]
	if fem == "" then
		fem = (pagename) .. "e"
	end
	if fem then
		table.insert(data.inflections, {label = "femení", fem, accel = "femenina-form-of gender-f"})
		if not mw.title.new(fem).exists then
			table.insert(data.categories, "Termes en francès amb flexions a crear")
		end
	end
end

-- Adjectius i la seva flexió
pos_functions["Adjectius"] = 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 not genere then
		if locucio then
			genere = "loc"
		elseif string.find(pagename, "e$") then
			genere = "i"
		else
			genere = "m"
		end
	end
	genere = string.gsub(genere, "mf", "i")
	genere = string.gsub(genere, "([^%-])p$", "%1%-p") -- conversió a "m-p", "f-p", "i-p"
	table.insert(data.genders, genere)
	
	local plural = args.p or forma_plural(pagename)
	local plural2 = args.p2; if plural2 == "" then plural2 = nil end
	local plural_fem = args.pf; if plural_fem == "" then plural_fem = nil end
	
	-- Gènere invariable
	if plural == "i" then
		table.insert(data.categories, "Adjectius en " .. lang.name)
		table.insert(data.categories, "Adjectius invariables en " .. lang.name)
		table.insert(data.inflections, {label = "plural invariable"})
	elseif genere == "i" then
		table.insert(data.categories, "Adjectius en " .. lang.name)
		table.insert(data.categories, "Adjectius invariables en " .. lang.name)
		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
		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 francès amb flexions a crear")
		end
	-- Doble gènere
	elseif genere == "m" then
		table.insert(data.categories, "Adjectius en " .. lang.name)
		local masc2 = args.m2; if masc2 == "" then masc2 = nil end
		local fem = args.f or (pagename) .. "e"
		local fem2 = args.f2; if fem2 == "" then fem2 = nil end
		plural_fem = plural_fem or forma_plural(fem)
		if masc2 then
			table.insert(data.inflections, {label = "alternatiu", accel = "alternativa-form-of gender-m", masc2})
			if not mw.title.new(masc2).exists then
				table.insert(data.categories, "Termes en francès amb flexions a crear")
			end
		end
		if fem2 then
			table.insert(data.inflections, {label = "femení", accel = "femenina-form-of gender-f", fem, fem2})
			if not mw.title.new(fem2).exists then
				table.insert(data.categories, "Termes en francès amb flexions a crear")
			end
		else
			table.insert(data.inflections, {label = "femení", accel = "femenina-form-of gender-f", fem})
		end
		if plural2 then
			table.insert(data.inflections, {label = "plural masculí", accel = "plural-form-of gender-m", plural, plural2})
		else
			table.insert(data.inflections, {label = "plural masculí", accel = "plural-form-of gender-m", plural})
		end
		table.insert(data.inflections, {label = "plural femení", accel = "plural-form-of gender-f origin-" .. fem, plural_fem})
		if not mw.title.new(plural).exists or not mw.title.new(plural_fem).exists or (plural2 and not mw.title.new(plural2).exists) then
			table.insert(data.categories, "Termes en francès amb flexions a crear")
		end
	-- Formes flexionades
	elseif genere == "f" then
		table.insert(data.categories, "Formes d'adjectius en femení en " .. lang.name)
		plural_fem = plural_fem or forma_plural(pagename)
		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

-- Forma plural
function forma_plural_nominal(base)
	if base:find("[^ ]+ [^ ]+") then
		local preposicions = {" à ", " au ", " aux ", " anti ", " arrière ", " autour ", " avec ", " contre ", " dans ",
				" de ", " d'", " des ", " du ", " en ", " par ", " pour ", " sans ", " sous ", " sur ", " vers "}
		for i, prep in ipairs(preposicions) do
			offset = mw.ustring.find(base, prep, 1, true)
			if offset then
				local part1 = mw.ustring.sub(base, 1, offset-1)
				local part2 = mw.ustring.sub(base, offset)
				local plural = forma_plural_nominal(part1)
				return plural .. part2
			end
		end
		local plurals = {}
		for part in mw.text.gsplit(base, " ", true) do
			table.insert(plurals, forma_plural(part))
		end
		return table.concat(plurals, " ")
	else
		return forma_plural(base)
	end
end

--  llista d'excepcions: fr:Annexe:Pluriels irréguliers en français
function forma_plural(mot)
	local m_util = require("Mòdul:utilitats")
	local plural
	-- plural invariable
	if mw.ustring.find(mot, "[sxz]$") then
		plural = mot
	-- au, eu, oeu -> +x
	elseif mw.ustring.find(mot, "[aeœ]u$") then
		excepcions = m_util.llista {"berimbau", "donau", "karbau", "landau", "pilau", "sarrau", "unau", "bleu", "émeu", "enfeu", "pneu"}
		if excepcions[mot] then
			plural = mot .. "s"
		else
			plural = mot .. "x"
		end
	-- ou -> +s
	elseif mw.ustring.find(mot, "ou$") then
		excepcions = m_util.llista {"bijou", "caillou", "chou", "genou", "hibou", "joujou", "pou"}
		if excepcions[mot] then
			plural = mot .. "x"
		else
			plural = mot .. "s"
		end
	-- al -> aux
	elseif mw.ustring.find(mot, "al$") then
		excepcions = m_util.llista {"acétal", "ammonal", "aval", "bal", "barbital", "cal", "captal", "carnaval", "cérémonial", "chacal", "chloral",
			"chrysocal", "copal", "dial", "dispersal", "éthanal", "festival", "foiral", "furfural", "futal", "gal", "galgal", "gardénal", "graal",
			"joual", "kraal", "kursaal", "matorral", "mescal", "mezcal", "méthanal", "minerval", "mistral", "nopal", "pal", "pascal",
			"hectopascal", "kilopascal", "penthotal", "phénobarbital", "pipéronal", "raval", "récital", "régal", "rétinal", "rital", "roberval",
			"roseval", "salicional", "sal", "santal", "saroual", "sial", "sisal", "sonal", "tagal", "tefal", "tergal", "thiopental", "tical",
			"tincal", "véronal", "zicral", "corral", "deal", "goal", "autogoal", "revival", "serial", "spiritual", "trial", "caracal", "chacal",
			"gavial", "gayal", "narval", "quetzal", "rorqual", "serval", "metical", "rial", "riyal", "ryal", "cantal", "emmental", "emmenthal",
			"floréal", "germinal", "prairial"}
		if excepcions[mot] then
			plural = mot .. "s"
		else
			plural = mw.ustring.gsub(mot, "al$", "aux")
		end
	-- ail -> +s
	elseif mw.ustring.find(mot, "ail$") then
		excepcions = m_util.llista {"corail", "bail", "émail", "soupirail", "travail", "vantail", "vitrail"}
		if excepcions[mot] then
			plural = mw.ustring.gsub(mot, "ail$", "aux")
		else
			plural = mot .. "s"
		end
	else
		plural = mot .. "s"
	end
	return plural
end

-- Funcions exportables per a proves
function p.plural(frame)
	local p = forma_plural_nominal(frame.args[1])
	return p
end

return p