Module:pl-verb

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Work in progress module for conjugation of Polish verbs.


local export = {}

local m_g = require('Module:gender and number')
local m_links = require('Module:links')
local m_adj = require('Module:pl-adj')
local m_noun = require('Module:pl-noun')
local lang = require("Module:languages").getByCode("pl")

tense_rows = {
	{	tense = "inf";
		title = "infinitive";
		pltitle = "bezokolicznik";
		color = "#e2e4c0";
		inflects_for = {};
	},
	{	tense = "pres";
		title = "present tense";
		pltitle = "czas teraźniejszy";
		color = "#c0cfe4";
		inflects_for = { person = true; impersonal = true; number = true; };
	},
	{	tense = "past";
		title = "past tense";
		pltitle = "czas przeszły";
		color = "#b0e4e4";
		inflects_for = { person = true; impersonal = true; gender = true; number = true; };
	},
	{	tense = "fut";
		title = "future tense";
		pltitle = "czas przyszły";
		color = "#c0e4c0";
		inflects_for = { person = true; impersonal = true; gender = true; number = true; };
	},
	-- single-word future tense for perfective verbs
	{	tense = "sfut";
		title = "future tense";
		pltitle = "czas przyszły prosty";
		color = "#c0e4c0";
		inflects_for = { person = true; impersonal = true; gender = false; number = true; };
	},
	{	tense = "cond";
		title = "conditional";
		pltitle = "tryb przypuszczający";
		color = "#f4f4c0";
		inflects_for = { person = true; impersonal = true; gender = true; number = true; };
	},
	{	tense = "imp";
		title = "imperative";
		pltitle = "tryb rozkazujący";
		color = "#e4d4c0";
		inflects_for = { person = true; number = true; };
	},
	{	tense = "aadj";
		title = "active adjectival participle";
		pltitle = "imiesłów przymiotnikowy czynny";
		color = "#e2e4c0";
		inflects_for = { gender = true; number = true; case = true; };
	},
	{	tense = "padj";
		title = "passive adjectival participle";
		pltitle = "imiesłów przymiotnikowy bierny";
		color = "#e2e4c0";
		inflects_for = { gender = true; number = true; case = true; };
	},
	{	tense = "pastadj";
		title = "past adjectival participle";
		pltitle = "imiesłów przymiotnikowy przeszły";
		color = "#e2e4c0";
		inflects_for = { gender = true; number = true; case = true; };
	},
	{	tense = "cadv";
		title = "contemporary adverbial participle";
		pltitle = "imiesłów przysłówkowy współczesny";
		color = "#e2e4c0";
		inflects_for = {};
	},
	{	tense = "aadv";
		title = "anterior adverbial participle";
		pltitle = "imiesłów przysłówkowy uprzedni";
		color = "#e2e4c0";
		inflects_for = {};
	},
	{	tense = "vn";
		title = "verbal noun\n" .. m_g.format_list({"n-s"}, lang);
		pltitle = "rzeczownik odczasownikowy";
		color = "#e2e4c0";
		inflects_for = { number = true; case = true; };
	}
}

local numbers = {
	{ key = "s"; en = "singular"; pl = "liczba pojedyncza"; },
	{ key = "p"; en = "plural"; pl = "liczba mnoga"; },
}

local genders = {
	{ key = "m"; glist = {"m-s"}; pl = "rodzaj męski"; number = "s"; },
	{ key = "f"; glist = {"f-s"}; pl = "rodzaj żeński"; number = "s"; },
	{ key = "n"; glist = {"n-s"}; pl = "rodzaj nijaki"; number = "s"; },
	{ key = "p"; glist = {"m-pr-p"}; pl = "rodzaj męskoosobowy"; number = "p"; },
	{ key = "o"; glist = {"np-p"}; pl = "rodzaj niemęskoosobowy"; number = "p"; },
}

local persons = {
	{ key = "1"; en = "1<sup>st</sup>"; pl = "pierwsza osoba (ja, my)"; },
	{ key = "2"; en = "2<sup>nd</sup>"; pl = "druga osoba (ty, wy)"; },
	{ key = "3"; en = "3<sup>rd</sup>"; pl = "trzecia osoba (on, ona, ono, pan, pani, oni, one)"; },
}

