Modul:pt-adj

Definition från Wiktionary, den fria ordlistan.
Hoppa till navigering Hoppa till sök

Dokumentation för denna modul finns på /dok (redigera), /test


Syfte[redigera]

Stödja mallarna {{pt-adj}} och {{pt-adj-okomp}}

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

local lang_code_param                   = "pt"
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 without_last_1            = mw.ustring.sub(pagename, 1, -2)
	local without_last_2            = mw.ustring.sub(pagename, 1, -3)
	local accented_letter_found_in_second_last_syllable = not not mw.ustring.find(mw.ustring.sub(pagename, -6, -4), "[áâéêíóôú]")
	local vowel                     = "[aeiouáéíóú]"
	local has_irregular_comparation = meta.irreg_comp
	
	local sing_masc = pagename
	local sing_fem  = "?"
	local plur_masc = "?"
	local plur_fem  = "?"

	if last_2 == "or" then
		sing_fem  = without_last_2 .. "ora"
		plur_masc = without_last_2 .. "ores"
		plur_fem  = without_last_2 .. "oras"
	elseif last_2 == "ôr" then
		sing_fem  = without_last_2 .. "ôra"
		plur_masc = without_last_2 .. "ôres"
		plur_fem  = without_last_2 .. "ôras"
	elseif last_2 == "ol" then
		sing_fem  = without_last_2 .. "ola"
		plur_masc = without_last_2 .. "óis"
		plur_fem  = without_last_2 .. "olas"
	elseif last_1 == "e" then
		sing_fem  = without_last_1 .. "e"
		plur_masc = without_last_1 .. "es"
		plur_fem  = without_last_1 .. "es"
	elseif last_2 == "el" then
		sing_fem  = without_last_2 .. "el"
		plur_masc = without_last_2 .. "eis"
		plur_fem  = without_last_2 .. "eis"
	elseif last_2 == "es" then
		sing_fem  = without_last_2 .. "es"
		plur_masc = without_last_2 .. "es"
		plur_fem  = without_last_2 .. "es"
	elseif last_2 == "ês" then
		sing_fem  = without_last_2 .. "esa"
		plur_masc = without_last_2 .. "eses"
		plur_fem  = without_last_2 .. "esas"
	elseif last_2 == "ez" then
		sing_fem  = without_last_2 .. "eza"
		plur_masc = without_last_2 .. "ezes"
		plur_fem  = without_last_2 .. "ezas"
	elseif last_2 == "eu" then
		sing_fem  = without_last_2 .. "eia"
		plur_masc = without_last_2 .. "us"
		plur_fem  = without_last_2 .. "eias"
	elseif last_1 == "a" then
		sing_fem  = without_last_1 .. "a"
		plur_masc = without_last_1 .. "as"
		plur_fem  = without_last_1 .. "as"
	elseif last_2 == "al" then
		sing_fem  = without_last_2 .. "al"
		plur_masc = without_last_2 .. "ais"
		plur_fem  = without_last_2 .. "ais"
	elseif last_2 == "ar" then
		sing_fem  = without_last_2 .. "ar"
		plur_masc = without_last_2 .. "ares"
		plur_fem  = without_last_2 .. "ares"
	elseif last_2 == "ão" then
		-- manual forms
	elseif last_1 == "o" then
		sing_fem  = without_last_1 .. "a"
		plur_masc = without_last_1 .. "os"
		plur_fem  = without_last_1 .. "as"
	elseif last_2 == "il" then
		if accented_letter_found_in_second_last_syllable then
			sing_fem  = without_last_2 .. "il"
			plur_masc = without_last_2 .. "eis"
			plur_fem  = without_last_2 .. "eis"
		else
			sing_fem  = without_last_2 .. "il"
			plur_masc = without_last_2 .. "is"
			plur_fem  = without_last_2 .. "is"
		end
	elseif last_2 == "ul" then
		sing_fem  = without_last_2 .. "ul"
		plur_masc = without_last_2 .. "uis"
		plur_fem  = without_last_2 .. "uis"
	elseif last_1 == "m" then
		plur_masc = without_last_1 .. "ns"
		-- manual feminine forms
	elseif mw.ustring.find(last_1, vowel) then
		sing_fem  = pagename
		plur_masc = pagename .. "s"
		plur_fem  = pagename .. "s"
	else
		-- manual forms
	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 is_uncomparable then
		comparation_text = "Kompareras inte."
	else
		comparation_text = "Kompareras med '''mais''' och '''o/os/a/as mais'''."
	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 = ''
		.. 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:pt-adj/Former saknas]]"
	end

	return str
end

return export