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 de suport per la plantilla {{de-adj-decl}} per a generar la taula de declinació d’un adjectiu en alemany. Vegeu la plantilla per al seu ús.

local p = {}

local m_links = require("Module:enllaç")
local m_utilities = require("Module:utilitats")
local lang = {code = "de", name = "alemany", sc = "Latn"}
NAMESPACE = NAMESPACE or mw.title.getCurrentTitle().nsText

local declensions = {'pos', 'comp', 'sup'}
local case_order = {
	-- declinació forta
	"f_nom_m", "f_nom_f", "f_nom_n", "f_nom_p",
	"f_gen_m", "f_gen_f", "f_gen_n", "f_gen_p",
	"f_dat_m", "f_dat_f", "f_dat_n", "f_dat_p",
	"f_ac_m", "f_ac_f", "f_ac_n", "f_ac_p",
	-- declinació feble
	"d_nom_m", "d_nom_f", "d_nom_n", "d_nom_p",
	"d_gen_m", "d_gen_f", "d_gen_n", "d_gen_p",
	"d_dat_m", "d_dat_f", "d_dat_n", "d_dat_p",
	"d_ac_m", "d_ac_f", "d_ac_n", "d_ac_p",
	-- declinació mixta
	"m_nom_m", "m_nom_f", "m_nom_n", "m_nom_p",
	"m_gen_m", "m_gen_f", "m_gen_n", "m_gen_p",
	"m_dat_m", "m_dat_f", "m_dat_n", "m_dat_p",
	"m_ac_m", "m_ac_f", "m_ac_n", "m_ac_p",
	-- predicatiu
	"pred_m", "pred_f", "pred_n", "pred_p"
}

local function process(data, args)
	for _, decl in ipairs(declensions) do
		for _, key in ipairs(case_order) do
			if args[key] or data[decl][key] then
				val = args[key] or data[decl][key]
				if type(val) == "string" then
					val = mw.text.split(val, "/")
				end
				if val[1] == "" or val == "" or val == {""} or val[1] == "-" or val[1] == "—" or val == "-" or val == "—" then
					data[decl][key] = "—"
				else
					for i, form in ipairs(val) do
						val[i] = m_links.full_link({term = form, lang = lang}, nil, false)
					end
					data[decl][key] = table.concat(val, ", ")
				end
			end
		end
	end
end

