Hoppa till innehållet

Modul:ca-adj

Definition från Wiktionary, den fria ordlistan.

Dokumentationen för denna modul kan skapas på Modul:ca-adj/dok /test


Modul:ca-adj/dok

local gt = require("Modul:grammar-table")
local export = require("Modul:grammar")

local lang_code_param                            = "ca"
local part_of_speech_param                       = "adj"
local uncomparable_templatename_suffix           = "-okomp"

function export._getAcceptedParameters()
	return {}
end

function export._getForms(pagename, templatename, args, meta, format)
	local last_1							= mw.ustring.sub(pagename, -1, -1)
	local last_2							= mw.ustring.sub(pagename, -2, -1)
	local last_3							= mw.ustring.sub(pagename, -3, -1)
	local last_4							= mw.ustring.sub(pagename, -4, -1)
	local last_5							= mw.ustring.sub(pagename, -5, -1)
	local last_6							= mw.ustring.sub(pagename, -6, -1)
	local without_last_1					= mw.ustring.sub(pagename, 1, -2)
	local without_last_2					= mw.ustring.sub(pagename, 1, -3)
	local without_last_3					= mw.ustring.sub(pagename, 1, -4)
	local without_last_4					= mw.ustring.sub(pagename, 1, -5)
	local ends_with_accent					= not not mw.ustring.find(last_1, "[àèéíòóú]")
	local ends_with_accent_e_s				= not not mw.ustring.find(last_2, "[èé]s")
	local ends_with_vowel_gen				= not not mw.ustring.find(last_4, "[aeiou]gen")
	local ends_with_accent_con_ic			= not not mw.ustring.find(last_4, "[àèéíòóú][bcçdfghjklmnpqrstvwxz·]ic")
	local ends_with_accent_con_con_ic		= not not mw.ustring.find(last_5, "[àèéíòóú][bcçdfghjklmnpqrstvwxz·][bcçdfghjklmnpqrstvwxz·]ic")
	local ends_with_accent_con_con_con_ic	= not not mw.ustring.find(last_6, "[àèéíòóú][bcçdfghjklmnpqrstvwxz·][bcçdfghjklmnpqrstvwxz·][bcçdfghjklmnpqrstvwxz·]ic")
	local vowel								= "[aeiouàèéíòóú]"
	local consonant							= "[bcçdfghjklmnpqrstvwxz·]"
	local has_irregular_comparation			= meta.irreg_comp

	local function addAccent(char)
		local from_chars = {"a", "i", "o"} 
		local to_chars   = {"à", "í", "ò"}
		
		for i,from in ipairs(from_chars) do
			local to = to_chars[i] 
			char = mw.ustring.gsub(char, from, to)
		end

		return char
	end

	local sing_masc = pagename
	local sing_fem  = "?"
	local plur_masc = "?"
	local plur_fem  = "?"

	if last_1 == "à" then
		sing_fem  = without_last_1 .. "ana"
		plur_masc = without_last_1 .. "ans"
		plur_fem  = without_last_1 .. "anes"
	elseif last_3 == "las" then
		sing_fem  = pagename .. "sa"
		plur_masc = pagename .. "sos"
		plur_fem  = pagename .. "ses"
	elseif last_2 == "os" then
		sing_fem  = pagename .. "sa"
		plur_masc = pagename .. "sos"
		plur_fem  = pagename .. "ses"
	elseif last_2 == "ós" then
		sing_fem  = without_last_2 .. "osa"
		plur_masc = without_last_2 .. "osos"
		plur_fem  = without_last_2 .. "oses"
	elseif last_2 == "us" then
		sing_fem  = pagename .. "sa"
		plur_masc = pagename .. "sos"
		plur_fem  = pagename .. "ses"
	elseif last_2 == "ús" then
		sing_fem  = without_last_2 .. "ussa"
		plur_masc = without_last_2 .. "ussos"
		plur_fem  = without_last_2 .. "usses"
	elseif last_2 == "as" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "os"
		plur_fem  = pagename .. "es"
	elseif last_2 == "is" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "os"
		plur_fem  = pagename .. "es"
	elseif last_2 == "ís" then
		sing_fem  = without_last_2 .. "issa"
		plur_masc = without_last_2 .. "issos"
		plur_fem  = without_last_2 .. "isses"
	elseif last_3 == "ers" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "os"
		plur_fem  = pagename .. "es"
	elseif last_3 == "ens" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "os"
		plur_fem  = pagename .. "es"
	elseif last_3 == "ble" then
		sing_fem  = pagename
		plur_masc = pagename .. "s"
		plur_fem  = pagename .. "s"
	elseif last_1 == "e" then
		sing_fem  = without_last_1 .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = pagename .. "s"
	elseif ends_with_accent_e_s then
		sing_fem  = without_last_2 .. "esa"
		plur_masc = without_last_2 .. "esos"
		plur_fem  = without_last_2 .. "eses"
	elseif last_1 == "s" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "os"
		plur_fem  = pagename .. "es"
	elseif last_1 == "x" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "os"
		plur_fem  = pagename .. "es"
	elseif last_2 == "az" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "os"
		plur_fem  = pagename .. "es"
	elseif last_2 == "il" then
		sing_fem  = without_last_1 .. "l"
		plur_masc = pagename .. "s"
		plur_fem  = pagename .. "s"
	elseif last_2 == "al" then
		sing_fem  = without_last_1 .. "l"
		plur_masc = pagename .. "s"
		plur_fem  = pagename .. "s"
	elseif last_2 == "ar" then
		sing_fem  = without_last_1 .. "r"
		plur_masc = pagename .. "s"
		plur_fem  = pagename .. "s"
	elseif last_2 == "nt" then
		sing_fem  = without_last_1 .. "t"
		plur_masc = pagename .. "s"
		plur_fem  = pagename .. "s"
	elseif last_2 == "at" then
		sing_fem  = without_last_1 .. "da"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "des"
	elseif last_2 == "it" then
		sing_fem  = without_last_1 .. "da"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "des"
	elseif last_2 == "ut" then
		sing_fem  = without_last_1 .. "da"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "des"
	elseif last_2 == "st" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s, " .. pagename .. "os"
		plur_fem  = pagename .. "es"
	elseif last_2 == "xt" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s, " .. pagename .. "os"
		plur_fem  = pagename .. "es"
	elseif last_1 == "í" then
		sing_fem  = without_last_1 .. "ina"
		plur_masc = without_last_1 .. "ins"
		plur_fem  = without_last_1 .. "ines"
	elseif last_1 == "ó" then
		sing_fem  = without_last_1 .. "ona"
		plur_masc = without_last_1 .. "ons"
		plur_fem  = without_last_1 .. "ones"
	elseif last_1 == "ú" then
		sing_fem  = without_last_1 .. "una"
		plur_masc = without_last_1 .. "uns"
		plur_fem  = without_last_1 .. "unes"
	elseif last_2 == "au" then
		sing_fem  = without_last_1 .. "va"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ves"
	elseif last_2 == "eu" then
		sing_fem  = without_last_1 .. "va"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ves"
	elseif last_2 == "iu" then
		sing_fem  = without_last_1 .. "va"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ves"
	elseif last_2 == "ou" then
		sing_fem  = without_last_1 .. "va"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ves"
	elseif last_2 == "ny" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = pagename .. "es"
	elseif last_3 == "aic" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ques"
	elseif last_3 == "mic" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ques"
	elseif last_3 == "tic" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ques"
	elseif last_4 == "quic" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ques"
	elseif ends_with_accent_con_con_con_ic then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ques"
	elseif ends_with_accent_con_con_ic then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ques"
	elseif ends_with_accent_con_ic then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ques"
	elseif last_2 == "ic" then
		sing_fem  = without_last_1 .. "ga"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "gues"
	elseif last_3 == "uec" then
		sing_fem  = without_last_1 .. "ga"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "gues"
	elseif last_2 == "sc" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s, " .. pagename .. "os"
		plur_fem  = without_last_1 .. "ques"
	elseif last_2 == "uc" then
		sing_fem  = without_last_1 .. "ga"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "gues"
	elseif last_1 == "c" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_1 .. "ques"
	elseif last_2 == "ga" then
		sing_fem  = pagename
		plur_masc = without_last_2 .. "gues"
		plur_fem  = without_last_2 .. "gues"
	elseif last_2 == "ja" then
		sing_fem  = without_last_1 .. "a"
		plur_masc = without_last_2 .. "ges"
		plur_fem  = without_last_2 .. "ges"
	elseif last_1 == "a" then
		sing_fem  = without_last_1 .. "a"
		plur_masc = without_last_1 .. "es"
		plur_fem  = without_last_1 .. "es"
	elseif last_3 == "aci" then
		sing_fem  = without_last_3 .. "àcia"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_3 .. "àcies"
	elseif last_3 == "ini" then
		sing_fem  = without_last_3 .. "ínia"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_3 .. "ínies"
	elseif last_3 == "ari" then
		sing_fem  = without_last_3 .. "ària"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_3 .. "àries"
	elseif last_3 == "ori" then
		sing_fem  = without_last_3 .. "òria"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_3 .. "òries"
	elseif last_3 == "oig" then
		sing_fem  = without_last_2 .. "ja"
		plur_masc = pagename .. "s, " .. without_last_2 .. "jos"
		plur_fem  = without_last_2 .. "ges"
	elseif last_1 == "g" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = pagename .. "ues"
	elseif last_3 == "alç" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "os"
		plur_fem  = without_last_1 .. "ces"
	elseif last_3 == "olç" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "os"
		plur_fem  = without_last_1 .. "ces"
	elseif last_2 == "uç" then
		sing_fem  = pagename .. "a"
		plur_masc = pagename .. "os"
		plur_fem  = without_last_1 .. "ces"
	elseif last_1 == "ç" then
		sing_fem  = without_last_1 .. "ç"
		plur_masc = pagename .. "os"
		plur_fem  = without_last_1 .. "ces"
	elseif ends_with_vowel_gen then
		sing_fem  = without_last_4 .. addAccent(last_4) .. "a"
		plur_masc = pagename .. "s"
		plur_fem  = without_last_4	 .. addAccent(last_4) .. "es"
	elseif mw.ustring.find(last_1, consonant) then
		sing_fem  = without_last_1 .. last_1 .. "a"
		plur_masc = without_last_1 .. last_1 .. "s"
		plur_fem  = without_last_1 .. last_1 .. "es"
	elseif mw.ustring.find(last_1, vowel) then
		sing_fem  = without_last_1 .. last_1
		plur_masc = without_last_1 .. last_1 .. "s"
		plur_fem  = without_last_1 .. last_1 .. "s"
	end
	
	local forms = {}
	forms.sing_mask = args[1] or sing_masc
	forms.sing_fem  = args[2] or sing_fem
	forms.plur_mask = args[3] or plur_masc
	forms.plur_fem  = args[4] or plur_fem

	if has_irregular_comparation then
		forms.sing_mask_komp = args[5] or "?"
		forms.sing_fem_komp = args[6] or "?"
		forms.plur_mask_komp = args[7] or "?"
		forms.plur_fem_komp = args[8] or "?"
		forms.sing_mask_sup  = args[9] or "?"
		forms.sing_fem_sup  = args[10] or "?"
		forms.plur_mask_sup  = args[11] or "?"
		forms.plur_fem_sup  = args[12] or "?"
	end
	
	return forms
