Module:Pt-verb-form-of

local abbrevs = { ["i"]="personal infinitive ", ["g"]="gerund ", ["pp"]="past participle ", ["spp"]="short past participle ", ["lpp"]="long past participle ", ["psi"]="present indicative ", ["ipi"]="imperfect indicative ", ["pti"]="preterite indicative ", ["pli"]="pluperfect indicative ", ["fti"]="future indicative ", ["c"]="conditional ", ["pss"]="present subjunctive ", ["ips"]="imperfect subjunctive ", ["fts"]="future subjunctive ", ["ai"]="affirmative imperative ", ["ni"]="negative imperative ", ["1"]="first-person ", ["2"]="second-person ", ["3"]="third-person ", ["s"]="singular ", ["p"]="plural ", ["m"]="masculine ", ["f"]="feminine ", ["mf"]="masculine and feminine ", [""] = "" }

-- Format: [suffix+conj] = {vf, p, n, which gloss, gender, context} local suffixes = {} suffixes = { ["a1"]={{"psi", "3", "s", 1}, {"ai", "2", "s", 2}}, ["a2"]={{"pss", "1" ,"s", 1}, {"pss", "3", "s", 2}, {"ai", "3", "s", 1}, {"ni", "3", "s", 1}}, ["a3"]={{"pss", "1" ,"s", 1}, {"pss", "3", "s", 2}, {"ai", "3", "s", 1}, {"ni", "3", "s", 1}}, ["e1"]={{"pss", "1", "s", 1}, {"pss", "3", "s", 2}, {"ai", "3", "s", 1}, {"ni", "3", "s", 1}}, ["e2"]={{"psi", "3", "s", 1}, {"ai", "2", "s", 2}}, ["e3"]={{"psi", "3", "s", 1}, {"ai", "2", "s", 2}}, ["i2"]=, ["i3"]={{"pti", "1", "s"}, {"ai", "2", "p"}}, ["o1"]=, ["o2"]=, ["o3"]=, ["ai1"]=, ["am1"]=, ["am2"]={{"pss", "3", "p"}, {"ai", "3", "p"}, {"ni", "3", "p"}}, ["am3"]={{"pss", "3", "p"}, {"ai", "3", "p"}, {"ni", "3", "p"}}, ["ar1"]={{"i", "1", "s", 1}, {"i", "3", "s", 1}, {"fts", "1", "s", 1}, {"fts", "3", "s", 2}}, ["as1"]=, ["as2"]={{"pss", "2", "s"}, {"ni", "2", "s"}}, ["as3"]={{"pss", "2", "s"}, {"ni", "2", "s"}}, ["ei1"]=, ["ei2"]=, ["em1"]={{"pss", "3", "p"}, {"ai", "3", "p"}, {"ni", "3", "p"}}, ["em2"]=, ["em3"]=, ["er2"]={{"i", "1", "s", 1}, {"i", "3", "s", 1}, {"fts", "1", "s", 1}, {"fts", "3", "s", 2}}, ["es1"]={{"pss", "2", "s"}, {"ni", "2", "s"}}, ["es2"]=, ["es3"]=, ["eu2"]=, ["ia2"]={{"ipi", "1", "s"}, {"ipi", "3", "s"}}, ["ia3"]={{"ipi", "1", "s"}, {"ipi", "3", "s"}}, ["ir3"]={{"i", "1", "s", 1}, {"i", "3", "s", 1}, {"fts", "1", "s", 1}, {"fts", "3", "s", 2}}, ["is3"]=, ["iu3"]=, ["ou1"]=, ["ada1"]=, ["ado1"]=, ["ais1"]=, ["ais2"]={{"pss", "2", "p"}, {"ni", "2", "p"}}, ["ais3"]={{"pss", "2", "p"}, {"ni", "2", "p"}}, ["ara1"]={{"pli", "1", "s"}, {"pli", "3", "s"}}, ["ará1"]=, ["ava1"]={{"ipi", "1", "s"}, {"ipi", "3", "s"}}, ["eis1"]={{"pss", "2", "p"}, {"ni", "2", "p"}}, ["eis2"]=, ["era2"]={{"pli", "1", "s"}, {"pli", "3", "s"}}, ["erá2"]=, ["iam2"]=, ["iam3"]=, ["ias2"]=, ["ias3"]=, ["ida2"]=, ["ida3"]=, ["ido2"]=, ["ido3"]=, ["ira3"]={{"pli", "1", "s"}, {"pli", "3", "s"}}, ["irá3"]=, ["adas1"]=, ["ados1"]=, ["amos1"]={{"psi", "1", "p", 1}, {"pti", "1", "p", 2, "Brazil"}}, ["amos2"]={{"pss", "1", "p"}, {"ai", "1", "p"}, {"ni", "1", "p"}}, ["amos3"]={{"pss", "1", "p"}, {"ai", "1", "p"}, {"ni", "1", "p"}}, ["ámos1"]=, ["ando1"]=, ["aram1"]={{"pti", "3", "p"}, {"pli", "3", "p"}}, ["arão1"]=, ["aras1"]=, ["arás1"]=, ["arei1"]=, ["arem1"]={{"i", "3", "p", 1}, {"fts", "3", "p", 2}}, ["ares1"]={{"i", "2", "s", 1}, {"fts", "2", "s", 2}}, ["aria1"]={{"c", "1", "s"}, {"c", "3", "s"}}, ["asse1"]={{"ips", "1", "s"}, {"ips", "3", "s"}}, ["aste1"]=, ["avam1"]=, ["avas1"]=, ["emos1"]={{"pss", "1", "p"}, {"ai", "1", "p"}, {"ni", "1", "p"}}, ["emos2"]={{"psi", "1", "p", 1}, {"pti", "1", "p", 2}}, ["endo2"]=, ["eram2"]={{"pti", "3", "p"}, {"pli", "3", "p"}}, ["erão2"]=, ["eras2"]=, ["erás2"]=, ["erei2"]=, ["erem2"]={{"i", "3", "p", 1}, {"fts", "3", "p", 2}}, ["eres2"]={{"i", "2", "s", 1}, {"fts", "2", "s", 2}}, ["eria2"]={{"c", "1", "s"}, {"c", "3", "s"}}, ["esse2"]={{"ips", "1", "s"}, {"ips", "3", "s"}}, ["este2"]=, ["idas2"]=, ["idas3"]=, ["idos2"]=, ["idos3"]=, ["íeis2"]=, ["íeis3"]=, ["imos3"]={{"psi", "1", "p", 1}, {"pti", "1", "p", 2}}, ["indo3"]=, ["iram3"]={{"pti", "3", "p"}, {"pli", "3", "p"}}, ["irão3"]=, ["iras3"]=, ["irás3"]=, ["irei3"]=, ["irem3"]={{"i", "3", "p", 1}, {"fts", "3", "p", 2}}, ["ires3"]={{"i", "2", "s", 1}, {"fts", "2", "s", 2}}, ["iria3"]={{"c", "1", "s"}, {"c", "3", "s"}}, ["isse3"]={{"ips", "1", "s"}, {"ips", "3", "s"}}, ["iste3"]=, ["ardes1"]={{"i", "2", "p", 1}, {"fts", "2", "p", 2}}, ["areis1"]=, ["áreis1"]=, ["ariam1"]=, ["arias1"]=, ["armos1"]={{"i", "1", "p", 1}, {"fts", "1", "p", 2}}, ["assem1"]=, ["asses1"]=, ["astes1"]=, ["áveis1"]=, ["erdes2"]={{"i", "2", "p", 1}, {"fts", "2", "p", 2}}, ["ereis2"]=, ["êreis2"]=, ["eriam2"]=, ["erias2"]=, ["ermos2"]={{"i", "1", "p", 1}, {"fts", "1", "p", 2}}, ["essem2"]=, ["esses2"]=, ["estes2"]=, ["íamos2"]=, ["íamos3"]=, ["irdes3"]={{"i", "2", "p", 1}, {"fts", "2", "p", 2}}, ["ireis3"]=, ["íreis3"]=, ["iriam3"]=, ["irias3"]=, ["irmos3"]={{"i", "1", "p", 1}, {"fts", "1", "p", 2}}, ["issem3"]=, ["isses3"]=, ["istes3"]=, ["áramos1"]=, ["aremos1"]=, ["aríeis1"]=, ["ásseis1"]=, ["ávamos1"]=, ["êramos2"]=, ["eremos2"]=, ["eríeis2"]=, ["êsseis2"]=, ["íramos3"]=, ["iremos3"]=, ["iríeis3"]=, ["ísseis3"]=, ["aríamos1"]=, ["ássemos1"]=, ["eríamos2"]=, ["êssemos2"]=, ["iríamos3"]=, ["íssemos3"]=, }