local function make_table(data, decl)
	if not data[decl].title then return '' end
	
	local style_art = 'style="border-right-width: 0px; padding-right: 0em; text-align:right;"'
	local style_form = 'style="border-left-width: 0px; text-align:left;"'
	local style_label = 'style="font-weight: normal; font-style: italic;"'
	
	local ret = {}
	ret[#ret+1] = '<div class="NavFrame">'
	ret[#ret+1] = '\n<div class="NavHead" style="text-align: left; font-style:italic;">' .. data[decl].title .. '</div>'
	ret[#ret+1] = '\n<div class="NavContent">'
	ret[#ret+1] = '\n{| class="wikitable"'
	ret[#ret+1] = '\n! ' .. style_label .. ' colspan="2" rowspan="2" | Nombre i gènere'
	ret[#ret+1] = '\n! ' .. style_label .. ' colspan="6" | Singular'
	ret[#ret+1] = '\n! ' .. style_label .. ' colspan="2" | Plural'
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' colspan="2" | Masculí'
	ret[#ret+1] = '\n! ' .. style_label .. ' colspan="2" | Femení'
	ret[#ret+1] = '\n! ' .. style_label .. ' colspan="2" | Neutre'
	ret[#ret+1] = '\n! ' .. style_label .. ' colspan="2" | Masc./Fem./Neutre'
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' rowspan="4" | Declinació forta<br />(sense article)'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Nominatiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_nom_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_nom_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_nom_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_nom_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Genitiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_gen_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_gen_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_gen_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_gen_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Datiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_dat_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_dat_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_dat_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_dat_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Acusatiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_ac_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_ac_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_ac_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' |'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_ac_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' rowspan="4" | Declinació feble<br />(amb article definit)'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Nominatiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' | der'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_nom_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | die'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_nom_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | das'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_nom_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | die'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_nom_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Genitiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' | des'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_gen_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | der'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_gen_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | des'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_gen_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | der'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_gen_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Datiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' | dem'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_dat_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | der'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_dat_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | dem'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_dat_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | den'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_dat_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Acusatiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' | den'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_ac_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | die'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_ac_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | das'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_ac_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | die'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_ac_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' rowspan="4" | Declinació mixta<br />(amb article indefinit<br />o possessiu)'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Nominatiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' | ein'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_nom_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | eine'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_nom_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | ein'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_nom_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | (keine)'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_nom_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Genitiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' | eines'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_gen_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | einer'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_gen_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | eines'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_gen_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | (keiner)'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_gen_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Datiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' | einem'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_dat_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | einer'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_dat_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | einem'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_dat_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | (keinen)'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_dat_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' | Acusatiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' | einen'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_ac_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | eine'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_ac_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | ein'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["f_ac_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | (keine)'
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["d_ac_p"]
	ret[#ret+1] = '\n|-'
	ret[#ret+1] = '\n! ' .. style_label .. ' colspan="2" | Predicatiu'
	ret[#ret+1] = '\n| ' .. style_art .. ' | ' .. (data[decl]["pred_m"] == '—' and '' or 'er ist')
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["pred_m"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | ' .. (data[decl]["pred_f"] == '—' and '' or 'sie ist')
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["pred_f"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | ' .. (data[decl]["pred_n"] == '—' and '' or 'es ist')
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["pred_n"]
	ret[#ret+1] = '\n| ' .. style_art .. ' | ' .. (data[decl]["pred_p"] == '—' and '' or 'sie sind')
	ret[#ret+1] = '\n| ' .. style_form .. ' | ' .. data[decl]["pred_p"]
	ret[#ret+1] = '\n|}'
	ret[#ret+1] = '\n</div></div>'
	
	return table.concat(ret)
end

local function make_forms(stem, pred, predf)
	local forms = {}
	
	forms["f_nom_m"] = stem .. "er"
	forms["f_nom_f"] = stem .. "e"
	forms["f_nom_n"] = stem .. "es"
	forms["f_nom_p"] = stem .. "e"
	
	forms["f_gen_m"] = stem .. "en"
	forms["f_gen_f"] = stem .. "er"
	forms["f_gen_n"] = stem .. "en"
	forms["f_gen_p"] = stem .. "er"
	
	forms["f_dat_m"] = stem .. "em"
	forms["f_dat_f"] = stem .. "er"
	forms["f_dat_n"] = stem .. "em"
	forms["f_dat_p"] = stem .. "en"
	
	forms["f_ac_m"] = stem .. "en"
	forms["f_ac_f"] = stem .. "e"
	forms["f_ac_n"] = stem .. "es"
	forms["f_ac_p"] = stem .. "e"
	
	forms["d_nom_m"] = stem .. "e"
	forms["d_nom_f"] = stem .. "e"
	forms["d_nom_n"] = stem .. "e"
	forms["d_nom_p"] = stem .. "en"
	
	forms["d_gen_m"] = stem .. "en"
	forms["d_gen_f"] = stem .. "en"
	forms["d_gen_n"] = stem .. "en"
	forms["d_gen_p"] = stem .. "en"
	
	forms["d_dat_m"] = stem .. "en"
	forms["d_dat_f"] = stem .. "en"
	forms["d_dat_n"] = stem .. "en"
	forms["d_dat_p"] = stem .. "en"
	
	forms["d_ac_m"] = stem .. "en"
	forms["d_ac_f"] = stem .. "e"
	forms["d_ac_n"] = stem .. "e"
	forms["d_ac_p"] = stem .. "en"
	
	forms["m_nom_m"] = stem .. "er"
	forms["m_nom_f"] = stem .. "e"
	forms["m_nom_n"] = stem .. "es"
	forms["m_nom_p"] = stem .. "en"
	
	forms["m_gen_m"] = stem .. "en"
	forms["m_gen_f"] = stem .. "en"
	forms["m_gen_n"] = stem .. "en"
	forms["m_gen_p"] = stem .. "en"
	
	forms["m_dat_m"] = stem .. "en"
	forms["m_dat_f"] = stem .. "en"
	forms["m_dat_n"] = stem .. "en"
	forms["m_dat_p"] = stem .. "en"
	
	forms["m_ac_m"] = stem .. "en"
	forms["m_ac_f"] = stem .. "e"
	forms["m_ac_n"] = stem .. "es"
	forms["m_ac_p"] = stem .. "en"
	
	forms["pred_m"] = (pred or stem) .. (predf and 'er' or '')
	forms["pred_f"] = (pred or stem) .. (predf and 'e' or '')
	forms["pred_n"] = (pred or stem) .. (predf and 'es' or '')
	forms["pred_p"] = (pred or stem) .. (predf and 'e' or '')
	
	return forms
end

local function check_forms(stem, data, args)
	if data.redlink or NAMESPACE ~= '' then return true end
	
	local endings = {'e', 'em', 'en', 'er', 'es'}
	for _, e in ipairs(endings) do
		if args.bot then
			data.bot = data.bot .. "* decl=" .. stem .. e .. "\n"
		else
			local t = mw.title.new(stem .. e)
			if not t.exists then
				table.insert(data.categories,'Termes en alemany amb flexions a crear')
				return true
			end
		end
	end
	return false
end
	
function p.show(frame)
	local args = frame:getParent().args
	local pagename = args.pagename or mw.title.getCurrentTitle().subpageText
	local comp = args[1]
	if comp == '' or comp == 'er' then
		comp = nil
	end
	local sup = args[2]
	if sup == '' or sup == 'sten' then
		sup = nil
	end
	local pred = args.pred or pagename
	local predf = args["pred_fort"]
	
	local data = {pos = {}, comp = {}, sup = {}, categories = {}, redlink = false, bot = ''}

	-- formes positives
	local stem = pagename
	if string.sub(stem, -1) == "e" then
		stem = string.sub(stem, 1, -2)
	end
	data.pos = make_forms(stem, pred, predf)
	data.redlink = check_forms(stem, data, args)
	if comp == '-' and (sup == nil or sup == '-') then
		data.pos.title = "Declinació de " .. pagename
	else
		data.pos.title = "Formes positives de " .. pagename
	end
	
	-- formes comparatives
	if comp ~= '-' then
		stem = comp or (pagename .. 'er')
		local pred_comp = pred == '-' and '-' or stem
		data.comp = make_forms(stem, pred_comp)
		data.redlink = check_forms(stem, data, args)
		data.comp.title = "Formes comparatives de " .. pagename
		if args.comp2 then
			pred_comp = pred == '-' and '-' or args.comp2
			local comp2 = make_forms(args.comp2, pred_comp)
			data.redlink = check_forms(args.comp2, data, args)
			for k, form in pairs(comp2) do
				data.comp[k] = data.comp[k] .. '/' .. form
			end
		end
	end
	
	-- formes superlatives
	if sup ~= '-' and not (comp == '-' and sup == nil) then
		stem = string.gsub(sup or pagename .. 'st', 'sten$', 'st')
		local pred_sup = pred == '-' and '-' or ('am [[' .. stem .. 'en]]')
		data.sup = make_forms(stem, pred_sup)
		data.redlink = check_forms(stem, data, args)
		data.sup.title = "Formes superlatives de " .. pagename
		if args.sup2 then
			stem = string.gsub(args.sup2, 'sten$', 'st')
			pred_sup = pred == '-' and '-' or (stem .. 'en')
			local sup2 = make_forms(stem, pred_sup)
			data.redlink = check_forms(stem, data, args)
			for k, form in pairs(sup2) do
				data.sup[k] = data.sup[k] .. '/' .. form
			end
		end
	end
	
	if args.bot then
		return data.bot
	else
		process(data, args)
		
		local tables = ''
		for _, decl in ipairs(declensions) do
			tables = tables .. make_table(data, decl)
		end
		return tables .. m_utilities.format_categories(data.categories, lang)
	end
end

return p