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 implementa les plantilles que mostren un lema en anglès i la seva línia de flexió. Actualment funciona per {{en-nom}}, {{en-adj}} i {{en-adv}}. Vegeu la documentació d'aquestes plantilles per a més informació.

local p = {}

local lang = {code = "en", name = "anglès", sc = "Latn"}
local pos_functions = {}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function p.show(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 = {}, inflections = {}, categories = {}}
	local head = args.lema; if head == "" then head = nil end
	table.insert(data.heads, head)
	
	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)
	else
		table.insert(data.categories, poscat .. " en " .. lang.name)
	end
	
	if args.bot then
		return require("Module:lema").make_bot_list(data.inflections)
	else
		return require("Module:lema").full_headword(data)
	end
end

-- This function does the common work between adjectives and adverbs
function make_comparatives(params, data)
	local comp_parts = {label = "comparatiu", accel = "comparativa-form-of"}
	local sup_parts = {label = "superlatiu", accel = "superlativa-form-of"}
	
	if #params == 0 then
		table.insert(params, {"more"})
	end
	
	-- To form the stem, replace -(e)y with -i and remove a final -e.
	local stem = pagename:gsub("([^aeiou])e?y$", "%1i"):gsub("e$", "")
	
	-- Go over each parameter given and create a comparative and superlative form
	for i, val in ipairs(params) do
		local comp = val[1]
		local sup = val[2]
		
		if comp == "more" and pagename ~= "many" and pagename ~= "much" then
			table.insert(comp_parts, "[[more]] " .. pagename)
			table.insert(sup_parts, "[[most]] " .. pagename)
		elseif comp == "further" and pagename ~= "far" then
			table.insert(comp_parts, "[[further]] " .. pagename)
			table.insert(sup_parts, "[[furthest]] " .. pagename)
		elseif comp == "er" then
			table.insert(comp_parts, stem .. "er")
			table.insert(sup_parts, stem .. "est")
		else
			-- If the full comparative was given, but no superlative, then
			-- create it by replacing the ending -er with -est.
			if not sup then
				if comp:find("er$") then
					sup = comp:gsub("er$", "est")
				else
					error("La forma superlativa de \"" .. comp .. "\" no es pot generar automàticament. Especifiqueu-la amb el paràmetre \"sup" .. (i == 1 and "" or i) .. "=\"")
				end
			end
			
			table.insert(comp_parts, comp)
			table.insert(sup_parts, sup)
		end
	end
	
	table.insert(data.inflections, comp_parts)
	table.insert(data.inflections, sup_parts)
end

pos_functions["Adjectius"] = {func = function(args, data)
	local shift = 0

	if string.find(pagename, "[^ ]+ [^ ]+") then
		table.insert(data.categories, "Locucions adjectivals en " .. lang.name)
	else
		table.insert(data.categories, "Adjectius en " .. lang.name)
	end
	
	-- If the first parameter is ?, then don't show anything, just return.
	if args[1] == "?" then
		return
	-- If the first parameter is -, then move all parameters up one position.
	elseif args[1] == "-" then
		shift = 1
	end
	
	-- Gather all the comparative and superlative parameters.
	local params = {}
	local i = 1
	
	while true do
		local comp = args[i + shift]; if comp == "" then comp = nil end
		local sup = args["sup" .. (i == 1 and "" or i)]; if sup == "" then sup = nil end
		
		if not comp then
			do break end
		end
		
		table.insert(params, {comp, sup})
		i = i + 1
	end
	
	if shift == 1 then
		-- If the first parameter is "-" but there are no parameters,
		-- then show "not comparable" only and return. If there are parameters,
		-- then show "not generally comparable" before the forms.
		if #params == 0 then
			table.insert(data.inflections, {label = "no comparable"})
			return
		else
			table.insert(data.inflections, {label = "normalment no comparable"})
		end
	end
	
	-- Process the parameters
	make_comparatives(params, data)
end
}

