Modulo:En-conj

Da Wikizionario, il dizionario a contenuto aperto.

Questo modulo costituisce il codice di funzionamento del Template:En-conj, e crea, in base ai parametri inseriti in quest'ultimo, la tabella di coniugazione dei verbi inglesi. Si compone di una funzione principale, p.enconj (richiamata direttamente nel template) e di due funzioni accessorie (p.wiki e p.alts) che sono utilizzate solo all'interno della funzione principale per abbreviarne il codice.

Il modulo (in particolare la tabella) è stato parzialmente derivato dal Modulo:It-conj.

Funzione p.enconj

È la funzione principale del modulo; interpreta i parametri passati dal template e li utilizza per formare le stringhe per le forme flesse e i tempi composti, che sono poi inserite nella tabella di coniugazione che ne costituisce l'output. Possiede due parametri fondamentali, stem e parse:

  • stem corrisponde al primo parametro del template, ed equivale alla forma del verbo all'infinito (senza la particella to), viene richiamata per formare le forme flesse dei verbi regolari apponendovi le corrispondenti desinenze (ad es stem.. "ed" per il passato semplice)
  • parse corrisponde al secondo parametro del template; riconosce i seguenti valori definiti in base ai quali costruisce automaticamente le forme flesse (per i verbi regolari; si vedano le istruzioni del template): "e", "es", "y", "d" e "doppia". Se invece tale parametro è diverso da tali valori definiti il modulo utilizza per le forme flesse direttamente i parametri passati dal template.

Se sono presenti varianti alternative per il participio presente (ppres2), per il passato semplice (ps2) e participio passato (ppas2), queste vengono aggiunte accanto alla forma base dalla funzione p.alts (vedi sotto).

Il template genera poi i tempi composti, codificandoli in stringhe: pastperf per il passato semplice (simple past), presperf12s per la prima e seconda persona singolare del presente perfetto (present perfect), condpresperf per il presente perfetto condizionale (present perfect conditional) e così via. Tali stringhe per itempi composti, insieme con quelle delle forme base, sono poi inserite nella tabella di coniugazione.

Funzione p.wiki