local export = {} local w

function export.show(frame)

-- This template supports two types of parameter entering: --- by data: manually enter the tense/aspect form, the person, the number, ---         etc.    --- by suffix: enter the conjugation paradigm (1, 2 or 3) and the suffix ---           expected from a regular verb (even if the verb itself isn’t    ---            regular) and the template will automatically find out all the ---           forms that suffix forms. local args = frame:getParent.args w = mw.title.getCurrentTitle.text local l = args[1] -- lemma local vf = args[2] or "" local tg = args["tg"] or "" local tg2 = args["tg2"] or tg or "" local ig = args["ig"] or "" local ig2 = args["ig2"] or ig or "" local obj = args["obj"] or "" local objtr = args["objtr"] or "" local c = args["cx"] or "" local imp = false if (args["imp"]) then imp = true end local data local suf local conj local s = "" if (mw.ustring.sub(l, -2) == "ar") then conj = "1" elseif (mw.ustring.sub(l, -2) == "ir") then conj = "3" else conj = 2 end if (args[2] == nil) then suf = get_suffix(l) --print(suf) end if (args[3] == nil and args[2] ~= "g") then suf = suf or args[2] data = suffixes[suf .. conj] if not data then error('No data for the suffix "' .. suf .. '" and the conjugation "' .. conj .. '".') end local correct_tg, correct_ig for c1 = 1, table.getn(data) do	       if (data[c1][4] == 2) then correct_tg = tg2 correct_ig = ig2 else correct_tg = tg	           correct_ig = ig	        end local context = c	       if (c ~= "" and data[c1][5] ~= nil) then context = context .. ", "	       end context = context .. (data[c1][5] or "") if (c1 > 1) then s = s .. "\n# " end s = s .. def(l, context, data[c1][1], data[c1][2], data[c1][3], correct_tg, correct_ig, imp, obj, objtr) end else local p = args[3] or "" local n = args[4] s = s .. def(l, c, args[2], p, n, tg, ig, imp, obj, objtr) end return s; end

