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 de Mòdul:la-adj. Genera la taula de declinació.

local p = {}

local function convert(data)
	local col = {}
	local row = {}
	local colors = {}
	local marked = {}
	local function add(i, j)
		local entry = data[i][j]
		local col = col[i][j]
		local row = row[i][j]
		local color = colors[i][j]
		if col == 0 or row == 0 then
			return ""
		end
		if col == 1 then
			if row == 1 then
				return '\n|style="color: inherit; background-color: #' .. color .. ';" | ' .. entry
			else
				return '\n|style="color: inherit; background-color: #' .. color .. ';" rowspan=' .. row .. ' | ' .. entry
			end
		else
			if row == 1 then
				return '\n|style="color: inherit; background-color: #' .. color .. ';" colspan=' .. col .. ' | ' .. entry
			else
				return '\n|style="color: inherit; background-color: #' .. color .. ';" colspan=' .. col .. ' rowspan=' .. row .. ' | ' .. entry
			end
		end
	end
	
	for i = 1, #data do
		col[i] = {}
		row[i] = {}
		colors[i] = {}
		marked[i] = {}
		for j = 1, #data[i] do
			col[i][j] = 1
			row[i][j] = 1
			colors[i][j] = "inherit"
			marked[i][j] = false
		end
	end
	
--[[ De moment no fusionem files
	--merge rows
	for i = 1, #data do
		for j = 1, #data[i] do
			if row[i][j] ~= 0 then
				for k = i + 1, #data do
					if data[i][j] ~= data[k][j] or col[i][j] ~= col[k][j] then
						break
					end
					row[i][j] = row[i][j] + 1
					row[k][j] = 0
				end
			end
		end
	end
]]

	--merge columns
	for i = 1, #data do 
		for j = 1, #data[i] do
			if col[i][j] ~= 0 then
				for k = j + 1, #data[i] do
					if data[i][j] ~= data[i][k] then
						break
					end
					col[i][j] = col[i][j] + 1
					col[i][k] = 0
					row[i][k] = 0
				end
			end
		end 
	end

	--final
	for i = 1 ,#data do
		for j = 1, #data[i] do
			data[i][j] = add(i,j)
		end
		data[i] = table.concat(data[i])
	end
	return data
end

local function make_table_mfn_pl(data)
	local conv = {
		{data.forms.nom_p_m},
		{data.forms.voc_p_m},
		{data.forms.ac_p_m},
		{data.forms.gen_p_m},
		{data.forms.dat_p_m},
		{data.forms.abl_p_m},
	}
	conv = convert(conv)
	
	local output = data.title
	output = output .. '\n{| class="wikitable"'
	output = output .. '\n! style="' .. data.style_label .. '" rowspan="2" | Cas'
	output = output .. '\n! style="' .. data.style_label .. '" | Plural'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Masc./Fem./Neutre'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Nominatiu'
	output = output .. conv[1]
	if data.voc then
		output = output .. '\n|-'
		output = output .. '\n! style="' .. data.style_label .. '" | Vocatiu'
		output = output .. conv[2]
	end
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Acusatiu'
	output = output .. conv[3]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Genitiu'
	output = output .. conv[4]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Datiu'
	output = output .. conv[5]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Ablatiu'
	output = output .. conv[6]
	output = output .. '\n|}'
	
	return output
end

local function make_table_mfn_sg(data)
	local conv = {
		{data.forms.nom_s_m},
		{data.forms.voc_s_m},
		{data.forms.ac_s_m},
		{data.forms.gen_s_m},
		{data.forms.dat_s_m},
		{data.forms.abl_s_m},
	}
	conv = convert(conv)
	
	local output = data.title
	output = output .. '\n{| class="wikitable"'
	output = output .. '\n! style="' .. data.style_label .. '" rowspan="2" | Cas'
	output = output .. '\n! style="' .. data.style_label .. '" | Singular'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Masc./Fem./Neutre'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Nominatiu'
	output = output .. conv[1]
	if data.voc then
		output = output .. '\n|-'
		output = output .. '\n! style="' .. data.style_label .. '" | Vocatiu'
		output = output .. conv[2]
	end
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Acusatiu'
	output = output .. conv[3]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Genitiu'
	output = output .. conv[4]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Datiu'
	output = output .. conv[5]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Ablatiu'
	output = output .. conv[6]
	output = output .. '\n|}'
	
	return output
end

