Module:sv-adj

La documentation pour ce module peut être créée à Module:sv-adj/Documentation

local bases = require('Module:bases')
local p = {}

function p.getWikitext(frame)
	-- Reçoit l'appel du modèle
	local args     = frame:getParent().args
	local title    = mw.title.getCurrentTitle()
	local pagename = args["mot"] or args[1] or title.text
	local forms    = p.getForms(pagename, args)
	
	if args.noncomp then
		return p.getTable(pagename, forms, args)
	end
	return p.getTableComp(pagename, forms, args)
end

function p.getForms(pagename, args)
	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 plural = nil
	local neuter = pagename .. "t"
	
	-- Paramètre 'alt'
	if args['alt'] or args['e'] then
		if last_1 == "m" then  -- équivaut à args['raj'] = "m"
			args['rac'] = pagename .. "m"
		elseif last_1 == "t" then
			neuter      = pagename
		elseif last_4 == "mmen" or last_4 == "nnen" or last_4 == "mmal" then
			neuter      = last_1 == "n" and without_last_1 .. "t" or neuter
			args['rac'] = without_last_3 .. last_1
		elseif last_2 == "el" or last_2 == "en" or last_2 == "er" then
			neuter      = last_1 == "n" and without_last_1 .. "t" or neuter
			args['rac'] = without_last_2 .. last_1
		elseif last_2 == "dd" then
			neuter      = without_last_2 .. "tt"
		elseif last_2 == "ad" or args['e'] then
			neuter      = without_last_1 .. "t"
			plural      = pagename .. "e"
		elseif last_2 == "nn" or ends_with_consonant_d then
			neuter      = without_last_1 .. "t"
		end
	end
	
	-- Déclinaison régulière
	local common        = pagename
	local masc          = (args['rac'] or pagename) .. "e"
	local comp          = (args['rac'] or pagename) .. "are"
	local attr_sup      = (args['rac'] or pagename) .. "aste"
	local attr_sup_masc = (args['rac'] or pagename) .. "aste"
	local pred_sup      = (args['rac'] or pagename) .. "ast"
	plural              = plural or (args['rac'] or pagename) .. "a"
	
	--
	if args['raj'] then
		masc            = pagename .. args['raj'] .. "e"
		plural          = pagename .. args['raj'] .. "a"
		comp            = pagename .. args['raj'] .. "are"
		attr_sup        = pagename .. args['raj'] .. "aste"
		attr_sup_masc   = pagename .. args['raj'] .. "aste"
		pred_sup        = pagename .. args['raj'] .. "ast"
	end
	if args['rac-comp'] or args['rac-sup'] then
		comp            = (args['rac-comp'] .. "re") or comp
		attr_sup        = (args['rac-sup'] or args['rac-comp']) .. "ste"
		attr_sup_masc   = (args['rac-sup'] or args['rac-comp']) .. "ste"
		pred_sup        = (args['rac-sup'] or args['rac-comp']) .. "st"
	end
	
	if ends_with_vowel then
		neuter = pagename .. "tt"
	end
	
	local forms = {}
	forms.sing_indef_comm_pos = args[1] or common
	forms.sing_indef_neut_pos = args[2] or args['n'] or args['neutre'] or neuter
	forms.sing_def_masc_pos   = args[3] or args['masc'] or masc
	forms.sing_def_aut_pos    = args[4] or plural
	forms.plur_pos            = args[5] or args['pl'] or plural
	forms.comp                = args['noncomp'] and '' or args[6] or comp
	forms.sup_attr_masc       = args['noncomp'] and '' or args[7] or attr_sup_masc
	forms.sup_attr            = args['noncomp'] and '' or args[8] or attr_sup
	forms.sup_pred            = args['noncomp'] and '' or args[9] or pred_sup
	
	return forms
end

function p.getTableComp(pagename, forms, args)
	
	local m = ''
	if args.masc == '' then
		m = "—\n| —"
	else
		m = bases.lien_modele(forms.sing_def_masc_pos, 'sv') .. "\n"..
			"| " .. bases.lien_modele(forms.sup_attr_masc, 'sv')
	end
	
	-- Construction du code wikitext du tableau
	local txt = '{| class="flextable"\n'..
				'! class="invisible" |\n'..
				'|-\n'..
				"! rowspan=2 colspan=3 |''Déclinaison de " .. pagename .. "''\n"..
				"! rowspan=2| Positif\n"..
				"! rowspan=2| Comparatif\n"..
				"! colspan=2| Superlatif\n"..
				"|-\n"..
				"! Attributif\n"..
				"! Prédicatif\n"..
				"|-\n"..
				"! rowspan=4| Singulier\n"..
				"! rowspan=2| Indéfini\n"..
				"! Commun\n"..
				"| " .. bases.lien_modele(pagename, 'sv') .. "\n"..
				"| rowspan=5| " .. bases.lien_modele(forms.comp, 'sv') .. "\n"..
				"| rowspan=2| —\n"..
				"| rowspan=2| " .. bases.lien_modele(forms.sup_pred, 'sv') .. "\n"..
				"|-\n"..
				"! Neutre\n"..
				"| " .. bases.lien_modele(forms.sing_indef_neut_pos, 'sv') .. "\n"..
				"|-\n"..
				"! rowspan=2| Défini\n"..
				"! Masculin\n"..
				"| " .. m .. "\n"..
				"| rowspan=2| —\n"..
				"|-\n"..
				"! Autres\n"..
				"| " .. bases.lien_modele(forms.sing_def_aut_pos, 'sv') .. "\n"..
				"| " .. bases.lien_modele(forms.sup_attr, 'sv') .. "\n"..
				"|-\n"..
				"! colspan=3| Pluriel\n"..
				"| " .. bases.lien_modele(forms.plur_pos, 'sv') .. "\n"..
				"| " .. bases.lien_modele(forms.sup_attr, 'sv') .. "\n"..
				"| " .. bases.lien_modele(forms.sup_pred, 'sv') .. "\n"..
				"|}\n"
	return txt
end

function p.getTable(pagename, forms, args)
	
	local m = ''
	if args.masc == '' then
		m = "—"
	else
		m = bases.lien_modele(forms.sing_def_masc_pos, 'sv')
	end
	
	-- Construction du code wikitext du tableau
	local txt = '{| class="flextable"\n'..
				'! class="invisible" |\n'..
				'|-\n'..
				"! colspan=3 |''Déclinaison de " .. pagename .. "''\n"..
				"! Positif\n"..
				"|-\n"..
				"! rowspan=4| Singulier\n"..
				"! rowspan=2| Indéfini\n"..
				"! Commun\n"..
				"| " .. bases.lien_modele(pagename, 'sv') .. "\n"..
				"|-\n"..
				"! Neutre\n"..
				"| " .. bases.lien_modele(forms.sing_indef_neut_pos, 'sv') .. "\n"..
				"|-\n"..
				"! rowspan=2| Défini\n"..
				"! Masculin\n"..
				"| " .. m .. "\n"..
				"|-\n"..
				"! Autres\n"..
				"| " .. bases.lien_modele(forms.sing_def_aut_pos, 'sv') .. "\n"..
				"|-\n"..
				"! colspan=3| Pluriel\n"..
				"| " .. bases.lien_modele(forms.plur_pos, 'sv') .. "\n"..
				"|}\n"
	return txt
end

return p