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 or args 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, "d")
local ends_with_consonant_d = not not mw.ustring.find(last_2, "d")
local ends_with_vowel = not not mw.ustring.find(last_1, "")
local plural = nil
local neuter = pagename .. "t"
-- Paramètre 'alt'
if args or args then
if last_1 == "m" then -- équivaut à args = "m"
args = 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 = 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 = without_last_2 .. last_1
elseif last_2 == "dd" then
neuter = without_last_2 .. "tt"
elseif last_2 == "ad" or args 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 or pagename) .. "e"
local comp = (args or pagename) .. "are"
local attr_sup = (args or pagename) .. "aste"
local attr_sup_masc = (args or pagename) .. "aste"
local pred_sup = (args or pagename) .. "ast"
plural = plural or (args or pagename) .. "a"
--
if args then
masc = pagename .. args .. "e"
plural = pagename .. args .. "a"
comp = pagename .. args .. "are"
attr_sup = pagename .. args .. "aste"
attr_sup_masc = pagename .. args .. "aste"
pred_sup = pagename .. args .. "ast"
end
if args or args then
comp = (args .. "re") or comp
attr_sup = (args or args) .. "ste"
attr_sup_masc = (args or args) .. "ste"
pred_sup = (args or args) .. "st"
end
if ends_with_vowel then
neuter = pagename .. "tt"
end
local forms = {}
forms.sing_indef_comm_pos = args or common
forms.sing_indef_neut_pos = args or args or args or neuter
forms.sing_def_masc_pos = args or args or masc
forms.sing_def_aut_pos = args or plural
forms.plur_pos = args or args or plural
forms.comp = args and '' or args or comp
forms.sup_attr_masc = args and '' or args or attr_sup_masc
forms.sup_attr = args and '' or args or attr_sup
forms.sup_pred = args and '' or args 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