-- Returns the text for the definition and the usex. Parameters: --- l:    lemma --- c:    context (i.e. “Portugal” for “falámos”) --- vf:   verb form (abbreviation) --- p:    person (abbreviation) or gender (for past participle) --- n:    number (abbreviation) --- tg:   transitive sense gloss --- ig:   intransitive sense gloss --- imp:  impersonal --- obj:  object --- objtr: object translation function def(l, c, vf, p, n, tg, ig, imp, obj, objtr) local s = "" if (mw.ustring.len(c) > 0) then s = s .. "(" .. c .. ") " end s = s .. "''" .. abbrevs[p] .. abbrevs[n] if (vf ~= "g" and vf ~= "pp" and vf ~= "spp" and vf ~= "lpp") then s = s .. "(" .. pronoun_notes(vf, p, n) .. ") " end s = s .. abbrevs[vf] .. "of" s = s .. "'' " .. l .. "" s = s .. make_usex(vf, p, n, tg, true, imp, obj, objtr) s = s .. make_usex(vf, p, n, ig, false, imp, obj, objtr) return s end

-- Returns information about the pronouns used with the form. Parameters: --- vf:   verb form (abbreviation) --- p:    person (abbreviation) --- n:    number (abbreviation) function pronoun_notes(vf, p, n)   local s = "ele and ela, also used with você"            else                s = s .. "eles#Portuguese|eles and elas, also used with vocês"            end            s = s .. " and others" else if (n == "s") then s = s .. "você]]'''" else s = s .. "vocês]]'''" end end else if (p == "2") then if (n == "s") then s = s .. "tu#Portuguese|tu" else s = s .. "vós#Portuguese|vós" end if (vf == "ni" or vf == "ai") then s = s .. "]], sometimes used with [[" if (n == "s") then s = s .. "você#Portuguese|você" else s = s .. "vocês#Portuguese|vocês" end end else if (n == "s") then s = s .. "eu#Portuguese|eu" else s = s .. "nós#Portuguese|nós" end end s = s .. "]]'''"   end return s; end