local function make_table_mf_pl(data)
	local conv = {
		{data.forms.nom_p_m, data.forms.nom_p_n},
		{data.forms.voc_p_m, data.forms.voc_p_n},
		{data.forms.ac_p_m, data.forms.ac_p_n},
		{data.forms.gen_p_m, data.forms.gen_p_n},
		{data.forms.dat_p_m, data.forms.dat_p_n},
		{data.forms.abl_p_m, data.forms.abl_p_n},
	}
	conv = convert(conv)
	
	local output = data.title
	output = output .. '\n{| class="wikitable"'
	output = output .. '\n! style="' .. data.style_label .. '" rowspan="2" | Cas'
	output = output .. '\n! style="' .. data.style_label .. '" colspan="2" | Plural'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Masc./Fem.'
	output = output .. '\n! style="' .. data.style_label .. '" | Neutre'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Nominatiu'
	output = output .. conv[1]
	if data.voc then
		output = output .. '\n|-'
		output = output .. '\n! style="' .. data.style_label .. '" | Vocatiu'
		output = output .. conv[2]
	end
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Acusatiu'
	output = output .. conv[3]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Genitiu'
	output = output .. conv[4]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Datiu'
	output = output .. conv[5]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Ablatiu'
	output = output .. conv[6]
	output = output .. '\n|}'
	
	return output
end

local function make_table_mf_sg(data)
	local conv = {
		{data.forms.nom_s_m, data.forms.nom_s_n},
		{data.forms.voc_s_m, data.forms.voc_s_n},
		{data.forms.ac_s_m, data.forms.ac_s_n},
		{data.forms.gen_s_m, data.forms.gen_s_n},
		{data.forms.dat_s_m, data.forms.dat_s_n},
		{data.forms.abl_s_m, data.forms.abl_s_n},
	}
	conv = convert(conv)
	
	local output = data.title
	output = output .. '\n{| class="wikitable"'
	output = output .. '\n! style="' .. data.style_label .. '" rowspan="2" | Cas'
	output = output .. '\n! style="' .. data.style_label .. '" colspan="2" | Singular'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Masc./Fem.'
	output = output .. '\n! style="' .. data.style_label .. '" | Neutre'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Nominatiu'
	output = output .. conv[1]
	if data.voc then
		output = output .. '\n|-'
		output = output .. '\n! style="' .. data.style_label .. '" | Vocatiu'
		output = output .. conv[2]
	end
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Acusatiu'
	output = output .. conv[3]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Genitiu'
	output = output .. conv[4]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Datiu'
	output = output .. conv[5]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Ablatiu'
	output = output .. conv[6]
	output = output .. '\n|}'
	
	return output
end

local function make_table_pl(data)
	local conv = {
		{data.forms.nom_p_m, data.forms.nom_p_f, data.forms.nom_p_n},
		{data.forms.voc_p_m, data.forms.voc_p_f, data.forms.voc_p_n},
		{data.forms.ac_p_m, data.forms.ac_p_f, data.forms.ac_p_n},
		{data.forms.gen_p_m, data.forms.gen_p_f, data.forms.gen_p_n},
		{data.forms.dat_p_m, data.forms.dat_p_f, data.forms.dat_p_n},
		{data.forms.abl_p_m, data.forms.abl_p_f, data.forms.abl_p_n},
	}
	conv = convert(conv)
	
	local output = data.title
	output = output .. '\n{| class="wikitable"'
	output = output .. '\n! style="' .. data.style_label .. '" rowspan="2" | Cas'
	output = output .. '\n! style="' .. data.style_label .. '" colspan="3" | Plural'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Masculí'
	output = output .. '\n! style="' .. data.style_label .. '" | Femení'
	output = output .. '\n! style="' .. data.style_label .. '" | Neutre'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Nominatiu'
	output = output .. conv[1]
	if data.voc then
		output = output .. '\n|-'
		output = output .. '\n! style="' .. data.style_label .. '" | Vocatiu'
		output = output .. conv[2]
	end
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Acusatiu'
	output = output .. conv[3]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Genitiu'
	output = output .. conv[4]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Datiu'
	output = output .. conv[5]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Ablatiu'
	output = output .. conv[6]
	output = output .. '\n|}'
	
	return output
end