end

function export._getMeta(pagename, templatename, args)
	local can_not_be_compared = mw.ustring.sub(templatename, -mw.ustring.len(uncomparable_templatename_suffix), -1) == uncomparable_templatename_suffix
	local has_irregular_comparation = not can_not_be_compared and args[5] or args[6] or args[7] or args[8] or  args[9] or args[10] or args[11] or args[12]
	
	local meta = {}
	meta.numbered_cells = has_irregular_comparation and 12 or 4
	meta.named_cells    = {}
	meta.uncomp         = can_not_be_compared
	meta.irreg_comp     = has_irregular_comparation

	return meta
end

function export._getWikitable(forms, meta)
	local contains_a_quality_notice  = not not meta.quality_notice
	local note                       = meta.note
	local as_first_part              = meta.as_first_part
	local comparation_text           = ""
	local is_uncomparable            = meta.uncomp
	local has_regular_comparation    = not meta.irreg_comp
	local number_of_columns          = has_regular_comparation and 3 or 5
	
	gt.setLanguage(lang_code_param)

	if has_regular_comparation and is_uncomparable then
		comparation_text = "Kompareras inte."
	else
		comparation_text = "Kompareras med '''més''' och '''el/la/els/les més'''."
	end

	local sing_forms_are_identical = forms.sing_mask == forms.sing_fem
	local plur_forms_are_identical = forms.plur_mask == forms.plur_fem

	local sing_mask_cell = sing_forms_are_identical and {'|rowspan="2"', forms.sing_mask} or forms.sing_mask 
	local sing_fem_cell  = not sing_forms_are_identical and forms.sing_fem
	local plur_mask_cell = plur_forms_are_identical and {'|rowspan="2"', forms.plur_mask} or forms.plur_mask 
	local plur_fem_cell  = not plur_forms_are_identical and forms.plur_fem

	local sing_komp_forms_are_identical = forms.sing_mask_komp == forms.sing_fem_komp
	local plur_komp_forms_are_identical = forms.plur_mask_komp == forms.plur_fem_komp

	local sing_mask_komp_cell = sing_komp_forms_are_identical and {'|rowspan="2"', forms.sing_mask_komp} or forms.sing_mask_komp
	local sing_fem_komp_cell  = not sing_komp_forms_are_identical and forms.sing_fem_komp
	local plur_mask_komp_cell = plur_komp_forms_are_identical and {'|rowspan="2"', forms.plur_mask_komp} or forms.plur_mask_komp 
	local plur_fem_komp_cell  = not plur_komp_forms_are_identical and forms.plur_fem_komp

	local sing_sup_forms_are_identical = forms.sing_mask_sup == forms.sing_fem_sup
	local plur_sup_forms_are_identical = forms.plur_mask_sup == forms.plur_fem_sup

	local sing_mask_sup_cell = sing_sup_forms_are_identical and {'|rowspan="2"', forms.sing_mask_sup} or forms.sing_mask_sup
	local sing_fem_sup_cell  = not sing_sup_forms_are_identical and forms.sing_fem_sup
	local plur_mask_sup_cell = plur_sup_forms_are_identical and {'|rowspan="2"', forms.plur_mask_sup} or forms.plur_mask_sup 
	local plur_fem_sup_cell  = not plur_sup_forms_are_identical and forms.plur_fem_sup

	local str = ""

	if has_regular_comparation then
		str = str
		.. gt.getStart(number_of_columns, lang_code_param, part_of_speech_param, contains_a_quality_notice)
		.. gt.getRow({'!class="main min"', 'Böjningar av ' .. meta.pagename .. ' ' .. meta.meanings}, {'!', 'Singular'}, {'!', 'Plural'})
		.. gt.getRow({'!', 'Maskulinum'}, sing_mask_cell, plur_mask_cell)
		.. gt.getRow({'!', 'Femininum'},  sing_fem_cell,  plur_fem_cell)
		.. gt.getRow({'!colspan="3"', comparation_text})
		.. gt.getEnd(number_of_columns, note, as_first_part)
	else
		str = str
		.. gt.getStart(number_of_columns, lang_code_param, part_of_speech_param, contains_a_quality_notice)
		.. gt.getRow({'!class="main min" colspan="2"', 'Böjningar av ' .. meta.pagename .. ' ' .. meta.meanings}, {'!', 'Positiv'}, {'!', 'Komparativ'}, {'!', 'Superlativ'})
		.. gt.getRow({'!rowspan="2"', 'Singular'}, {'!', 'Maskulinum'}, sing_mask_cell, sing_mask_komp_cell, sing_mask_sup_cell)
		.. gt.getRow(                              {'!', 'Femininum'},  sing_fem_cell,  sing_fem_komp_cell,  sing_fem_sup_cell)
		.. gt.getRow({'!rowspan="2"', 'Plural'},   {'!', 'Maskulinum'}, plur_mask_cell, plur_mask_komp_cell, plur_mask_sup_cell)
		.. gt.getRow(                              {'!', 'Femininum'},  plur_fem_cell,  plur_fem_komp_cell,  plur_fem_sup_cell)
		.. gt.getEnd(number_of_columns, note, as_first_part)
	end

	return str
end

function export._getCategories(forms, meta)
	local one_or_more_forms_are_missing = forms.plur_masc == "?" or forms.sing_fem == "?" or forms.plur_fem == "?" 

	local str = ""
	if one_or_more_forms_are_missing then
		str = str .. "[[Kategori:Wiktionary:ca-adj/Former saknas]]"
	end

	return str
end

return export