pos_functions["Adverbis"] = {func = function(args, data)
	local shift = 0

	if string.find(pagename, "[^ ]+ [^ ]+") then
		table.insert(data.categories, "Locucions adverbials en " .. lang.name)
	else
		table.insert(data.categories, "Adverbis en " .. lang.name)
	end
	
	-- If the first parameter is ?, then don't show anything, just return.
	if args[1] == "?" then
		return
	-- If the first parameter is -, then move all parameters up one position.
	elseif args[1] == "-" then
		shift = 1
	end
	
	-- Gather all the comparative and superlative parameters.
	local params = {}
	local i = 1
	
	while true do
		local comp = args[i + shift]; if comp == "" then comp = nil end
		local sup = args["sup" .. (i == 1 and "" or i)]; if sup == "" then sup = nil end
		
		if not comp then
			do break end
		end
		
		table.insert(params, {comp, sup})
		i = i + 1
	end
	
	if shift == 1 then
		-- If the first parameter is "-" but there are no parameters,
		-- then show "not comparable" only and return. If there are parameters,
		-- then show "not generally comparable" before the forms.
		if #params == 0 then
			table.insert(data.inflections, {label = "no comparable"})
			return
		else
			table.insert(data.inflections, {label = "normalment no comparable"})
		end
	end
	
	-- Process the parameters
	make_comparatives(params, data)
end
}

pos_functions["Substantius"] = {func = function(args, data)
	-- Gather all the plural parameters from the numbered parameters.
	local plurals = {}
	local i = 1

	if string.find(pagename, "[^ ]+ [^ ]+") then
		table.insert(data.categories, "Locucions nominals en " .. lang.name)
	else
		table.insert(data.categories, "Substantius en " .. lang.name)
	end
	
	while true do
		local pl = args[i]; if pl == "" then pl = nil end
		
		if not pl then
			break
		end
		
		table.insert(plurals, pl)
		i = i + 1
	end
	
	-- Decide what to do next...
	local mode = nil
	
	if plurals[1] == "?" or plurals[1] == "!" or plurals[1] == "-" or plurals[1] == "~" then
		mode = plurals[1]
		table.remove(plurals, 1) -- Remove the mode parameter
	end
	
	-- Plural is unknown
	if mode == "?" then
		return
	-- Plural is not attested
	elseif mode == "!" then
		table.insert(data.inflections, {label = "plural no atestat"})
		return
	-- Uncountable noun; may occasionally have a plural
	elseif mode == "-" then
		
		-- If plural forms were given explicitly, then show "usually"
		if #plurals > 0 then
			table.insert(data.inflections, {label = "normalment incomptable"})
		else
			table.insert(data.inflections, {label = "incomptable"})
		end
	-- Mixed countable/uncountable noun, always has a plural
	elseif mode == "~" then
		table.insert(data.inflections, {label = "comptable i incomptable"})
		
		-- If no plural was given, add a default one now
		if #plurals == 0 then
			plurals = {"s"}
		end
	-- The default, always has a plural
	else
		-- If no plural was given, add a default one now
		if #plurals == 0 then
			plurals = {"s"}
		end
	end
	
	-- If there are no plurals to show, return now
	if #plurals == 0 then
		return
	end
	
	-- There are plural forms to show, so show them
	local pl_parts = {label = "plural", accel = "plural-form-of"}
	
	local stem = pagename
	
	for i, pl in ipairs(plurals) do
		if pl == "s" then
			table.insert(pl_parts, stem .. "s")
			if not mw.title.new(stem .. "s").exists then
				table.insert(data.categories, "Termes en anglès amb flexions a crear")
			end
		elseif pl == "es" then
			table.insert(pl_parts, stem .. "es")
			if not mw.title.new(stem .. "es").exists then
				table.insert(data.categories, "Termes en anglès amb flexions a crear")
			end
		else
			table.insert(pl_parts, pl)
			if not mw.title.new(pl).exists then
				table.insert(data.categories, "Termes en anglès amb flexions a crear")
			end
		end
	end
	
	table.insert(data.inflections, pl_parts)
end
}

