มอดูล:el-déclinaison-nom

จาก วิกิพจนานุกรม พจนานุกรมเสรี
-- Module el-déclinaison-nom librement inspiré de [[:el:Module:el-nouns-decl]]
--
-- à ajouter: options selon les cas usité (singulier seulement, pluriel seulement,
-- vocatif inusité, génitif pluriel peu/pas usité).

local pagename = mw.title.getCurrentTitle().text

local p = {}

-- tables de déclinaison
local data = mw.loadData('Module:el-déclinaison-nom/data')

function lang_el(mot)
	return  mot 
end

function lien_el(mot)
	if mot == mw.title.getCurrentTitle().prefixedText then
		return '[[' .. mot .. '|' .. lang_el(mot) .. ']]'
	else
		return '[[' .. mot .. '#el|' .. lang_el(mot) .. ']]'
	end
end

-- Fonction auxiliaire pour faire les lignes du tableau.
function ligne_tableau(cas, as, ms, ap, mp, ms2, mp2, class)
    local ligne = '|- class="vsHide" style="background:#f9f9f9" '
    ligne = ligne .. '\r\n! style="background:#dfdfdf" | ' .. cas
    ligne = ligne .. '\r\n| '
    if as ~= nil then
        ligne = ligne .. lang_el(as .. ' ')
    end
    
    ligne = ligne .. '\r\n| <span lang="el" class="form-of ' .. class .. '-singular-form-of lang-el">' .. lien_el(ms) .. '</span>'
    if ms2 ~= nil then
        ligne = ligne .. '<br /><span lang="el" class="form-of ' .. class .. '-singular-form-of lang-el">' .. lien_el(ms2) .. '</span>'
    end
    ligne = ligne .. '\r\n| '
    if ap ~= nil then
        ligne = ligne .. lang_el(ap .. '&nbsp;')
    end
    ligne = ligne .. '\r\n| <span lang="el" class="form-of ' .. class .. '-plural-form-of lang-el">' .. lien_el(mp) .. '</span>'
    if mp2 ~= nil then
        ligne = ligne .. '<br /><span lang="el" class="form-of ' .. class .. '-plural-form-of lang-el">' .. lien_el(mp2) .. '</span>'
    end
    return ligne .. "\r\n"
end