local function make_table_sg(data)
	local conv = {
		{data.forms.nom_s_m, data.forms.nom_s_f, data.forms.nom_s_n},
		{data.forms.voc_s_m, data.forms.voc_s_f, data.forms.voc_s_n},
		{data.forms.ac_s_m, data.forms.ac_s_f, data.forms.ac_s_n},
		{data.forms.gen_s_m, data.forms.gen_s_f, data.forms.gen_s_n},
		{data.forms.dat_s_m, data.forms.dat_s_f, data.forms.dat_s_n},
		{data.forms.abl_s_m, data.forms.abl_s_f, data.forms.abl_s_n},
	}
	conv = convert(conv)
	
	local output = data.title
	output = output .. '\n{| class="wikitable"'
	output = output .. '\n! style="' .. data.style_label .. '" rowspan="2" | Cas'
	output = output .. '\n! style="' .. data.style_label .. '" colspan="3" | Singular'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Masculí'
	output = output .. '\n! style="' .. data.style_label .. '" | Femení'
	output = output .. '\n! style="' .. data.style_label .. '" | Neutre'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Nominatiu'
	output = output .. conv[1]
	if data.voc then
		output = output .. '\n|-'
		output = output .. '\n! style="' .. data.style_label .. '" | Vocatiu'
		output = output .. conv[2]
	end
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Acusatiu'
	output = output .. conv[3]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Genitiu'
	output = output .. conv[4]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Datiu'
	output = output .. conv[5]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Ablatiu'
	output = output .. conv[6]
	output = output .. '\n|}'
	
	return output
end

local function make_table_mfn(data)
	local conv = {
		{data.forms.nom_s_m},
		{data.forms.voc_s_m},
		{data.forms.ac_s_m},
		{data.forms.gen_s_m},
		{data.forms.dat_s_m},
		{data.forms.abl_s_m},
		{"----"},
		{data.forms.nom_p_m},
		{data.forms.voc_p_m},
		{data.forms.ac_p_m},
		{data.forms.gen_p_m},
		{data.forms.dat_p_m},
		{data.forms.abl_p_m},
	}
	conv = convert(conv)
	
	local output = data.title
	output = output .. '\n{| class="wikitable"'
	output = output .. '\n! style="' .. data.style_label .. '" rowspan="2" | Cas'
	output = output .. '\n! style="' .. data.style_label .. '" | Singular'
	output = output .. '\n|rowspan="2"|'
	output = output .. '\n! style="' .. data.style_label .. '" | Plural'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Masc./Fem./Neutre'
	output = output .. '\n! style="' .. data.style_label .. '" | Masc./Fem./Neutre'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Nominatiu'
	output = output .. conv[1]
	if data.voc then
		output = output .. '\n|rowspan="6"|'
	else
		output = output .. '\n|rowspan="5"|'
	end
	output = output .. conv[8]
	if data.voc then
		output = output .. '\n|-'
		output = output .. '\n! style="' .. data.style_label .. '" | Vocatiu'
		output = output .. conv[2]
		output = output .. conv[9]
	end
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Acusatiu'
	output = output .. conv[3]
	output = output .. conv[10]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Genitiu'
	output = output .. conv[4]
	output = output .. conv[11]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Datiu'
	output = output .. conv[5]
	output = output .. conv[12]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Ablatiu'
	output = output .. conv[6]
	output = output .. conv[13]
	output = output .. '\n|}'
	
	return output
end

local function make_table_mf(data)
	local conv = {
		{data.forms.nom_s_m, data.forms.nom_s_n},
		{data.forms.voc_s_m, data.forms.voc_s_n},
		{data.forms.ac_s_m, data.forms.ac_s_n},
		{data.forms.gen_s_m, data.forms.gen_s_n},
		{data.forms.dat_s_m, data.forms.dat_s_n},
		{data.forms.abl_s_m, data.forms.abl_s_n},
		{"----"},
		{data.forms.nom_p_m, data.forms.nom_p_n},
		{data.forms.voc_p_m, data.forms.voc_p_n},
		{data.forms.ac_p_m, data.forms.ac_p_n},
		{data.forms.gen_p_m, data.forms.gen_p_n},
		{data.forms.dat_p_m, data.forms.dat_p_n},
		{data.forms.abl_p_m, data.forms.abl_p_n},
	}
	conv = convert(conv)
	
	local output = data.title
	output = output .. '\n{| class="wikitable"'
	output = output .. '\n! style="' .. data.style_label .. '" rowspan="2" | Cas'
	output = output .. '\n! style="' .. data.style_label .. '" colspan="2" | Singular'
	output = output .. '\n|rowspan="2"|'
	output = output .. '\n! style="' .. data.style_label .. '" colspan="2" | Plural'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Masc./Fem.'
	output = output .. '\n! style="' .. data.style_label .. '" | Neutre'
	output = output .. '\n! style="' .. data.style_label .. '" | Masc./Fem.'
	output = output .. '\n! style="' .. data.style_label .. '" | Neutre'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Nominatiu'
	output = output .. conv[1]
	if data.voc then
		output = output .. '\n|rowspan="6"|'
	else
		output = output .. '\n|rowspan="5"|'
	end
	output = output .. conv[8]
	if data.voc then
		output = output .. '\n|-'
		output = output .. '\n! style="' .. data.style_label .. '" | Vocatiu'
		output = output .. conv[2]
		output = output .. conv[9]
	end
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Acusatiu'
	output = output .. conv[3]
	output = output .. conv[10]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Genitiu'
	output = output .. conv[4]
	output = output .. conv[11]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Datiu'
	output = output .. conv[5]
	output = output .. conv[12]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Ablatiu'
	output = output .. conv[6]
	output = output .. conv[13]
	output = output .. '\n|}'
	
	return output