pos_functions["Verbs"] = {func = function(args, data)
	-- Get parameters
	local par1 = args[1]; if par1 == "" then par1 = nil end
	local par2 = args[2]; if par2 == "" then par2 = nil end
	local par3 = args[3]; if par3 == "" then par3 = nil end
	local par4 = args[4]; if par4 == "" then par4 = nil end
	
	local pres_3sg_forms = {label = "3a persona singular present"}
	local pres_ptc_forms = {label = "gerundi"}
	local past_forms = {label = "passat"}
	local pres_3sg_form = par1 or pagename .. "s"
	local pres_ptc_form = par2 or pagename .. "ing"
	local past_form = par3 or pagename .. "ed"
	local pres_3sg_qual = args["pres_3sg_qual"]; if pres_3sg_qual == "" then pres_3sg_qual = nil end
	local pres_ptc_qual = args["pres_ptc_qual"]; if pres_ptc_qual == "" then pres_ptc_qual = nil end
	local past_qual = args["past_qual"]; if past_qual == "" then past_qual = nil end
	
	if par1 and par2 and par3 then
		pres_3sg_form = par1
		pres_ptc_form = par2
		past_form = par3
	elseif par1 then
		if par1 == "es" then
			pres_3sg_form = pagename .. "es"
			pres_ptc_form = pagename .. "ing"
			past_form = pagename .. "ed"
		elseif par1 == "ies" then
			if not mw.ustring.find(pagename, "y$") then
				error("El primer paràmetre \"ies\" és incoherent amb un verb que no acabi en -y.")
			end
			
			local stem = mw.ustring.gsub(pagename, "y$", "")
			pres_3sg_form = stem .. "ies"
			pres_ptc_form = stem .. "ying"
			past_form = stem .. "ied"
		elseif par1 == "d" then
			pres_3sg_form = pagename .. "s"
			pres_ptc_form = pagename .. "ing"
			past_form = pagename .. "d"
		else
			pres_3sg_form = pagename .. "s"
			pres_ptc_form = par1 .. "ing"
			past_form = par1 .. "ed"
		end
	end
	
	table.insert(pres_ptc_forms, {term = pres_ptc_form, qualifiers = {pres_ptc_qual}})
	table.insert(pres_3sg_forms, {term = pres_3sg_form, qualifiers = {pres_3sg_qual}})
	table.insert(past_forms, {term = past_form, qualifiers = {past_qual}})
		
	if not mw.title.new(pres_ptc_form).exists or not mw.title.new(pres_3sg_form).exists or not mw.title.new(past_form).exists then
		table.insert(data.categories, "Termes en anglès amb flexions a crear")
	end
	
	-- Present 3rd singular
	local i = 2
	
	while args["pres_3sg" .. i] do
		local form = args["pres_3sg" .. i]; if form == "" then form = nil end
		local qual = args["pres_3sg" .. i .. "_qual"]; if qual == "" then qual = nil end
		
		if form then
			table.insert(pres_3sg_forms, {term = form, qualifiers = {qual}})
		end
		
		i = i + 1
	end
	
	-- Present participle
	local i = 2
	
	while args["pres_ptc" .. i] do
		local form = args["pres_ptc" .. i]; if form == "" then form = nil end
		local qual = args["pres_ptc" .. i .. "_qual"]; if qual == "" then qual = nil end
		
		if form then
			table.insert(pres_ptc_forms, {term = form, qualifiers = {qual}})
		end
		
		i = i + 1
	end
	
	-- Past
	local i = 2
	
	while args["past" .. i] do
		local form = args["past" .. i]; if form == "" then form = nil end
		local qual = args["past" .. i .. "_qual"]; if qual == "" then qual = nil end
		
		if form then
			table.insert(past_forms, {term = form, qualifiers = {qual}})
		end
		
		i = i + 1
	end
	
	-- Past participle
	local past_ptc_forms = {label = "participi"}
	
	if par4 then
		local qual = args["past_ptc_qual"]; if qual == "" then qual = nil end
		table.insert(past_ptc_forms, {term = par4, qualifiers = {qual}})
		local i = 2
		
		while args["past_ptc" .. i] do
			local form = args["past_ptc" .. i]; if form == "" then form = nil end
			local qual = args["past_ptc" .. i .. "_qual"]; if qual == "" then qual = nil end
			
			if form then
				table.insert(past_ptc_forms, {term = form, qualifiers = {qual}})
			end
			
			i = i + 1
		end
	end
	
	-- Are the past forms identical to the past participle forms?
	local identical = true
	
	if #past_forms ~= #past_ptc_forms then
		identical = false
	else
		for key, val in ipairs(past_forms) do
			if past_ptc_forms[key].term ~= val.term or past_ptc_forms[key].qual ~= val.qual then
				identical = false
				break
			end
		end
	end
	
	-- Insert the forms
	table.insert(data.inflections, pres_3sg_forms)
	table.insert(data.inflections, pres_ptc_forms)
	
	if #past_ptc_forms == 0 or identical then
		past_forms.label = "passat i participi"
		table.insert(data.inflections, past_forms)
	else
		table.insert(data.inflections, past_forms)
		table.insert(data.inflections, past_ptc_forms)
	end
	
	if string.find(pagename, "[^ ]+ [^ ]+") then
		table.insert(data.categories, "Locucions verbals en " .. lang.name)
	else
		table.insert(data.categories, "Verbs en " .. lang.name)
	end

end
}

return p