-- Fonction de formatage principale. Les arguments sont des tables comportant
-- des champs ns/as/gs/vs et np/ap/gp/vp pour les différents cas.
function fait_tableau(art, mots, mots2)
    local tableau = [==[
{| class="inflection-table vsSwitcher vsToggleCategory-inflection" cellspacing="1px" style="border: solid 1px #dfdfdf; text-align:left" cellpadding="2"
! class="vsToggleElement" colspan="5" style="background:#dfdfdf; min-width:34em" | การผันรูปของ '']==] .. pagename .. [==[''
|-
|- class="vsHide" style="background:#dfdfdf"
! style="min-width: 10em;" |
! colspan="2" style="min-width: 12em;" | เอกพจน์
! colspan="2" style="min-width: 12em;" | พหูพจน์
]==]
    tableau = tableau .. ligne_tableau("กรรตุการก", art.ns, mots.ns, art.np, mots.np, mots2.ns, mots2.np, 'nom')
    tableau = tableau .. ligne_tableau("สัมพันธการก",   art.gs, mots.gs, art.gp, mots.gp, mots2.gs, mots2.gp, 'gen')
    tableau = tableau .. ligne_tableau("กรรมการก", art.as, mots.as, art.ap, mots.ap, mots2.as, mots2.ap, 'acc')
    tableau = tableau .. ligne_tableau("สัมโพธนการก",      nil, mots.vs,    nil, mots.vp, mots2.vs, mots2.vp, 'voc')
    return tableau .. "|}"
end

function lien_couleur(r, desinence)
    local des_couleur = '<span style="color:DeepPink">' .. desinence .. '</span>'
    return "[[" .. r .. desinence .. "|" .. r .. des_couleur .. "]]"
end

-- Principe: les déclinaisons régulières ont besoin de connaître:
-- * le radical avec son accent premier (désinences courtes)
-- * le radical avec l'accent sur la dernière syllabe (désinence longue)
-- * le radical sans accent (désinence très longue)
-- Ces trois radicaux sont extraits par la fonction radicaux().

local accentue = {
   ['α']='ά',
   ['ε']='έ',
   ['η']='ή',
   ['ι']='ί',
   ['ϊ']='ΐ',
   ['ο']='ό',
   ['υ']='ύ',
   ['ϋ']='ΰ',
   ['ω']='ώ',
}

local sans_accents = {
   ['ά']='α',
   ['έ']='ε',
   ['ή']='η',
   ['ί']='ι',
   ['ΐ']='ϊ',
   ['ό']='ο',
   ['ύ']='υ',
   ['ΰ']='ϋ',
   ['ώ']='ω',
}

-- tronque retourne le mot sans sa desinence. En cas d'argument
-- invalide (si le mot ne termine pas par desinence), renvoie "ERREUR"
function tronque(mot, desinence)
    local l = mw.ustring.len(desinence)
    if l == 0 then
    	return mot
    end
    if mw.ustring.len(mot) < l then
        return "ERREUR"
    end
    if mw.ustring.sub(mot, -l, -1) ~= desinence then
        return "ERREUR"
    end
    return mw.ustring.sub(mot, 1, -l-1)
end

-- radicaux déplace l'accent de l'argument premier et renvoie
-- les trois variantes d'accentuation du radical.
-- Le déplacement peut faire apparaître un tréma:
-- άι -> αϊ (χάιδεμα: caresse)
-- έι -> εϊ (?)
-- όι -> οϊ (κορόιδεμα: moquerie)
-- ύι -> υϊ (?)
-- άυ -> αϋ (πράυνση)
-- έυ -> εϋ (?)
-- όυ -> οϋ (?)
function radicaux(premier)
    local r2 = ""
    local r3 = ""
    local pos_accent = -1 -- position de l'accent
    local voyelle = 0 -- indice de la dernière voyelle
    local i = 0
    -- on fait r3 en enlevant tous les accents
    for c in mw.ustring.gcodepoint(premier) do
    	c = mw.ustring.char(c)
    	i = i + 1
        c2 = sans_accents[c]
        if c2 == nil then c2 = c else pos_accent = i end
        if accentue[c2] ~= nil then voyelle = i end
        if accentue[c2] ~= nil and pos_accent+1 == i then
        	-- une voyelle se trouve juste après l'accent, il faut lui mettre un tréma.
        	if c2 == "ι" then c2 = "ϊ" end
        	if c2 == "υ" then c2 = "ϋ" end
        end
        r3 = r3 .. c2
    end
    if voyelle == 0 then
    	r2 = premier
    else
    	local pre = mw.ustring.sub(r3, 1, voyelle-1)
    	local voy = mw.ustring.sub(r3, voyelle, voyelle)
    	local suf = mw.ustring.sub(r3, voyelle+1, -1)
    	if accentue[voy] ~= nil then voy = accentue[voy] end
    	r2 = pre .. voy .. suf
    end
    return premier, r2, r3
end

-- vedette extrait le mot à traiter du titre de la page (par défaut)
-- ou du premier argument passé à l'invocation.
function vedette(frame)
	if frame.args == nil or frame.args[1] == nil then
		return mw.title.getCurrentTitle().baseText
	else
		return frame.args[1]
	end
end

local artm = {
    ns = "ο",  as = "το(ν)", gs = "του",
    np = "οι", ap = "τους",  gp = "των",
}

local artf = {
    ns = "η",  as = "τη(ν)", gs = "της",
    np = "οι", ap = "τις",   gp = "των",
}

local artn = {
    ns = "το", as = "το", gs = "του",
    np = "τα", ap = "τα", gp = "των",
}

local articles = {m = artm, f = artf, n = artn}

-- decline décline un mot selon un modèle de déclinaison.
function decline(mot, table_decl)
	local r = tronque(mot, table_decl.desinences.ns[2])
	local rads = {radicaux(r)}
	local formes = {}
	local formes_alt = {}
	for cas, x in pairs(table_decl.desinences) do
	   local type_rad, desinence = x[1], x[2]
	   formes[cas] = rads[type_rad] .. desinence
	end
	for cas, x in pairs(table_decl.alt) do
	   local type_rad, desinence = x[1], x[2]
	   formes_alt[cas] = rads[type_rad] .. desinence
	end
	return fait_tableau(articles[table_decl.genre], formes, formes_alt)
end

-- Déclinaisons de noms masculins.
-- - ouranos: ός accentué
-- - dromos/angelos: ος non accentué
-- - antilalos: ος accent fixe
-- - nikitis: ής accentué
-- - navtis: ης non accentué, gén.pl. ών
-- - tamias: ας non accentué, gén.pl. ών
-- - fylakas/agonas: ας non accentué, gén.pl ων
-- - grammateas: -έας, pluriel en -είς
-- - balomatis/sfoungaras/kafes: imparisyllabiques oxytons
-- - manavis: imparisyllabique paroxyton

function p._ouranos(mot)   return decline(mot, data["ouranos"]) end
function p._angelos(mot)   return decline(mot, data["angelos"]) end
function p._antilalos(mot) return decline(mot, data["antilalos"]) end
function p._nikitis(mot)   return decline(mot, data["nikitis"]) end
function p._navtis(mot)    return decline(mot, data["navtis"]) end
function p._tamias(mot)    return decline(mot, data["tamias"]) end
function p._fylakas(mot)   return decline(mot, data["fylakas"]) end
function p._grammateas(mot)  return decline(mot, data["grammateas"]) end
function p._impari_masc(mot) return decline(mot, data["kafes"]) end

-- Les fonctions à utiliser en temps normal (utilisent le titre de page).
function p.ouranos(frame) return p._ouranos(vedette(frame)) end
function p.dromos(frame)  return p._angelos(vedette(frame)) end
function p.angelos(frame) return p._angelos(vedette(frame)) end -- alias
function p.antilalos(frame) return p._antilalos(vedette(frame)) end
function p.nikitis(frame) return p._nikitis(vedette(frame)) end
function p.navtis(frame)  return p._navtis (vedette(frame)) end
function p.tamias(frame)  return p._tamias (vedette(frame)) end
function p.fylakas(frame) return p._fylakas(vedette(frame)) end
function p.agonas(frame)  return p._fylakas(vedette(frame)) end -- alias
function p.grammateas(frame) return p._grammateas(vedette(frame)) end
function p.balomatis(frame)  return p._impari_masc(vedette(frame)) end -- variante en η
function p.sfoungaras(frame) return p._impari_masc(vedette(frame)) end -- variante en α
function p.kafes(frame)      return p._impari_masc(vedette(frame)) end -- variante en ε
function p.manavis(frame)    return p._impari_masc(vedette(frame)) end -- variante en η proparoxyton

-- Modèles de déclinaison de noms féminins
-- - kardia: ά oxyton
-- - ora/thalassa: α non accentué, -ών
-- - elpida/salpigga: α non accentué, -ων non accentué
-- - psychi: ή oxyton
-- - niki: η, -ών
-- - nosos: oς paroxyton
-- - diametros: ος proparoxyton
-- - skepsi/dynami: η, -εως
-- - giagia/alepou: imparisyllabiques

function p._kardia(mot) return decline(mot, data["kardia"]) end
function p._ora(mot)    return decline(mot, data["ora"])    end
function p._elpida(mot) return decline(mot, data["elpida"]) end
function p._psychi(mot) return decline(mot, data["psychi"]) end
function p._niki(mot)   return decline(mot, data["niki"])   end
function p._nosos(mot)  return decline(mot, data["nosos"])  end
function p._dynami(mot) return decline(mot, data["dynami"]) end
function p._giagia(mot) return decline(mot, data["giagia"]) end
	
function p.kardia(frame)   return p._kardia(vedette(frame)) end -- ά
function p.ora(frame)      return p._ora   (vedette(frame)) end -- α
function p.thalassa(frame) return p._ora   (vedette(frame)) end -- α
function p.elpida(frame)   return p._elpida(vedette(frame)) end -- α < 3e décl.
function p.salpigga(frame) return p._elpida(vedette(frame)) end -- α < 3e décl.
function p.psychi(frame)   return p._psychi(vedette(frame)) end -- ή
function p.niki(frame)     return p._niki  (vedette(frame)) end -- η
function p.nosos(frame)    return p._nosos (vedette(frame)) end -- ος
function p.dynami(frame)   return p._dynami(vedette(frame)) end -- η/εις
function p.skepsi(frame)   return p._dynami(vedette(frame)) end -- η/εις
function p.giagia(frame)   return p._giagia(vedette(frame)) end -- pluriel δες
function p.alepou(frame)   return p._giagia(vedette(frame)) end -- pluriel δες

-- Modèles de noms neutres
-- bouno: ό oxyton
-- pevko: ο accent fixe
-- prosopo: -ο accent qui descend
-- provato: -ο accent qui descend optionnellement
-- paidi: -ί oxyton
-- tragoudi: -ι gén. -ιού
-- kyma/onoma: -μα/-ματα
-- desimo: -μο/-ματα
-- meros/edafos: -ος gén. -ους
-- anthos: -ος gén.pl. -έων
-- kreas:  -ας/-ατα
-- mellon: -ον/-οντα

function p._bouno(mot)    return decline(mot, data["bouno"])    end
function p._pevko(mot)    return decline(mot, data["pevko"])    end
function p._prosopo(mot)  return decline(mot, data["prosopo"])  end 
function p._provato(mot)  return decline(mot, data["provato"])  end 
function p._paidi(mot)    return decline(mot, data["paidi"])    end
function p._tragoudi(mot) return decline(mot, data["tragoudi"]) end
function p._onoma(mot)    return decline(mot, data["onoma"])    end
function p._desimo(mot)   return decline(mot, data["desimo"])   end
function p._meros(mot)    return decline(mot, data["meros"])    end
function p._kreas(mot)    return decline(mot, data["kreas"])    end
function p._mellon(mot)   return decline(mot, data["mellon"])   end

function p.bouno(frame)  return p._bouno(vedette(frame)) end -- -ό
function p.pevko(frame)  return p._pevko(vedette(frame)) end -- -ο
function p.prosopo(frame)  return p._prosopo (vedette(frame)) end -- -ο
function p.provato(frame)  return p._provato (vedette(frame)) end -- -ο
function p.paidi(frame)    return p._paidi   (vedette(frame)) end -- -ί
function p.tragoudi(frame) return p._tragoudi(vedette(frame)) end -- -ι
function p.kyma(frame)   return p._onoma(vedette(frame)) end -- -μα
function p.onoma(frame)  return p._onoma(vedette(frame)) end -- -μα
function p.desimo(frame) return p._desimo(vedette(frame)) end -- -μο
function p.meros(frame)  return p._meros(vedette(frame)) end -- -ος
function p.edafos(frame) return p._meros(vedette(frame)) end -- -ος
function p.kreas(frame)  return p._kreas(vedette(frame)) end -- -ας/-ατα
function p.mellon(frame) return p._mellon(vedette(frame)) end -- -ν/-ντα

-- Fonctions de test.

function p.test_masculins(frame)
	return p._ouranos("ουρανός") .. "\r\n" ..
	       p._angelos("λόγος") .. "\r\n" ..
	       p._angelos("άνθρωπος") .. "\r\n" ..
	       p._antilalos("αντίλαλος") .. "\r\n" ..
	       p._nikitis("νικητής") .. "\r\n" ..
	       p._impari_masc("μπαλοματής") .. "\r\n" ..
	       p._navtis("μετανάστης") .. "\r\n" ..
	       p._impari_masc("μανάβης") .. "\r\n" ..
	       p._tamias("ταμίας") .. "\r\n" ..
	       p._fylakas("αγώνας") .. "\r\n" ..
	       p._fylakas("φύλακας") .. "\r\n" ..
	       p._impari_masc("σφουγγαράς") .. "\r\n" ..
	       p._impari_masc("καφές")
end

function p.test_feminins(frame)
    return p._kardia("καρδιά") .. "\r\n" ..
	       p._ora("ώρα") .. "\r\n" ..
	       p._ora("θάλασσα") .. "\r\n" ..
           p._elpida("ελπίδα") .. "\r\n" ..
           p._elpida("σάλπιγγα") .. "\r\n" ..
           p._dynami("δύναμη") .. "\r\n" ..
           p._dynami("σκέψη") .. "\r\n" ..
           p._giagia("γιαγιά") .. "\r\n" ..
           p._giagia("αλεπού") .. "\r\n"
end

function p.test_neutres(frame)
    return p._bouno("βουνό") .. "\r\n" ..
           p._pevko("πεύκο") .. "\r\n" ..
           p._pevko("σίδερο") .. "\r\n" .. -- exemple proparoxyton chez Triantafyllidis
           p._prosopo("πρόσωπο") .. "\r\n" ..
           p._provato("πρόβατο") .. "\r\n" ..
           p._paidi("παιδί") .. "\r\n" ..
           p._tragoudi("τραγούδι") .. "\r\n" ..
           p._onoma("κύμα") .. "\r\n" ..
           p._onoma("όνομα") .. "\r\n" ..
           p._desimo("δέσιμο") .. "\r\n" ..
           p._meros("μέρος") .. "\r\n" ..
           p._meros("έδαφος") .. "\r\n" ..
           p._kreas("κρέας") .. "\r\n" ..
           -- exemples de Triantafyllidis
           p._mellon("μέλλον") .. "\r\n" ..
           p._mellon("καθήκον") .. "\r\n" ..
           p._mellon("σύμπαν") .. "\r\n" ..
           p._mellon("φωνήεν") .. "\r\n"
end

function p.test_radicaux(frame)
    local ret = [==[
Ce test doit afficher:
* δύναμ, δυνάμ, δυναμ
* όνομ, ονόμ, ονομ
* πόλ, πόλ, πολ
* έτ, έτ, ετ
* φ, φ, φ
* ί, ί, ι
* χάιδεμ, χαϊδέμ, χαϊδεμ
* πράυνσ, πραΰνσ, πραϋνσ

Résultat du test:
]==]
    function test_ligne(r)
    	a, b, c = radicaux(r)
    	return "* " .. a .. ", " .. b .. ", " .. c .. "\r\n"
    end
	ret = ret .. test_ligne("δύναμ")
	ret = ret .. test_ligne("όνομ")
	ret = ret .. test_ligne("πόλ")
	ret = ret .. test_ligne("έτ")
	ret = ret .. test_ligne("φ")
	ret = ret .. test_ligne("ί")
	ret = ret .. test_ligne("χάιδεμ")
	ret = ret .. test_ligne("πράυνσ")
	return ret
end

return p