-- Returns the word’s inflectional suffix. function get_suffix(l) local suf4 = mw.ustring.sub(l, -4) local suf3 = mw.ustring.sub(l, -3) local wsuf if (suf4 == "guer" or suf4 == "guir" or suf4 == "quer" or suf4 == "quir") then wsuf = mw.ustring.sub(w, mw.ustring.len(l) - mw.ustring.len(w) - 3) if (mw.ustring.sub(wsuf, 1, 1) == "u") then wsuf = mw.ustring.sub(wsuf, 2) end else wsuf = mw.ustring.sub(w, mw.ustring.len(l) - mw.ustring.len(w) - 2) local fl = mw.ustring.sub(wsuf, 1, 1) -- first letter local ftl = mw.ustring.sub(wsuf, 1, 2) -- first two letters if (suf3 == "car" or suf3 == "gar") then if (mw.ustring.sub(wsuf, 1, 1) == "u") then wsuf = mw.ustring.sub(wsuf, 2) end elseif (suf3 == "air" or suf3 == "uir") then if (ftl == "io" or ftl == "ia") then wsuf = mw.ustring.sub(wsuf, 2) elseif (fl == "í") then if (suffixes[wsuf .. "3"] == nil) then wsuf = "i" .. mw.ustring.sub(wsuf, 2) end elseif (wsuf == "i" or wsuf == "is") then wsuf = "e" .. mw.ustring.sub(wsuf, 2) end elseif (suf3 == "ear") then if (fl == "i") then wsuf = mw.ustring.sub(wsuf, 2) end elseif (suf3 == "oer") then if (fl == "i") then wsuf = "e" .. mw.ustring.sub(wsuf, 2) elseif (fl == "í" and mw.ustring.len(wsuf <=3)) then wsuf = "i" .. mw.ustring.sub(wsuf, 2) end end end return wsuf end

-- Generates an automatic usage example. Returns an empty string if one can’t be -- generated.

-- parameters: --- vf:   verb form (abbreviation) --- p:    person (abbreviation) --- n:    number (abbreviation) --- g:    gloss --- tr:   whether the verb sense is transitive --- imp:  (boolean) whether the verb is impersonal (i.e. chover, gear) --- obj:  the object; default “isso” --- objtr: the object’s translation; default “this”

-- The gloss should be the English form that translates the Portuguese one. -- For example, the form of ‘to be’ to be used is: --- be:   ai, ni, fti, c, pss, i --- am:    psi 1s, fts 1s --- is:   psi 3s, fts 3s --- are   psi 2s p, fts 2s p --- was:   pti 1s 3s, ipi 1s 3s --- were: pti 2s p, ipi 2s p, ips --- been: pp, lpp, spp, pli --- being: g function make_usex(vf, p, n, g, tr, imp, obj, objtr) if (g == "") then return "" end local pt = "" local en = "" local ww   if (mw.ustring.len(obj) == 0) then obj = "isso" objtr = "this" end if (vf == "g") then if (imp == true) then pt = pt .. "Aqui está '''" .. w .. "'''"           en = en .. "It is '''" .. g .. "''' here" else pt = pt .. "Conheço a pessoa '''" .. w .. "'''"           en = en .. "I know the person '''" .. g .. "'''"           if (tr) then pt = pt .. " " .. obj en = en .. " " .. objtr end end