-- Same as above, but adds the impersonal form.
-- Normally I would append to the previous array, but Lua is so braindead that
-- it doesn't even have an array copy function.
local persons_impersonal = {
	{ key = "1"; en = "1<sup>st</sup>"; pl = "pierwsza osoba (ja, my)"; },
	{ key = "2"; en = "2<sup>nd</sup>"; pl = "druga osoba (ty, wy)"; },
	{ key = "3"; en = "3<sup>rd</sup>"; pl = "trzecia osoba (on, ona, ono, pan, pani, oni, one)"; },
	{ key = "impers"; en = "impersonal"; pl = "forma bezosobowa"; },
}

-- todo: export from Module:pl-noun instead of copying
local cases = {
	{ key = "nom"; en = "nominative, vocative"; pl = "mianownik (kto? co?), wołacz (o!)" },
	{ key = "gen"; en = "genitive"; pl = "dopełniacz (kogo? czego?)" },
	{ key = "dat"; en = "dative"; pl = "celownik (komu? czemu?)" },
	{ key = "acc"; en = "accusative"; pl = "biernik (kogo? co?)" },
	{ key = "ins"; en = "instrumental"; pl = "narzędnik (kim? czym?)" },
	{ key = "loc"; en = "locative"; pl = "miejscownik (o kim? o czym?)" },
	--{ key = "voc"; en = "vocative"; pl = "wołacz (o!)" },
}

-- Generate a table contains true for each space-separated word in str
local function make_lookup_table(str)
	local ret = {}
	for i in mw.ustring.gmatch(str, "%w+") do
		ret[i] = 1
	end
	return ret
end

local function make_link(str)
	local x = [=[if not str then
		return "—"
	else
		local linked = {}
		for word in mw.ustring.gmatch("%a+", str) do
			table.insert(linked, m_links.full_link(word, nil, lang, nil, nil, nil, {}, false))
		end
		return table.concat(linked, " ")
	end]=]
	return str or "—"
end

