Hopp til innhold

Modul:sv-adj

Fra Wiktionary

Fra sv:Modul:sv-adj.


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

local lang_code_param       = "sv"
local part_of_speech_param  = "adj"
local adverb_param          = "adv"
local comparative_param     = "komp"
local superlative_param     = "sup"
local neuter_param          = "neutrum"
local positive_param        = "pos"
local attributive_param     = "attr"
local predicative_param     = "pred"
local personal_param        = "pers"
local uncomparable_templatename_suffix  = "-usam"
local periphrastic_templatename_suffix  = "-peri"
local irregular_templatename_suffix     = "-ureg"
local inflexible_positive_templatename  = "sv-adj-0"
local alternative_paradigm_templatename = "sv-adj-alt"

function export._getAcceptedParameters()
	return {adverb_param, comparative_param, superlative_param, neuter_param, positive_param, attributive_param, predicative_param, personal_param}
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_4                = mw.ustring.sub(pagename, -4, -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 ends_with_vowel_d     = not not mw.ustring.find(last_2, "[aouåeiyäö]d")
	local ends_with_consonant_d = not not mw.ustring.find(last_2, "[bcdfghjklmnpqrstvwxz]d")
	local ends_with_vowel       = not not mw.ustring.find(last_1, "[aouåeiyäö]")
	
	local common        = pagename
	local neuter        = ends_with_vowel_d and without_last_1 .. "tt" or pagename .. "t"
	local masc          = pagename .. "e"
	local plural        = pagename .. "a"
	local comp          = pagename .. "are"
	local attr_sup      = pagename .. "aste"
	local attr_sup_masc = pagename .. "aste"
	local pred_sup      = pagename .. "ast"

	local has_alternative_inflection_pattern = meta.alt_paradigm
	local belongs_to_second_declension       = meta.second_declension
	local positive_forms_are_not_inflected   = meta.positive_uninflected

	if has_alternative_inflection_pattern then
		if last_1 == "t" then
			neuter        = pagename
		elseif last_1 == "m" then
			masc          = pagename .. "me"
			plural        = pagename .. "ma"
			comp          = pagename .. "mare"
			attr_sup      = pagename .. "maste"
			attr_sup_masc = pagename .. "maste"
			pred_sup      = pagename .. "mast"
		elseif last_4 == "mmen" or last_4 == "nnen" or last_4 == "mmal" then
			neuter        = last_1 == "n" and without_last_1 .. "t" or neuter
			masc          = without_last_3 .. last_1 .. "e"
			plural        = without_last_3 .. last_1 .. "a"
			comp          = without_last_3 .. last_1 .. "are"
			attr_sup      = without_last_3 .. last_1 .. "aste"
			attr_sup_masc = without_last_3 .. last_1 .. "aste"
			pred_sup      = without_last_3 .. last_1 .. "ast"
		elseif last_2 == "el" or last_2 == "en" or last_2 == "er" then
			neuter        = last_1 == "n" and without_last_1 .. "t" or neuter
			masc          = without_last_2 .. last_1 .. "e"
			plural        = without_last_2 .. last_1 .. "a"
			comp          = without_last_2 .. last_1 .. "are"
			attr_sup      = without_last_2 .. last_1 .. "aste"
			attr_sup_masc = without_last_2 .. last_1 .. "aste"
			pred_sup      = without_last_2 .. last_1 .. "ast"
		elseif last_2 == "dd" then
			neuter        = without_last_2 .. "tt"
		elseif last_2 == "ad" then
			neuter        = without_last_1 .. "t"
			plural        = pagename .. "e"
		elseif last_2 == "nn" or ends_with_consonant_d then
			neuter        = without_last_1 .. "t"
		elseif ends_with_vowel then
			neuter        = pagename .. "tt"
		else
			if not args[2] and not args[4] then
				meta.alt_paradigm = false
			end
		end
	end

	if belongs_to_second_declension then
		comp          = args[comparative_param]
		attr_sup      = args[superlative_param] .. "a"
		attr_sup_masc = args[superlative_param] .. "e"
		pred_sup      = args[superlative_param]
	end

	if positive_forms_are_not_inflected then 
		common = pagename
		neuter = pagename
		masc   = pagename
		plural = pagename
	end

	local forms = {}
	forms.attr_obest_sing_utrum_pos   = args[1] or common
	forms.attr_obest_sing_neutrum_pos = args[2] or neuter
	forms.attr_best_sing_mask_pos     = args[3] or masc
	forms.attr_best_sing_alla_pos     = args[4] or plural
	forms.attr_plur_pos               = args[5] or plural
	forms.attr_komp                   = args[9] or comp
	forms.attr_komp_mask              = args[10] or comp
	forms.attr_best_sing_mask_sup     = args[12] or attr_sup_masc
	forms.attr_sup                    = args[13] or attr_sup
	forms.pred_sing_utrum_pos         = args[6] or common
	forms.pred_sing_neutrum_pos       = args[7] or neuter
	forms.pred_plur_pos               = args[8] or plural
	forms.pred_komp                   = args[11] or comp
	forms.pred_sup                    = args[14] or pred_sup
	forms.x_adv                         = args[adverb_param] ~= "" and args[adverb_param] or neuter

	if format == "wikitable" or format == "export" then
		local adjective_can_not_describe_a_person      = not meta.pers
		local masculine_forms_have_not_been_cleared    = not meta.pers_clear
		local adverb_derivative_has_not_been_cleared   = not meta.adv_clear
		local neuter_needs_to_but_has_not_been_cleared = not meta.neuter_clear
		local no_positive_forms_exist                  = not meta.pos
	    local no_suffix_compared_forms_exist           = not meta.comp
		local no_superlative_forms_exist               = not meta.sup
		local no_attributive_forms_exist               = not meta.attr
		local no_predicative_forms_exist               = not meta.pred
		local no_adverb_derivative_exists              = not meta.adv

		if adjective_can_not_describe_a_person then
			forms.attr_best_sing_mask_pos     = "-"
			forms.attr_komp_mask              = "-"
			forms.attr_best_sing_mask_sup     = "-"
		else 
			if masculine_forms_have_not_been_cleared then
				forms.attr_best_sing_mask_pos = forms.attr_best_sing_mask_pos .. "?"
				forms.attr_komp_mask          = forms.attr_komp_mask .. "?"
				forms.attr_best_sing_mask_sup = forms.attr_best_sing_mask_sup .. "?"
			end
		end
	
		if neuter_needs_to_but_has_not_been_cleared then
			forms.attr_obest_sing_neutrum_pos = forms.attr_obest_sing_neutrum_pos .. "?"
			forms.pred_sing_neutrum_pos       = forms.pred_sing_neutrum_pos .. "?"
		end

		if no_positive_forms_exist then
			forms.attr_obest_sing_utrum_pos   = "-"
			forms.attr_obest_sing_neutrum_pos = "-"
			forms.attr_best_sing_mask_pos     = "-"
			forms.attr_best_sing_alla_pos     = "-"
			forms.attr_plur_pos               = "-"
			forms.pred_sing_utrum_pos         = "-"
			forms.pred_sing_neutrum_pos       = "-"
			forms.pred_plur_pos               = "-"
		end
	
		if no_suffix_compared_forms_exist then
			forms.attr_komp                   = "-"
			forms.attr_komp_mask              = "-"
			forms.pred_komp                   = "-"
		end
	
		if no_superlative_forms_exist then
			forms.attr_best_sing_mask_sup     = "-"
			forms.attr_sup                    = "-"
			forms.pred_sup                    = "-"
		end
	
		if no_attributive_forms_exist then
			forms.attr_obest_sing_utrum_pos   = "-"
			forms.attr_obest_sing_neutrum_pos = "-"
			forms.attr_best_sing_mask_pos     = "-"
			forms.attr_best_sing_alla_pos     = "-"
			forms.attr_plur_pos               = "-"
			forms.attr_komp                   = "-"
			forms.attr_komp_mask              = "-"
			forms.attr_best_sing_mask_sup     = "-"
			forms.attr_sup                    = "-"
		end
	
		if no_predicative_forms_exist then
			forms.pred_sing_utrum_pos         = "-"
			forms.pred_sing_neutrum_pos       = "-"
			forms.pred_plur_pos               = "-"
			forms.pred_komp                   = "-"
			forms.pred_sup                    = "-"
		end

		if no_adverb_derivative_exists then
			forms.x_adv                       = "-"
		else
			if adverb_derivative_has_not_been_cleared then
				forms.x_adv                   = forms.x_adv .. "?"
			end
		end
	end

	return forms
end

function export._getMeta(pagename, templatename, args)
	local function isSecondDeclension(comp, sup)
		comp = comp or ""
		sup  = sup or ""
		local comp_last_3 = mw.ustring.sub(comp, -3, -1)
		local sup_last_3  = mw.ustring.sub(sup, -3, -1)
		local has_second_declension_comp_ending = not not mw.ustring.match(comp_last_3, "[^a]re")
		local has_second_declension_sup_ending  = not not mw.ustring.match(sup_last_3, "[^a]st")

		return has_second_declension_comp_ending and has_second_declension_sup_ending
	end

	local positive_forms_are_not_inflected     = mw.ustring.sub(templatename, 1, mw.ustring.len(inflexible_positive_templatename)) == inflexible_positive_templatename
	local has_alternative_inflection_pattern   = mw.ustring.sub(templatename, 1, mw.ustring.len(alternative_paradigm_templatename)) == alternative_paradigm_templatename
	local ends_with_vowel_t                    = not not mw.ustring.match(pagename, "[aouåeiyäö]t$")
	local does_not_need_neuter_comfirmation    = not ends_with_vowel_t
	local neuter_is_confirmed                  = args[neuter_param] == ""
	local can_not_be_compared                  = mw.ustring.sub(templatename, -mw.ustring.len(uncomparable_templatename_suffix), -1) == uncomparable_templatename_suffix
	local uses_mainly_periphrastic_comparation = mw.ustring.sub(templatename, -mw.ustring.len(periphrastic_templatename_suffix), -1) == periphrastic_templatename_suffix
	local uses_suffix_comparation              = not (uses_mainly_periphrastic_comparation or can_not_be_compared)
	local uses_irregular_template              = mw.ustring.sub(templatename, -mw.ustring.len(irregular_templatename_suffix), -1) == irregular_templatename_suffix

	local meta = {}
	meta.numbered_cells       = 14
	meta.named_cells          = {adverb_param}
	meta.pos                  = args[positive_param]  ~= "-"
	meta.comp                 = uses_suffix_comparation and args[comparative_param] ~= "-"
	meta.sup                  = uses_suffix_comparation and args[superlative_param]  ~= "-"
	meta.attr                 = args[attributive_param] ~= "-"
	meta.pred                 = args[predicative_param] ~= "-"
	meta.pers                 = args[personal_param] ~= "-"
	meta.adv                  = args[adverb_param]  ~= "-"
	meta.adv_clear            = not not args[adverb_param]
	meta.pers_clear           = args[personal_param] == "" or args[personal_param] == "-"
	meta.neuter_clear         = does_not_need_neuter_comfirmation or neuter_is_confirmed
	meta.second_declension    = isSecondDeclension(args[comparative_param], args[superlative_param])
	meta.positive_uninflected = positive_forms_are_not_inflected
	meta.alt_paradigm         = has_alternative_inflection_pattern
	meta.suffix_comparison    = uses_suffix_comparation
	meta.uncomp               = can_not_be_compared
	meta.peri                 = uses_mainly_periphrastic_comparation
	meta.irregular            = uses_irregular_template
	
	return meta;
end

function export._getWikitable(forms, meta)
	local number_of_columns                    = meta.suffix_comparison and 5 or 3
	local contains_a_quality_notice            = not not meta.quality_notice
	local uses_suffix_comparation              = meta.suffix_comparison
	local can_be_used_to_describe_a_person     = meta.pers and meta.pers_clear
	local uses_second_declension               = meta.second_declension
	local note                                 = meta.note
	local as_first_part                        = meta.as_first_part
	local adv_cell                             = type(forms.x_adv) == "string" and {'|', forms.x_adv, type='adv'} or forms.x_adv
	local comparation_text                     = ""
	local is_uncomparable                      = meta.uncomp
	local uses_mainly_periphrastic_comparation = meta.peri
	local merge_some_cells                     = not meta.irregular
	
	if uses_suffix_comparation then
		adv_cell[1] = '|colspan="3"'
		comparation_text = "Kan også gradbøyes med '''mer''' og '''mest'''."
	else
		if is_uncomparable then
			comparation_text = "Gradbøyes ikke."
		elseif uses_mainly_periphrastic_comparation then
			comparation_text = "Gradbøyes med '''mer''' og '''mest'''."
		end
	end

	gt.setLanguage(lang_code_param)

	local str = gt.getStart(number_of_columns, lang_code_param, part_of_speech_param, contains_a_quality_notice)
	
	if uses_suffix_comparation then
		str = str
		.. gt.getRow({'!class="main min" rowspan="2" colspan="2"', 'Bøyning av ' .. meta.pagename .. ' ' .. meta.meanings}, {'!', 'Positiv'}, {'!', 'Komparativ'}, {'!', 'Superlativ'})
		.. gt.getRow({'!colspan="3"', 'Attributivt'})

		if merge_some_cells and can_be_used_to_describe_a_person then
			if uses_second_declension then
				str = str
				.. gt.getRow({'!rowspan="2"', 'Ubestemt<br/>entall'},	{'!', 'Felleskjønn'},	forms.attr_obest_sing_utrum_pos,   {'|rowspan="5"', forms.attr_komp},     {'!rowspan="2"'})
				.. gt.getRow(						{'!', 'Intetkjønn'},	forms.attr_obest_sing_neutrum_pos)
				.. gt.getRow({'!rowspan="2"', 'Bestemt<br/>entall'},	{'!', 'Hankjønn'},	forms.attr_best_sing_mask_pos, forms.attr_best_sing_mask_sup)
				.. gt.getRow(						{'!', 'Alle'},		forms.attr_best_sing_alla_pos,	{'|rowspan="2"', forms.attr_sup})
				.. gt.getRow({'!colspan="2"', 'Flertall'},										forms.attr_plur_pos)
			else
				str = str
				.. gt.getRow({'!rowspan="2"', 'Ubestemt<br/>entall'},	{'!', 'Felleskjønn'},	forms.attr_obest_sing_utrum_pos,   {'|rowspan="5"', forms.attr_komp},     {'!rowspan="2"'})
				.. gt.getRow(						{'!', 'Intetkjønn'},	forms.attr_obest_sing_neutrum_pos)
				.. gt.getRow({'!rowspan="2"', 'Bestemt<br/>entall'},	{'!', 'Hankjønn'},	forms.attr_best_sing_mask_pos, {'|rowspan="3"', forms.attr_sup})
				.. gt.getRow(						{'!', 'Alle'},		forms.attr_best_sing_alla_pos)
				.. gt.getRow({'!colspan="2"', 'Flertall'},										forms.attr_plur_pos)
			end
		else
			str = str
			.. gt.getRow({'!rowspan="2"', 'Ubestemt<br/>entall'},		{'!', 'Felleskjønn'},	forms.attr_obest_sing_utrum_pos,   {'|rowspan="2"', forms.attr_komp},     {'!rowspan="2"'})
			.. gt.getRow(							{'!', 'Intetkjønn'},	forms.attr_obest_sing_neutrum_pos)
			.. gt.getRow({'!rowspan="2"', 'Bestemt<br/>flertall'},		{'!', 'Hankjønn'},	forms.attr_best_sing_mask_pos,     forms.attr_komp_mask, forms.attr_best_sing_mask_sup)
			.. gt.getRow(							{'!', 'Alle'},		forms.attr_best_sing_alla_pos,     {'|rowspan="2"', forms.attr_komp}, {'|rowspan="2"', forms.attr_sup})
			.. gt.getRow({'!colspan="2"', 'Flertall'},						forms.attr_plur_pos)
		end

		str = str
		.. gt.getRow({'!colspan="2"'},                   			{'!colspan="3"', 'Predikativt'})
		.. gt.getRow({'!rowspan="2"', 'Entall'},              			{'!', 'Felleskjønn'},		forms.pred_sing_utrum_pos,         {'|rowspan="3"', forms.pred_komp},     {'|rowspan="3"', forms.pred_sup})
		.. gt.getRow(                                       		    	{'!', 'Intetkjønn'},	forms.pred_sing_neutrum_pos)
		.. gt.getRow({'!colspan="2"', 'Flertall'},												forms.pred_plur_pos)
		.. gt.getRow({'!colspan="5"', comparation_text})
		.. gt.getRow({'!colspan="2" class="min"', 'Adverbsavledning'},                adv_cell)
	else
		str = str
		.. gt.getRow({'!class="main min" rowspan="2" colspan="2"', 'Bøyning&nbsp;av ' .. meta.pagename .. '&nbsp;' .. meta.meanings}, {'!', 'Positiv'})
		.. gt.getRow({'!', 'Attributivt'})
		.. gt.getRow({'!rowspan="2"', 'Ubestemt<br/>entall'}, 			{'!', 'Felleskjønn'},	forms.attr_obest_sing_utrum_pos)
		.. gt.getRow(                                           		{'!', 'Intetkjønn'},	forms.attr_obest_sing_neutrum_pos)
		.. gt.getRow({'!rowspan="2"', 'Bestemt<br/>entall'},    		{'!', 'Hankjønn'},	forms.attr_best_sing_mask_pos)
		.. gt.getRow(                                           		{'!', 'Alle'},		forms.attr_best_sing_alla_pos)
		.. gt.getRow({'!colspan="2"', 'Flertall'},												forms.attr_plur_pos)
		.. gt.getRow({'!colspan="2"'},                          		{'!', 'Predikativt'})
		.. gt.getRow({'!rowspan="2"', 'Entall'},                		{'!', 'Felleskjønn'},	forms.pred_sing_utrum_pos)
		.. gt.getRow(                                           		{'!', 'Intetkjønn'},	forms.pred_sing_neutrum_pos)
		.. gt.getRow({'!colspan="2"', 'Flertall'},												forms.pred_plur_pos)
		.. gt.getRow({'!colspan="3"', comparation_text})
		.. gt.getRow({'!colspan="2" class="min"', 'Adverbavledning'},         	adv_cell)
	end

	str = str .. gt.getEnd(number_of_columns, note, as_first_part)

	return str
end

function export._getCategories(forms, meta)
	local str                                             = ""
	local neuter_needs_to_but_has_not_been_cleared        = not meta.neuter_clear and meta.attr and meta.pos
	local undecided_if_adjective_can_describe_a_person    = not meta.pers_clear
	local undecided_if_adjective_has_an_adverb_derivative = not meta.adv_clear
	local has_common_inflection_pattern                   = not meta.alt_paradigm
	local uses_alternative_template                       = mw.ustring.sub(meta.templatename, 1, mw.ustring.len(alternative_paradigm_templatename)) == alternative_paradigm_templatename
	
	if neuter_needs_to_but_has_not_been_cleared then
		str = str .. "[[Kategori:Wiktionary:sv-adj/Mangler intetkjønnsparameter]]"
	end

	if undecided_if_adjective_can_describe_a_person then
		str = str .. "[[Kategori:Wiktionary:sv-adj/Mangler personparameter]]"
	end

	if undecided_if_adjective_has_an_adverb_derivative then
		str = str .. "[[Kategori:Wiktionary:sv-adj/Mangler adverbparameter]]"
	end

	if has_common_inflection_pattern and uses_alternative_template then
		str = str .. "[[Kategori:Wiktionary:sv-adj/Bruker feil mal]]"
	end
	
	return str
end

return export