elseif (vf == "pp" or vf == "lpp" or vf == "spp") then if (p == "m" and n == "s") then if (imp == true) then pt = pt .. "Havia '''" .. w .. "'''"               en = en .. "It had '''" .. g .. "'''"           else pt = pt .. "Alguém havia '''" .. w .. "'''"               en = en .. "Someone had '''" .. g .. "'''"               if (tr == true) then pt = pt .. " " .. obj en = en .. " " .. objtr end end else return "" end

else if (vf == "ni" or vf == "ai") then ww = w           if (p == "1") then en = en .. "'''Let’s" if (vf == "ni") then pt = pt .. "Não " en = en .. " not " else ww = capitalise(w) en = en .. " "               end else if (p == "2" and n == "s") then pt = pt .. "Tu" elseif (p == "2" and n == "p") then pt = pt .. "Vós" elseif (p == "3" and n == "s") then pt = pt .. "Você" else pt = pt .. "Vocês" end pt = pt .. " aí, " en = en .. "You there, " if (vf == "ni") then pt = pt .. "não " en = en .. "don’t " end en = en .. "'''"           end pt = pt .. "'''" .. ww .. "'''"           en = en .. g .. "'''"           if (tr == true) then pt = pt .. " " .. obj en = en .. " " .. objtr end else if (not(vf=="pss" or vf=="ips" or vf=="fts" or vf=="i")) then pt = pt .. capitalise(get_pron("pt", p, n, "s", imp)) en = en .. capitalise(get_pron("en", p, n, "s", imp)) elseif (vf == "i") then pt = pt .. "Aquilo foi feito para " en = en .. "That was done for " pt = pt .. get_pron("pt", p, n, "s", imp) en = en .. get_pron("en", p, n, "o", imp) else if (vf == "pss") then pt = pt .. "É importante que " en = en .. "It’s important that " elseif (vf == "ips") then pt = pt .. "Seria bom se " en = en .. "It would be nice if " else pt = pt .. "Estará terminado quando " en = en .. "It will be over when " end pt = pt .. get_pron("pt", p, n, "s", imp) en = en .. get_pron("en", p, n, "s", imp) end if (vf == "ipi") then pt = pt .. " frequentemente" en = en .. " often '''" elseif (vf == "pli") then en = en .. " '''had " elseif (vf == "fti") then en = en .. " '''will " elseif (vf == "c") then en = en .. " '''would " elseif (vf == "i") then en = en .. " '''to " else en = en .. " '''"           end pt = pt .. " '''" .. w .. "'''"           en = en .. g .. "'''"           if (tr == true) then pt = pt .. " " .. obj en = en .. " " .. objtr end if (vf == "pti") then pt = pt .. " uma vez" en = en .. " once" end end if (p == "2" or (vf == "ni" or vf == "ai") and p == "3") then if (n == "s") then pt = pt .. " sozinho" en = en .. " by yourself" else pt = pt .. " sozinhos" en = en .. " by yourselves" end end if (vf == "c") then pt = pt .. ", se fosse possível" en = en .. ", if it were possible" end end return "\n#: ''" .. pt .. ".''\n#:: " .. en .. "." end

-- Returns a pronoun. Parameters: --- l: language (“pt” or “en”) --- p: person (“1”, “2” or “3”) --- n: number (“s” or “p”) --- d: declension (“s” for subjective, “o” for objective.) Only relevant for ---   English, Portuguese always returns subjective. --- imp: whether the verb is impersonal -- Does not return “você” or “vocês,” these must be added manually. function get_pron(l, p, n, d, imp) if (l == "en") then if (p == "1") then if (n == "s") then if (d == "s") then return "I" else return "me" end else if (d == "s") then return "we" else return "us" end end elseif (p == "2") then return "you" else if (n == "s") then if (imp == true) then return "it" else if (d == "s") then return "he" else return "him" end end else if (d == "s") then return "they" else return "them" end end end else if (p == "1") then if (n == "s") then return "eu" else return "nós" end elseif (p == "2") then if (n == "s") then return "tu" else return "vós" end else if (imp == true) then return "ele" end if (n == "s") then return "ele" else return "eles" end end end end

-- Returns the parameter string with its first letter uppercase. function capitalise(s) return mw.ustring.upper(mw.ustring.sub(s, 1, 1)) .. mw.ustring.sub(s, 2); end

return export