end

function p.make_table(data)
	data.style_label = "font-style: italic; font-weight: normal;"
	local output
	if not data.forms.nom_s_n and not data.forms.nom_p_n then
		if data.num == "p" then 
			output = make_table_mfn_pl(data)
		elseif data.num == "s" then 
			output = make_table_mfn_sg(data)
		else 
			output = make_table_mfn(data) 
		end
	elseif not data.forms.nom_s_f and not data.forms.nom_p_f then
		if data.num == "p" then 
			output = make_table_mf_pl(data)
		elseif data.num == "s" then 
			output = make_table_mf_sg(data)
		else 
			output = make_table_mf(data) 
		end
	else
		if data.num == "p" then 
			output = make_table_pl(data)
		elseif data.num == "s" then 
			output = make_table_sg(data) 
		end
	end
	
	if output then
		if data.footnote and data.footnote ~= "" then
			output = output .. '\n' .. data.footnote
		end
		return output
	end
	
	local conv = {
		{data.forms.nom_s_m, data.forms.nom_s_f, data.forms.nom_s_n},
		{data.forms.voc_s_m, data.forms.voc_s_f, data.forms.voc_s_n},
		{data.forms.ac_s_m, data.forms.ac_s_f, data.forms.ac_s_n},
		{data.forms.gen_s_m, data.forms.gen_s_f, data.forms.gen_s_n},
		{data.forms.dat_s_m, data.forms.dat_s_f, data.forms.dat_s_n},
		{data.forms.abl_s_m, data.forms.abl_s_f, data.forms.abl_s_n},
		{"----", "----", "----"},
		{data.forms.nom_p_m, data.forms.nom_p_f, data.forms.nom_p_n},
		{data.forms.voc_p_m, data.forms.voc_p_f, data.forms.voc_p_n},
		{data.forms.ac_p_m, data.forms.ac_p_f, data.forms.ac_p_n},
		{data.forms.gen_p_m, data.forms.gen_p_f, data.forms.gen_p_n},
		{data.forms.dat_p_m, data.forms.dat_p_f, data.forms.dat_p_n},
		{data.forms.abl_p_m, data.forms.abl_p_f, data.forms.abl_p_n},
	}
	conv = convert(conv)
	
	local output = data.title
	output = output .. '\n{| class="wikitable"'
	output = output .. '\n! style="' .. data.style_label .. '" rowspan="2" | Cas'
	output = output .. '\n! style="' .. data.style_label .. '" colspan="3" | Singular'
	output = output .. '\n|rowspan="2"|'
	output = output .. '\n! style="' .. data.style_label .. '" colspan="3" | Plural'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Masculí'
	output = output .. '\n! style="' .. data.style_label .. '" | Femení'
	output = output .. '\n! style="' .. data.style_label .. '" | Neutre'
	output = output .. '\n! style="' .. data.style_label .. '" | Masculí'
	output = output .. '\n! style="' .. data.style_label .. '" | Femení'
	output = output .. '\n! style="' .. data.style_label .. '" | Neutre'
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Nominatiu'
	output = output .. conv[1]
	if data.voc then
		output = output .. '\n|rowspan="6"|'
	else
		output = output .. '\n|rowspan="5"|'
	end
	output = output .. conv[8]
	if data.voc then
		output = output .. '\n|-'
		output = output .. '\n! style="' .. data.style_label .. '" | Vocatiu'
		output = output .. conv[2]
		output = output .. conv[9]
	end
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Acusatiu'
	output = output .. conv[3]
	output = output .. conv[10]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Genitiu'
	output = output .. conv[4]
	output = output .. conv[11]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Datiu'
	output = output .. conv[5]
	output = output .. conv[12]
	output = output .. '\n|-'
	output = output .. '\n! style="' .. data.style_label .. '" | Ablatiu'
	output = output .. conv[6]
	output = output .. conv[13]
	output = output .. '\n|}'
	if data.footnote and data.footnote ~= "" then
		output = output .. '\n' .. data.footnote
	end
	
	return output
end

return p