Moduł:odmiana-czasownik-angielski
Moduł wykorzystywany przez szablon {{odmiana-czasownik-angielski}}.
local p = {}
local function endswith(str, suffix)
return mw.ustring.sub(str, -mw.ustring.len(suffix), -1) == suffix
end
local function generate_3rd(str, parg)
if endswith(str, "y") then
snip = mw.ustring.sub(str, 1, -2)
vowels = {"a", "e", "i", "o", "u"}
for i = 1, 5, 1 do
if endswith(snip, vowels[i]) then
return snip .. "ys"
end
end
return snip .. "ies"
end
endings = {"ch", "s", "sh", "z", "x"}
for i = 1, 5, 1 do
if endswith(str, endings[i]) then
return (string.match(parg, "+") and str .. mw.ustring.sub(str, -1, -1) .. "es") or str .. "es"
end
end
if endswith(str, "o") and not endswith(str, "oo") then
return str .. "es"
end
return str .. "s"
end
local function generate_past(str, parg, frame)
if endswith(str, "y") then
snip = mw.ustring.sub(str, 1, -2)
vowels = {"a", "e", "i", "o", "u"}
for i = 1, 5, 1 do
if endswith(snip, vowels[i]) then
return snip .. "yed"
end
end
return snip .. "ied"
elseif string.match(parg, "+") then
return str .. mw.ustring.sub(str, -1, -1) .. "ed"
elseif endswith(str, "e") then
return str .. "d"
elseif string.match(parg, "l") then
return str .. "ed / " .. frame:expandTemplate{title = "bryt"} .. " " .. str .. "led"
else
return str .. "ed"
end
end
local function generate_gerund(str, parg, frame)
if endswith(str, "e") and not string.match(parg, "e") then
return mw.ustring.sub(str, 1, -2) .. "ing"
elseif string.match(parg, "+") then
return str .. mw.ustring.sub(str, -1, -1) .. "ing"
elseif string.match(parg, "l") then
return str .. "ing / " .. frame:expandTemplate{title = "bryt"} .. " " .. str .. "ling"
else
return str .. "ing"
end
end
function p.main(frame)
local pframe = frame:getParent()
local pargs = pframe.args
local t = {}
local inf = pargs["bezokolicznik"] or mw.title.getCurrentTitle().text
-- Nieregularny: be
if inf == "be" then
t = {
["inf"] = "be", ["1 pres"] = "am", ["1 past"] = "was",
["2 pres"] = mw.ustring.format("are (%s art)", frame:expandTemplate{title = "przest"}),
["2 past"] = mw.ustring.format("were (%s wast / wert)", frame:expandTemplate{title = "przest"}),
["3 pres"] = "is", ["3 past"] = "was", ["pl pres"] = "are", ["pl past"] = "were",
["pres part"] = "being", ["past part"] = "been",
["pres subj"] = mw.ustring.format("be (%s ''2.'' %s beest)", frame:expandTemplate{title = "przest"}, frame:expandTemplate{title = "os"}),
["past subj"] = mw.ustring.format("were (%s ''2.'' %s wert)", frame:expandTemplate{title = "przest"}, frame:expandTemplate{title = "os"}),
["notka"] = "Formy 2. os. lp w nawiasach używane są wyłącznie z zaimkiem [[thou]]."
}
elseif inf == "do" then
t = {
["inf"] = "do", ["1 pres"] = "do", ["1 past"] = "did",
["2 pres"] = mw.ustring.format("do (%s doest / dost)", frame:expandTemplate{title = "przest"}),
["2 past"] = mw.ustring.format("did (%s didst)", frame:expandTemplate{title = "przest"}),
["3 pres"] = mw.ustring.format("does (%s doeth / doth)", frame:expandTemplate{title = "przest"}),
["3 past"] = "did", ["pl pres"] = "do", ["pl past"] = "did",
["pres part"] = "doing", ["past part"] = "done", ["pres subj"] = "do", ["past subj"] = "did",
["notka"] = "Formy 2. os. lp w nawiasach używane są wyłącznie z zaimkiem [[thou]]."
} else
t["inf"] = inf
t["1 pres"] = inf
t["2 pres"] = inf
t["3 pres"] = generate_3rd(inf, pargs[1] or "")
t["pl pres"] = inf
if pargs["nieregularny"] then
local forms = mw.text.split(pargs["nieregularny"], "/", true)
t["1 past"] = forms[1]
t["2 past"] = forms[1]
t["3 past"] = forms[1]
t["pl past"] = forms[1]
t["past part"] = forms[2] or forms[1]
t["past subj"] = forms[1]
else
local past = generate_past(inf, pargs[1] or "", frame)
t["1 past"] = past
t["2 past"] = past
t["3 past"] = past
t["pl past"] = past
t["past part"] = past
t["past subj"] = past
end
if pargs["alternatywny nieregularny"] then
local forms = mw.text.split(pargs["alternatywny nieregularny"], "/", true)
t["1 past"] = t["1 past"] .. " / " .. forms[1]
t["2 past"] = t["2 past"] .. " / " .. forms[1]
t["3 past"] = t["3 past"] .. " / " .. forms[1]
t["pl past"] = t["pl past"] .. " / " .. forms[1]
t["past part"] = t["past part"] .. " / " .. (forms[2] or forms[1])
t["past subj"] = t["past subj"] .. " / " .. forms[1]
end
t["pres part"] = generate_gerund(inf, pargs[1] or "", frame)
t["pres subj"] = inf
end
return frame:expandTemplate{title = "Szablon:odmiana-czasownik-angielski2", args = t}
end
return p