local function make_row(rowparams, show, conjinfo)
	if show[rowparams.tense] == 0 or (rowparams.subordinate and show[rowparams.subordinate] == 0) then
		return ''
	end
	local l2rows = { "" }
	local tspan = 'colspan="2"'
	if rowparams.inflects_for.person then
		if rowparams.inflects_for.impersonal then
			l2rows = persons_impersonal
		else
			l2rows = persons
		end
		tspan = ('rowspan="%d"'):format(#l2rows)
	elseif rowparams.inflects_for.case then
		l2rows = cases
		tspan = ('rowspan="%d"'):format(#cases)
	end
	row = ('! %s title="%s" style="background:%s" | %s\n'):format(
		tspan, rowparams.pltitle, rowparams.color, rowparams.title)
	for _, l2row in ipairs(l2rows) do
		if l2row ~= "" and show[l2row.key] == 1 then
			row = row .. ('! style="background:%s" title="%s" | %s\n'):format(
				rowparams.color, l2row.pl, l2row.en)
		end
		if l2row == "" or show[l2row.key] == 1 then
			if l2row.key == "impers" then
				local key = rowparams.tense .. "impers"
				row = row .. ('| colspan="%d" | %s\n'):format(show.allcols, make_link(conjinfo[key]))
			-- handling for rows that inflect for gender
			elseif rowparams.inflects_for.gender then
				for i, g in ipairs(genders) do
					if show[g.key] == 1 then
						local key = rowparams.tense .. (l2row.key or l2row) .. g.key
						row = row .. ('| %s\n'):format(make_link(conjinfo[key]))
					end
				end
			-- handling for rows that inflect only by number
			elseif rowparams.inflects_for.number then
				if show.scols > 0 then
					local key = rowparams.tense .. (l2row.key or l2row) .. "s"
					row = row .. ('| colspan="%d" | %s\n'):format(show.scols, make_link(conjinfo[key]))
				end
				if show.pcols > 0 then
					local key = rowparams.tense .. (l2row.key or l2row) .. "p"
					row = row .. ('| colspan="%d" | %s\n'):format(show.pcols, make_link(conjinfo[key]))
				end
			-- handling for rows that do not inflect at all (e.g. infinitive)
			else
				local key = rowparams.tense .. (l2row.key or l2row)
				row = row .. ('| colspan="%d" | %s\n'):format(show.allcols, make_link(conjinfo[key]))
			end
			row = row .. '|-\n'
		end
	end
	return row
end

function export.make_table_markup(conjinfo, hide)
	local show = make_lookup_table("m f n p o 1 2 3 impers "
		.. "inf pres past fut cond "
		.. "imp aadj padj cadv aadv vn nom gen dat acc ins loc voc")

	for k, _ in pairs(hide) do
		show[k] = 0
	end

	show.scols = show.m + show.f + show.n
	show.pcols = show.p + show.o
	show.allcols = show.scols + show.pcols

	if show.allcols == 0 then
		error("All colums hidden")
	end

	header = (
[=[<div class="NavFrame">
<div class="NavHead inflection-table-verb">Conjugation of %s</div>
<div class="NavContent">
{| class="inflection-table wikitable" style="width: 100%%; background: #F0F0F0; margin: 0 auto"
]=]):format(conjinfo.inf)

	local numbers_row = [=[! rowspan="2" style="background:#C0C0C0" | &nbsp;
! style="background:#C0C0C0" | &nbsp;
]=]
	if show.scols > 0 then
		numbers_row = numbers_row ..
			('! colspan="%d" title="%s" style="background:#C0C0C0" | singular\n')
			:format(show.scols, numbers[1].pl)
	end
	if show.pcols > 0 then
		numbers_row = numbers_row ..
			('! colspan="%d" title="%s" style="background:#C0C0C0" | plural\n')
			:format(show.pcols, numbers[2].pl)
	end
	numbers_row = numbers_row .. "|-\n"

	local genders_row = '! style="background:#C0C0C0" | person\n'
	for _, g in ipairs(genders) do
		if show[g.key] then
			genders_row = genders_row ..
				('! title="%s" style="background:#C0C0C0" | %s\n')
				:format(g.pl, m_g.format_list(g.glist, lang))
		end
	end
	genders_row = genders_row .. "|-\n"

	rows = {}
	for _, rowparams in ipairs(tense_rows) do
		table.insert(rows, make_row(rowparams, show, conjinfo))
	end

	local footer = '|}</div></div>'

	local table_markup = header .. numbers_row .. genders_row
		.. table.concat(rows) .. footer
	return table_markup
end

-- Generic patterns
local patterns = {}
patterns["generic-impf"] = function(pargs)
	local conjinfo = {
		inf = pargs[1];
		pres1s = pargs[2];
		pres1p = pargs[3] .. "my";
		pres2s = pargs[3] .. "sz";
		pres2p = pargs[3] .. "cie";
		pres3s = pargs[3];
		pres3p = pargs[4];
		presimpers = pargs[3] .. " się";
		past1m = pargs[5] .. "łem";
		past1f = pargs[6] .. "łam";
		past1p = pargs[7] .. "liśmy";
		past1o = pargs[6] .. "łyśmy";
		past2m = pargs[5] .. "łeś";
		past2f = pargs[6] .. "łaś";
		past2p = pargs[7] .. "liście";
		past2o = pargs[6] .. "łyście";
		past3m = pargs[5] .. "ł";
		past3f = pargs[6] .. "ła";
		past3n = pargs[6] .. "ło";
		past3p = pargs[7] .. "li";
		past3o = pargs[6] .. "ły";
		imp1p = pargs[8] .. "my";
		imp2s = pargs[8];
		imp2p = pargs[8] .. "cie";
		imp3s = "niech " .. pargs[3];
		imp3p = "niech " .. pargs[4];
		cadv = pargs[6] .. "ąc";
		aadjm = pargs[6] .. "ący";
		aadjf = pargs[6] .. "ąca";
		aadjn = pargs[6] .. "ące";
		aadjp = pargs[6] .. "ący";
		aadjo = pargs[6] .. "ące";
	}

	if pargs.pp then
		local decl = m_adj.autoinflect(pargs.pp)
		local t = {}
		t.nomm = decl[1]; t.nomf = decl[2]; t.nomn = decl[3]; t.nomp = decl[4]; t.nomo = decl[5];
		t.genm = decl[6]; t.genf = decl[7]; t.genn = decl[6]; t.genp = decl[8]; t.geno = decl[8];
		t.datm = decl[9]; t.datf = decl[7]; t.datn = decl[9]; t.datp = decl[10]; t.dato = decl[10];
		                  t.accf = decl[11]; t.accn = decl[3]; t.accp = decl[8]; t.acco = decl[5];
		t.insm = decl[12]; t.insf = decl[11]; t.insn = decl[12]; t.insp = decl[13]; t.inso = decl[13];
		t.locm = decl[12]; t.locf = decl[7]; t.locn = decl[12]; t.locp = decl[8]; t.loco = decl[8];
		t.accm = decl[6] .. "/" .. decl[1];
		for k, v in pairs(t) do
			conjinfo["padj" .. k] = v
		end
	end

	local vn = pargs.vn or pargs[3] .. "nie"
	local vndecl = m_noun.autoinflect("n", {}, vn)
	for i, case in ipairs(cases) do
		local key = case.key .. "s"
		conjinfo["vn" .. key] = vndecl[key]
	end
	
	if pargs.ip then
		pastimpers = pargs.ip
	end

	-- future tense and conditional
	local fut_byc = {
		["1"] = { s = "będę"; p = "będziemy"; };
		["2"] = { s = "będziesz"; p = "będziecie"; };
		["3"] = { s = "będzie"; p = "będą"; };
	}
	local cond_suffix = {
		["1"] = { s = "bym"; p = "byśmy"; };
		["2"] = { s = "byś"; p = "byście"; };
		["3"] = { s = "by"; p = "by"; };
	}
	for _, pers in ipairs(persons) do
		for _, gender in ipairs(genders) do
			if gender.key ~= "n" or pers.key == "3" then
				local fut_key = "fut" .. pers.key .. gender.key
				local cond_key = "cond" .. pers.key .. gender.key
				local past_key = "past3" .. gender.key
				conjinfo[fut_key] = fut_byc[pers.key][gender.number] .. " " .. conjinfo[past_key]
				conjinfo[cond_key] = conjinfo[past_key] .. cond_suffix[pers.key][gender.number]
			end
		end
	end
	return conjinfo
end

patterns["generic-pf"] = function(pargs)
	local conjinfo = {
		inf = pargs[1];
		sfut1s = pargs[2];
		sfut1p = pargs[3] .. "my";
		sfut2s = pargs[3] .. "sz";
		sfut2p = pargs[3] .. "cie";
		sfut3s = pargs[3];
		sfut3p = pargs[4];
		sfutimpers = pargs[3] .. " się";
		past1m = pargs[5] .. "łem";
		past1f = pargs[6] .. "łam";
		past1p = pargs[7] .. "liśmy";
		past1o = pargs[6] .. "łyśmy";
		past2m = pargs[5] .. "łeś";
		past2f = pargs[6] .. "łaś";
		past2p = pargs[7] .. "liście";
		past2o = pargs[6] .. "łyście";
		past3m = pargs[5] .. "ł";
		past3f = pargs[6] .. "ła";
		past3n = pargs[6] .. "ło";
		past3p = pargs[7] .. "li";
		past3o = pargs[6] .. "ły";
		imp1p = pargs[8] .. "my";
		imp2s = pargs[8];
		imp2p = pargs[8] .. "cie";
		imp3s = "niech " .. pargs[3];
		imp3p = "niech " .. pargs[4];
	}

	if pargs.pp then
		local decl = m_adj.autoinflect(pargs.pp)
		local t = {}
		t.nomm = decl[1]; t.nomf = decl[2]; t.nomn = decl[3]; t.nomp = decl[4]; t.nomo = decl[5];
		t.genm = decl[6]; t.genf = decl[7]; t.genn = decl[6]; t.genp = decl[8]; t.geno = decl[8];
		t.datm = decl[9]; t.datf = decl[7]; t.datn = decl[9]; t.datp = decl[10]; t.dato = decl[10];
		                  t.accf = decl[11]; t.accn = decl[3]; t.accp = decl[8]; t.acco = decl[5];
		t.insm = decl[12]; t.insf = decl[11]; t.insn = decl[12]; t.insp = decl[13]; t.inso = decl[13];
		t.locm = decl[12]; t.locf = decl[7]; t.locn = decl[12]; t.locp = decl[8]; t.loco = decl[8];
		t.accm = decl[6] .. "/" .. decl[1];
		for k, v in pairs(t) do
			conjinfo["padj" .. k] = v
		end
	end

	local vn = pargs.vn or pargs[3] .. "nie"
	local vndecl = m_noun.autoinflect("n", {}, vn)
	for i, case in ipairs(cases) do
		local key = case.key .. "s"
		conjinfo["vn" .. key] = vndecl[key]
	end

	-- conditional
	local cond_suffix = {
		["1"] = { s = "bym"; p = "byśmy"; };
		["2"] = { s = "byś"; p = "byście"; };
		["3"] = { s = "by"; p = "by"; };
	}
	for _, pers in ipairs(persons) do
		for _, gender in ipairs(genders) do
			if gender.key ~= "n" or pers.key == "3" then
				local cond_key = "cond" .. pers.key .. gender.key
				local past_key = "past3" .. gender.key
				conjinfo[cond_key] = conjinfo[past_key] .. cond_suffix[pers.key][gender.number]
			end
		end
	end
	return conjinfo
end

-- Regular patterns
patterns["I"] = function(pargs)
	if not pargs.a then
		error("aspect not specified")
	end
	local gargs = {
		pargs[1] .. "ć",
		pargs[1] .. "m",
		pargs[1],
		pargs[1] .. "ją",
		pargs[1],
		pargs[1],
		pargs[1],
		pargs[1] .. "j"
	}
	gargs.vn = pargs[1] .. "nie"
	gargs.pp = pargs[1] .. "ny"
	gargs.ap = pargs[1] .. "wszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	conjinfo.pastimpers = pargs[1] .. "no"
	conjinfo.aadv = pargs[1] .. "wszy"
	return conjinfo
end

patterns["II"] = function(pargs)
	if not pargs.a then
		error("aspect not specified")
	end
	local gargs = {
		pargs[1] .. "eć",
		pargs[1] .. "em",
		pargs[1] .. "e",
		pargs[1] .. "eją",
		pargs[1] .. "a",
		pargs[1] .. "a",
		pargs[1] .. "e",
		pargs[1] .. "ej"
	}
	gargs.vn = pargs[1] .. "enie"
	gargs.pp = pargs[1] .. "any"
	gargs.ap = pargs[1] .. "awszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	conjinfo.pastimpers = pargs[1] .. "ano"
	conjinfo.aadv = pargs[1] .. "awszy"
	return conjinfo
end

patterns["III"] = function(pargs)
	if not pargs.a then
		error("aspect not specified")
	end
	local gargs = {
		pargs[1] .. "eć",
		pargs[1] .. "eję",
		pargs[1] .. "eje",
		pargs[1] .. "eją",
		pargs[1] .. "a",
		pargs[1] .. "a",
		pargs[1] .. "e",
		pargs[1] .. "ej"
	}
	gargs.vn = pargs[1] .. "enie"
	gargs.pp = pargs[1] .. "ały"
	gargs.ap = pargs[1] .. "awszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	conjinfo.pastimpers = pargs[1] .. "ano"
	conjinfo.aadv = pargs[1] .. "awszy"
	return conjinfo
end

patterns["IV"] = function(pargs)
	if not pargs.a then
		error("aspect not specified")
	end
	local gargs = {
		pargs[1] .. "ować",
		pargs[1] .. "uję",
		pargs[1] .. "uje",
		pargs[1] .. "ują",
		pargs[1] .. "owa",
		pargs[1] .. "owa",
		pargs[1] .. "owa",
		pargs[1] .. "uj"
	}
	gargs.vn = pargs[1] .. "owanie"
	gargs.pp = pargs[1] .. "owany"
	gargs.ap = pargs[1] .. "owawszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	conjinfo.pastimpers = pargs[1] .. "owano"
	conjinfo.aadv = pargs[1] .. "owawszy"
	return conjinfo
end

patterns["V"] = function(pargs)
	if not pargs.a then
		error("aspect not specified")
	end
	
	local pastfinalII = {}
	
	if pargs[2] == "ną" then
		pastfinalII = "nę"
	elseif pargs[2] == "" then
		pastfinalII = nil
	end	
	
	local gargs = {
		pargs[1] .. "nąć",
		pargs[1] .. "nę",
		pargs[1] .. "nie",
		pargs[1] .. "ną",
		pargs[1] .. pargs[2],
		pargs[1] .. pastfinalII,
		pargs[1] .. pastfinalII,
		pargs[1] .. pargs[3]
	}
	gargs.vn = pargs[1] .. "nięcie"
	gargs.pp = pargs[1] .. "nięty"
	gargs.ap = pargs[1] .. "ąwszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	conjinfo.pastimpers = pargs[1] .. "nięto"
	conjinfo.aadv = pargs[1] .. "ąwszy"
	return conjinfo
end

patterns["VI"] = function(pargs)
	if not pargs.a then
		error("aspect not specified")
	end
	
	local stemfinal = {}
	local impfinal = {}
	
	if pargs[3] == "i" then
		if pargs[2] == "" then
			stemfinal = "j"
			impfinal = "j"
		elseif pargs[2] == "b" or pargs[2] == "p" then
			stemfinal = pargs[2] .. "i"
			impfinal = pargs[2]
		elseif pargs[2] == "c" then
			stemfinal = pargs[2]
			impfinal = "ć"
		elseif pargs[2] == "dz" then
			stemfinal = pargs[2]
			impfinal = "dź"
		elseif pargs[2] == "n" then
			stemfinal = pargs[2]
			impfinal = "ń"
		elseif pargs[2] == "s" then
			stemfinal = "sz"
			impfinal = "ś"
		elseif pargs[2] == "śc" then
			stemfinal = "szcz"
			impfinal = "ść"
		elseif pargs[2] == "z" then
			stemfinal = "ż"
			impfinal = "ź"
		elseif pargs[2] == "źdz" then
			stemfinal = "żdż"
			impfinal = "źdź"
		else
			stemfinal = pargs[2]
			impfinal = stemfinal
		end
	else
		stemfinal = pargs[2]
		impfinal = stemfinal
	end
	
	local gargs = {
		pargs[1] .. pargs[2] .. pargs[3] .. "ć",
		pargs[1] .. stemfinal .. "ę",
		pargs[1] .. pargs[2] .. pargs[3],
		pargs[1] .. stemfinal .. "ą",
		pargs[1] .. pargs[2] .. pargs[3],
		pargs[1] .. pargs[2] .. pargs[3],
		pargs[1] .. pargs[2] .. pargs[3],
		pargs[1] .. impfinal
	}
	gargs.vn = pargs[1] .. stemfinal .. "enie"
	gargs.pp = pargs[1] .. stemfinal .. "ony"
	gargs.ap = pargs[1] .. pargs[2] .. pargs[3] .. "wszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	conjinfo.pastimpers = pargs[1] .. stemfinal .. "ono"
	conjinfo.aadv = pargs[1] .. pargs[2] .. pargs[3] .. "wszy"
	return conjinfo
end

patterns["VII"] = function(pargs)
	if not pargs.a then
		error("aspect not specified")
	end
	
	local stemfinal = {}
	local impfinal = {}
	local finalvow = {}
	
	if pargs[3] == "i" then
		if pargs[2] == "b" or pargs[2] == "p" then
			stemfinal = pargs[2] .. "i"
			impfinal = pargs[2]
		elseif pargs[2] == "c" then
			stemfinal = pargs[2]
			impfinal = "ć"
		elseif pargs[2] == "dz" then
			stemfinal = pargs[2]
			impfinal = "dź"
		elseif pargs[2] == "n" then
			stemfinal = pargs[2]
			impfinal = "ń"
		elseif pargs[2] == "s" then
			stemfinal = "sz"
			impfinal = "ś"
		elseif pargs[2] == "śc" then
			stemfinal = "szcz"
			impfinal = "ść"
		elseif pargs[2] == "z" then
			stemfinal = "ż"
			impfinal = "ź"
		elseif pargs[2] == "źdz" then
			stemfinal = "żdż"
			impfinal = "źdź"
		else
			stemfinal = pargs[2]
			impfinal = stemfinal
		end
	else
		stemfinal = pargs[2]
		impfinal = stemfinal
	end
	
	if pargs[3] == "y" then
		finalvow = nil
	else
		finalvow = pargs[3]
	end
	
	local gargs = {
		pargs[1] .. pargs[2] .. finalvow .. "eć",
		pargs[1] .. stemfinal .. "ę",
		pargs[1] .. pargs[2] .. pargs[3],
		pargs[1] .. stemfinal .. "ą",
		pargs[1] .. pargs[2] .. finalvow .. "a",
		pargs[1] .. pargs[2] .. finalvow .. "a",
		pargs[1] .. pargs[2] .. finalvow .. "e",
		pargs[1] .. impfinal
	}
	gargs.vn = pargs[1] .. stemfinal .. "enie"
	gargs.pp = pargs[1] .. pargs[2] .. finalvow .. "any"
	gargs.ap = pargs[1] .. pargs[2] .. finalvow .. "awszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	conjinfo.pastimpers = pargs[1] .. pargs[2] .. finalvow .. "ano"
	conjinfo.aadv = pargs[1] .. pargs[2] .. finalvow .. "awszy"
	return conjinfo
end

patterns["VIII"] = function(pargs)
	if not pargs.a then
		error("aspect not specified")
	end
	local gargs = {
		pargs[1] .. pargs[2] .. "wać",
		pargs[1] .. "uję",
		pargs[1] .. "uje",
		pargs[1] .. "ują",
		pargs[1] .. pargs[2] .. "wa",
		pargs[1] .. pargs[2] .. "wa",
		pargs[1] .. pargs[2] .. "wa",
		pargs[1] .. "uj"
	}
	gargs.vn = pargs[1] .. pargs[2] .. "wanie"
	gargs.pp = pargs[1] .. pargs[2] .. "wany"
	gargs.ap = pargs[1] .. pargs[2] .. "wawszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	conjinfo.pastimpers = pargs[1] .. pargs[2] .. "wano"
	conjinfo.aadv = pargs[1] .. pargs[2] .. "wawszy"
	return conjinfo
end

patterns["IX"] = function(pargs)
	if not pargs.a then
		error("aspect not specified")
	end
	
	local impfinal = {}
	
	if pargs[4] then
		impfinal = pargs[4]
	else
		impfinal = pargs[3]
	end
	
	local gargs = {
		pargs[1] .. pargs[2] .. "ać",
		pargs[1] .. pargs[3] .. "ę",
		pargs[1] .. pargs[3] .. "e",
		pargs[1] .. pargs[3] .. "ą",
		pargs[1] .. pargs[2] .. "a",
		pargs[1] .. pargs[2] .. "a",
		pargs[1] .. pargs[2] .. "a",
		pargs[1] .. impfinal
	}
	gargs.vn = pargs[1] .. pargs[2] .. "anie"
	gargs.pp = pargs[1] .. pargs[2] .. "any"
	gargs.ap = pargs[1] .. pargs[2] .. "awszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	conjinfo.pastimpers = pargs[1] .. pargs[2] .. "ano"
	conjinfo.aadv = pargs[1] .. pargs[2] .. "awszy"
	return conjinfo
end

patterns["X"] = function(pargs)
	if not pargs.a then
		error("aspect not specified")
	end
	
	local stemvowII = {}
	
	if pargs[2] == "a" then
		stemvowII = "e"
	else
		stemvowII = pargs [2]
	end
	
	local gargs = {
		pargs[1] .. pargs[2] .. "ć",
		pargs[1] .. stemvowII .. "ję",
		pargs[1] .. stemvowII .. "je",
		pargs[1] .. stemvowII .. "ją",
		pargs[1] .. pargs[2],
		pargs[1] .. pargs[2],
		pargs[1] .. pargs[2],
		pargs[1] .. stemvowII .. "j"
	}
	
	if pargs[2] == "a" then
		gargs.vn = pargs[1] .. "anie"
		gargs.pp = pargs[1] .. "any"
	else
		gargs.vn = pargs[1] .. pargs[2] .. "cie"
		gargs.pp = pargs[1] .. pargs[2] .. "ty"
	end
	
	gargs.ap = pargs[1] .. pargs[2] .. "wszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	
	if pargs[2] == "a" then
		conjinfo.pastimpers = pargs[1] .. "ano"
	else
		conjinfo.pastimpers = pargs[1] .. pargs[2] .. "to"
	end
	
	conjinfo.aadv = pargs[1] .. pargs[2] .. "wszy"
	return conjinfo
end

-- ‘iść’ verbs
patterns["iść"] = function(pargs)
	if pargs[1] == "i" then
		pargs.a = "impf"
	else
		pargs.a = "pf"
	end
	
	if pargs[2] == "" then
		pargs[2] = nil
	end
	
	local gargs = {
		pargs[1] .. "ść",
		pargs[1] .. "dę",
		pargs[1] .. "dzie",
		pargs[1] .. "dą",
		pargs[2] .. "szed",
		pargs[2] .. "sz",
		pargs[2] .. "sz",
		pargs[1] .. "dź"
	}
	if pargs[1] == "i" then
		gargs.vn = nil
	else
		gargs.vn = pargs[1] .. "ście"
	end
	gargs.pp = nil
	gargs.ap = pargs[2] .. "szedłszy"

	local conjinfo = patterns["generic-" .. pargs.a](gargs)
	conjinfo.pastimpers = nil
	conjinfo.aadv = pargs[2] .. "szedłszy"
	return conjinfo
end

function export.template_conj(frame)
	local pargs = frame:getParent().args
	if not pargs["a"] then
		error("undefined aspect")
	end

	local aspect = "impf"
	if pargs.a == "p" or pargs.a == "pf" then
		aspect = "pf"
	end
	local conjinfo = {}
	local hide = {}
	local pattern = pargs.pattern or "generic"
	if aspect == "impf" then
		hide.aadv = 1
		hide.sfut = 1
	else
		hide.pres = 1
		hide.fut = 1
		hide.aadj = 1
		hide.cadv = 1
	end
	conjinfo = patterns[pattern .. "-" .. aspect](pargs)
	return export.make_table_markup(conjinfo, hide)
end

function export.test_table()
	local conjinfo = {
		inf = "robić";
		pres1s = "robię";
		pres1p = "robimy";
		pres2s = "robisz";
		pres2p = "robicie";
		pres3s = "robi";
		pres3p = "robią";
		presimpers = "robi się";
		past1m = "robiłem";
		past1f = "robiłam";
		past1p = "robiliśmy";
		past1o = "robiłyśmy";
		past2m = "robiłeś";
		past2f = "robiłaś";
		past2p = "robiliście";
		past2o = "robiłyście";
		past3m = "robił";
		past3f = "robiła";
		past3n = "robiło";
		past3p = "robili";
		past3o = "robiły";
		pastimpers = "robiono";
		fut1m = "będę robił";
		fut1f = "będę robiła";
		fut1p = "będą robili";
		fut1o = "będą robiły";
		fut2m = "będziesz robił";
		fut2f = "będziesz robiła";
		fut2p = "będziecie robili";
		fut2o = "będziecie robiły";
		fut3m = "będzie robił";
		fut3f = "będzie robiła";
		fut3n = "będzie robiło";
		fut3p = "będą robili";
		fut3o = "będą robiły";
		futimpers = "będzie robione";
		cond1m = "robiłbym";
		cond1f = "robiłabym";
		cond1p = "robilibyśmy";
		cond1o = "robiłybyśmy";
		cond2m = "robiłbyś";
		cond2f = "robiłabyś";
		cond2p = "robilibyście";
		cond2o = "robiłybyście";
		cond3m = "robiłby";
		cond3f = "robiłaby";
		cond3n = "robiłoby";
		cond3p = "robiliby";
		cond3o = "robiłyby";
		condimpers = "robiono by";
		--imp1s = "niech robię";
		imp1p = "róbmy";
		imp2s = "rób";
		imp2p = "róbcie";
		imp3s = "niech robi";
		imp3p = "niech robią";
		aadjm = "robiący";
		aadjf = "robiąca";
		aadjn = "robiące";
		aadjp = "robiący";
		aadjo = "robiące";
		padjm = "robiony";
		padjf = "robiona";
		padjn = "robione";
		padjp = "robieni";
		padjo = "robione";
		cadv = "robiąc";
		aadv = "robiwszy";
		vn = "robienie";
	}
	
	return export.make_table_markup(conjinfo, {pres=1})
end

return export