La funzione p.wiki (p.wiki(x)) rende il suo argomento, x, un wikilink, con "pipe" alla sezione inglese. In pratica, nel modulo, scrivere p.wiki(qualcosa) equivale al wikicodice [[qualcosa#Inglese|qualcosa]].

Inoltre, la funzione controlla, tramite la funzione standard di Scribunto mw.title.new(x).exists (si veda anche qui) se la pagina a cui punta tale link esiste o meno (funziona in modo molto simile alla funzione parser ifexist del codice mediawiki). Se la pagina non esiste, aggiunge al wikilink la Categoria:Verbi inglesi con forme da scrivere, e/o la Categoria:Verbi inglesi da scrivere se ad essere rosso è il link verso la forma all'infinito.

Funzione p.alts

La funzione p.alts (p.alts(x, y)) aggiunge l'eventuale variante alternativa (identificata dal suo secondo argomento, y), se definita, accanto a quella generata automaticamente (identificata dal primo argomento x), separandola con una virgola. Ad esempio, all'interno della funzione principale, il codice

  • ps = p.alts(ps, ps2)

cerca l'eventuale parametro "ps2=" (variante del passato semplice) nel template; se questo è definito lo aggiunge al seguito della forma base base, se non lo è restituisce invece solo quest'ultima.


-- Modulo per la coniugazione dei verbi inglesi; richiamato dal Template:En-conj
p = {}

function p.enconj(frame)
	pframe = frame:getParent()
    args = pframe.args
    stem = args[1]
    parse = args[2]
-- inizializzazione dei parametri interni al modulo
--Tempi semplici
    inf = "" --infinito
    pres = "" --presente semplice
    pres3s = "" --presente semplice, terza persona singolare
    ppres = ""; ppres2= "" --participio presente e relativa variante
    ps = ""; ps2 = "" --passato semplice e relativa variante
    ppas = ""; ppas2 = "" --participio passato e relativa variante
--Tempi composti
    infpas = "" --past infinitive
    gerpas = "" --past gerundive
    fut = ""; --simple future
    presperf12s = ""; presperf3s = ""; presperfp = "" --present perfect
    pastperf = ""; --past perfect
    futperf = ""; --future perfect
    prescont1s = ""; prescont2s = ""; prescont3s= ""; prescontp = "" --present continuous
    pastcont1s = ""; pastcont2s = ""; pastcont3s = ""; pastcontp = "" --past continuous
    futcont = ""; --future continuous
    presperfcont12s = ""; presperfcont3s = ""; presperfcontp = "" --present perfect continuous
    pastperfcont = "" --past perfect continuous
    futperfcont = "" --future perfect continuous
    condpres = "" --present conditional
    condpresperf = "" --present perfect conditional
    condprescont = "" --present continuous conditional
    condpresperfcont = "" --present perfect continuous conditional
    subpresperf = "" --present perfect subjunctive
    subpastperf = "" --past perfect subjunctive
    imp2s = ""; imp1p = ""; imp2p = "" --imperative
    
-- Forme verbali in base al parse
    if parse == nil or parse == "" then
    	inf = p.wiki(stem); pres = p.wiki(stem); pres3s = p.wiki(stem.. "s"); ppres = p.wiki(stem.. "ing"); ps = p.wiki(stem.. "ed"); ppas = p.wiki(stem.. "ed")
	elseif parse == "e" then
		inf = p.wiki(stem); pres = p.wiki(stem); pres3s = p.wiki(stem.. "s"); ppres = p.wiki(stem.sub(stem, 1, -2).. "ing"); ps = p.wiki(stem.. "d"); ppas = p.wiki(stem.. "d")
	elseif parse == "es" then
		inf = p.wiki(stem); pres = p.wiki(stem); pres3s = p.wiki(stem.. "es"); ppres = p.wiki(stem.. "ing"); ps = p.wiki(stem.. "ed"); ppas = p.wiki(stem.. "ed")
	elseif parse == "d" then
		inf = p.wiki(stem); pres = p.wiki(stem); pres3s = p.wiki(stem.. "s"); ppres = p.wiki(stem.. "ing"); ps = p.wiki(stem.. "d"); ppas = p.wiki(stem.. "d")
    elseif parse == "y" then
		inf = p.wiki(stem); pres = p.wiki(stem); pres3s = p.wiki(stem.sub(stem, 1, -2).. "ies"); ppres = p.wiki(stem.. "ing"); ps = p.wiki(stem.sub(stem, 1, -2).. "ied"); ppas = p.wiki(stem.sub(stem, 1, -2).. "ied")
    elseif parse == "doppia" then
		inf = p.wiki(stem); pres = p.wiki(stem); pres3s = p.wiki(stem.. "s"); ppres = p.wiki(stem.. stem.sub(stem, -1).. "ing"); ps = p.wiki(stem.. stem.sub(stem, -1).. "ed"); ppas = p.wiki(stem.. stem.sub(stem, -1).. "ed")
	else --verbi irregolari, si inseriscono i parametri manualmente
		inf = p.wiki(args[1]); pres = p.wiki(args[1]); pres3s = p.wiki(args[2]); ppres = p.wiki(args[3]); ps = p.wiki(args[4]); if args[5] == nil then ppas = p.wiki(args[4]) else ppas = p.wiki(args[5]) end
	end

-- Eventuali forme varianti
    ppres2 = p.wiki(args["ppres2"])
    ppres = p.alts(ppres,ppres2)
    ps2 = p.wiki(args["ps2"])
    ps = p.alts(ps,ps2)
    ppas2 = p.wiki(args["ppass2"])
    ppas = p.alts(ppas,ppas2)
    
-- Tempi composti
-- tempi composti che utilizzano il participio presente (progressivi)
    prescont1s = '[[am]] '.. ppres; prescont2s = '[[are]] '.. ppres; prescont3s = '[[is]] '.. ppres; prescontp = '[[are]] '.. ppres --present continuous
    pastcont1s = '[[was]] '.. ppres; pastcont2s = '[[were]] '.. ppres; pastcont3s = '[[was]] '.. ppres; pastcontp = '[[were]] '.. ppres --past continuous
    futcont = '[[will]] [[be]] '.. ppres --future continuous
    presperfcont12s = '[[have]] [[been]] '.. ppres; presperfcont3s = '[[has]] [[been]] '.. ppres; presperfcontp = '[[have]] [[been]] '.. ppres --present perfect continuous
    pastperfcont = '[[had]] [[been]] '.. ppres --past perfect continuous
    futperfcont ='[[will]] [[have]] [[been]] '.. ppres --future perfect continuous
    condprescont = '[[would]] [[be]] '.. ppres --present continuous conditional
    condpresperfcont = '[[would]] [[have]] [[been]] '.. ppres --present perfect continuous conditional
-- tempi composti che utilizzano il participio passato (perfetti)
    infpas = 'to [[have]] '.. ppas --past infinitive
    gerpas = '[[having]] '.. ppas --past gerundive
    presperf12s = '[[have]] '.. ppas; presperf3s = '[[has]] '.. ppas; presperfp = '[[have]] '.. ppas --present perfect
    pastperf = '[[had]] '.. ppas --past perfect
    futperf = '[[will]] [[have]] '.. ppas --future perfect
    condpresperf = '[[would]] [[have]] '.. ppas --present perfect conditional
    subpresperf = '[[have]] '.. ppas --present perfect subjunctive
    subpastperf = '[[had]] '.. ppas --past perfect subjunctive

-- Costruisce la tabella di coniugazione
    conj = '{| style="background:#F0F0F0;border-collapse:separate;border-spacing:2px;float=center" class="inflection-table"\n'
    conj = conj .. '|-\n'
    conj = conj .. '! colspan="7" style="background:#e2e4c0" | forme impersonali\n'
    conj = conj .. '|-\n! colspan="2" style="background:#e2e4c0" | infinito\n'
    conj = conj .. '| colspan="1" | to '.. inf.. '\n'
    conj = conj .. '! colspan="2" style="background:#e2e4c0" | infinito passato\n'
    conj = conj .. '| colspan="2" | '.. infpas.. '\n'
    conj = conj .. '|-\n! colspan="2" style="background:#e2e4c0" | gerundio\n'
    conj = conj .. '| colspan="1" |'.. ppres.. '\n'
    conj = conj .. '! colspan="2" style="background:#e2e4c0" | gerundio passato\n'
    conj = conj .. '| colspan="2" | '.. gerpas.. '\n'
    conj = conj .. '|-\n! colspan="2" style="background:#e2e4c0" | participio presente\n'
    conj = conj .. '| colspan="1" |'.. ppres.. '\n'
    conj = conj .. '! colspan="2" style="background:#e2e4c0" | participio passato\n'
    conj = conj .. '| colspan="2" |'.. ppas.. '\n'
    conj = conj .. '|-\n'
    conj = conj .. '! colspan="7" style="background:#C0C0C0" | forme personali\n'
    conj = conj .. '|-\n! colspan="1" rowspan="2" style="background:#C0C0C0" | persona\n'
    conj = conj .. '! colspan="3" style="background:#C0C0C0" | singolare\n'
    conj = conj .. '! colspan="3" style="background:#C0C0C0" | plurale\n'
    conj = conj .. '|-\n! style="background:#C0C0C0;width:12.5%" | prima\n'
    conj = conj .. '! style="background:#C0C0C0;width:12.5%" | seconda\n'
    conj = conj .. '! style="background:#C0C0C0;width:12.5%" | terza\n'
    conj = conj .. '! style="background:#C0C0C0;width:12.5%" | prima\n'
    conj = conj .. '! style="background:#C0C0C0;width:12.5%" | seconda\n'
    conj = conj .. '! style="background:#C0C0C0;width:12.5%" | terza\n'
    conj = conj .. '|-\n! style="background:#c0cfe4" colspan="1" | indicativo</br><small>indicative</small>\n'
    conj = conj .. '! style="background:#c0cfe4" | I\n'
    conj = conj .. '! style="background:#c0cfe4" | you\n'
    conj = conj .. '! style="background:#c0cfe4" | he/she/it\n'
    conj = conj .. '! style="background:#c0cfe4" | we\n'
    conj = conj .. '! style="background:#c0cfe4" | you\n'
    conj = conj .. '! style="background:#c0cfe4" | they\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | presente semplice</br><small>simple present</small>\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="2" |'.. pres.. '\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" |'.. pres3s.. '\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="3" |'.. pres.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | passato semplice</br><small>simple past</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" |'.. ps.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | futuro semplice</br><small>simple future</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" | [[will]] '.. inf.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | presente perfetto</br><small>present perfect</small>\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="2" | '.. presperf12s.. '\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | '.. presperf3s.. '\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="3" | '.. presperfp.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | piuccheperfetto</br><small>past perfect</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" | '.. pastperf.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | futuro perfetto</br><small>future perfect</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" | '.. futperf.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | presente progressivo</br><small>present continuous</small>\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | '.. prescont1s.. '\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | '.. prescont2s.. '\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | '.. prescont3s.. '\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="3" | '.. prescontp.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | passato progressivo</br><small>past continuous</small>\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | '.. pastcont1s.. '\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | '.. pastcont2s.. '\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | '.. pastcont3s.. '\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="3" | '.. pastcontp.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | futuro progressivo</br><small>future continuous</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" | '.. futcont.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | presente perfetto prog.</br><small>present perfect continuous</small>\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="2" | '.. presperfcont12s.. '\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | '.. presperfcont3s.. '\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="3" | '.. presperfcontp.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | piuccheperfetto prog.</br><small>past perfect continuous</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" | '.. pastperfcont.. '\n|-\n'
    conj = conj .. '! style="height:3em;background:#c0cfe4" colspan="1" | futuro perfetto prog.</br><small>future perfect continuous</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" | '.. futperfcont.. '\n|-\n'
    conj = conj .. '|-\n! style="background:#c0d8e4" colspan="1" | condizionale</br><small>conditional</small>\n'
    conj = conj .. '! style="background:#c0d8e4" | I\n'
    conj = conj .. '! style="background:#c0d8e4" | you\n'
    conj = conj .. '! style="background:#c0d8e4" | he/she/it\n'
    conj = conj .. '! style="background:#c0d8e4" | we\n'
    conj = conj .. '! style="background:#c0d8e4" | voi\n'
    conj = conj .. '! style="background:#c0d8e4" | they\n'
    conj = conj .. '|-\n! style="height:3em;background:#c0d8e4" colspan="1" | presente </br><small>present conditional</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" | [[would]] '.. inf.. '\n|-\n'
    conj = conj .. '|-\n! style="height:3em;background:#c0d8e4" colspan="1" | perfetto </br><small>present perfect conditional</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" | '.. condpresperfcont.. '\n|-\n'
    conj = conj .. '|-\n! style="height:3em;background:#c0d8e4" colspan="1" | presente progressivo </br><small>present continuous conditional</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" | '.. condprescont.. '\n|-\n'
    conj = conj .. '|-\n! style="height:3em;background:#c0d8e4" colspan="1" | presente perfetto prog. </br><small>present perfect continuous cond.</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" | '.. condpresperfcont.. '\n|-\n'
    conj = conj .. '|-\n! style="background:#c0e4c0" colspan="1" | congiuntivo</br><small>subjunctive</small>\n'
    conj = conj .. '! style="background:#c0e4c0" | I\n'
    conj = conj .. '! style="background:#c0e4c0" | you\n'
    conj = conj .. '! style="background:#c0e4c0" | he/she/it\n'
    conj = conj .. '! style="background:#c0e4c0" | we\n'
    conj = conj .. '! style="background:#c0e4c0" | voi\n'
    conj = conj .. '! style="background:#c0e4c0" | they\n'
    conj = conj .. '|-\n! style="height:3em;background:#c0e4c0" colspan="1" | presente </br><small>present subjunctive</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" |'.. pres.. '\n|-\n'
    conj = conj .. '|-\n! style="height:3em;background:#c0e4c0" colspan="1" | passato </br><small>past subjunctive</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" |'.. ps.. '\n|-\n'
    conj = conj .. '|-\n! style="height:3em;background:#c0e4c0" colspan="1" | presente perfetto </br><small>present perfect subjunctive</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" |'.. subpresperf.. '\n|-\n'
    conj = conj .. '|-\n! style="height:3em;background:#c0e4c0" colspan="1" | piuccheperfetto </br><small>past perfect subjunctive</small>\n'
    conj = conj .. '| style="height:3em;background:#D8D8D8;text-align:center" colspan="6" |'.. subpastperf.. '\n|-\n'
    conj = conj .. '|-\n! style="background:#e4d4c0" colspan="1" | imperativo</br><small>imperative</small>\n'
    conj = conj .. '! style="background:#e4d4c0" | -\n'
    conj = conj .. '! style="background:#e4d4c0" | you\n'
    conj = conj .. '! style="background:#e4d4c0" | -\n'
    conj = conj .. '! style="background:#e4d4c0" | we\n'
    conj = conj .. '! style="background:#e4d4c0" | you\n'
    conj = conj .. '! style="background:#e4d4c0" | -\n|-\n'
    conj = conj .. '! style="height:3em;background:#e4d4c0" colspan="1" | presente</br><small>present imperative</small>\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | \n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" |'.. pres.. '\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | \n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" |'.. "[[let]]'[[us|s]] ".. inf.. '\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" |'.. pres.. '\n'
    conj = conj .. '| style="height:3em;background:#f2f2f2;text-align:center" colspan="1" | \n'
    conj = conj .. '|}'
    return conj 
end

function p.wiki(x)
-- Utilizzato all'interno della funzione itconj
    if x == nil then return " " end
    if x == "" then return " " end
    -- aggiunge la categoria link rossi
    if x == (stem) then --per la voce all'infinito
    	if x >= "a" and mw.title.new(x).exists == false then
    	RedCat = "[[Categoria:Verbi inglesi da scrivere|".. mw.title.getCurrentTitle().subpageText.. "]] "
        else
    	RedCat = ""
    	end
    else --per tutte le altre
    	if x >= "a" and mw.title.new(x).exists == false then
    	RedCat = "[[Categoria:Verbi inglesi con forme da scrivere|".. mw.title.getCurrentTitle().subpageText.. "]] "
        else
    	RedCat = ""
    	end
	end
-- Rende il suo argomento un wikilink, o lo rende nullo se non definito (per facilitare la concatenazione)
    return RedCat.. "[[" .. x .. "#Inglese|" .. x .. "]]"
    end

function p.alts(x,y)
-- Utilizzato all'interno della funzione itconj
-- Aggiunge le eventuali forme alternative, se specificate nel template, separandole da quelle base con una virgola
--    if y == nil then return x end
    if y >= "a" then return x .. ", " .. y end
    return x
end

return p