Die Dokumentation für dieses Modul kann unter Modul:Tschechisch/Doku erstellt werden

local p = {}

local FormenSubstantiv = { "Nominativ Singular", "Nominativ Plural", "Genitiv Singular", "Genitiv Plural", "Dativ Singular", "Dativ Plural", "Akkusativ Singular", "Akkusativ Plural", "Vokativ Singular", "Vokativ Plural", "Lokativ Singular", "Lokativ Plural", "Instrumental Singular", "Instrumental Plural" }
local FormenSubstantivSingular = { "Nominativ Singular", "Genitiv Singular", "Dativ Singular", "Akkusativ Singular", "Vokativ Singular", "Lokativ Singular", "Instrumental Singular" }
local FormenSubstantivPlural = { "Nominativ Plural", "Genitiv Plural", "Dativ Plural", "Akkusativ Plural", "Vokativ Plural", "Lokativ Plural", "Instrumental Plural"}
local FormenVerb = { "imperfektiv", "perfektiv", "1. Person Singular", "2. Person Singular", "3. Person Singular", "1. Person Plural", "2. Person Plural", "3. Person Plural", "Präteritum", "Partizip Passiv", "Imperativ Singular", "Verbaladjektiv", "Verbalsubstantiv", "iterativ", "nicht iterativ",
	"Partizip Perfekt", "Präteritum Femininum" --diese letzten beiden nur vorübergehend

}
local Anmerkung = {}
Anmerkung["imperfektiv"] = "<dl><dd>Dieses [[imperfektiv]]e, unvollendete Verb wird dort verwendet, wo die Handlung noch nicht abgeschlossen ist, sich wiederholt oder gewöhnlich stattfindet. Siehe auch [[Verzeichnis:Tschechisch/Grammatik/Aspekt|Aspekt tschechischer Verben]].</dd></dl>"
Anmerkung["perfektiv"] = "<dl><dd>Dieses [[perfektiv]]e, vollendete Verb wird dort verwendet, wo die Handlung abgeschlossen ist und nur einmalig stattfindet. Siehe auch [[Verzeichnis:Tschechisch/Grammatik/Aspekt|Aspekt tschechischer Verben]].</dd></dl>"
Anmerkung["iterativ"] = "iteratives Verb zu "
Anmerkung["nicht iterativ"] = "nicht iteratives Verb zu "

local AnmerkungSieheAuch = "siehe auch: " 


local empty = "<div style=\"text-align: center\">—</div>"

--global
local pageName, wortart, aspekt
local reflexiv = false
local Categories = {}
local flexion

function alphanumsort(Table)
  local function padnum(d) local dec, n = mw.ustring.match(d, "(%.?)0*(.+)")
    return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n) end
  table.sort(Table, function(a,b)
    return tostring(a):gsub("%.?%d+",padnum)..("%3d"):format(#b)
         < tostring(b):gsub("%.?%d+",padnum)..("%3d"):format(#a) end)
  return Table
end

function split(s, delimiter)
    result = {};
    for match in (s..delimiter):gmatch("(.-)"..delimiter) do
        table.insert(result, trim(match));
    end
    return result
end

function trim(str)
  return (mw.ustring.gsub(str, "^%s*(.-)%s*$", "%1"))
end

function IsInList (List, value)
	for _, val in pairs (List) do
		if val == value then
			return true
		end
	end
	return false
end

function SplitFormen (str)
	if not str or str == "" then
		return str
	elseif mw.ustring.find(str, ",") then
		return split (str, ",")
	else
		return str
	end	
end	

function FillFormen ()
	local Forms
	if wortart == "Substantiv" then
		Forms = FormenSubstantiv
	elseif wortart == "Verb" then
		Forms = FormenVerb
	end	
	
	local Formen = {}
	for _, form in pairs (Forms) do
		if arg[form] and arg[form] ~= "" and arg[form] ~= "-" and arg[form] ~= "—" and arg[form] ~= "—" then
			Formen[form] = SplitFormen(arg[form])
		else
			if wortart == "Verb" then
				if not arg[form] or (arg[form] and arg[form] == "") then
					Formen[form] = ""
				elseif arg[form] then
					Formen[form] = empty
				end	
			end	
		end	
	end
	--Sternchenparameter
	for _, form in pairs (Forms) do
		if arg[form .. "*"] and arg[form.. "*"] ~= "" then
			Formen[form .. "*"] = SplitFormen (arg[form .. "*"])
		end
	end

	if wortart == "Substantiv" then
		if arg["Nominativ Plural"] and arg["Nominativ Plural"] ~= "" then
			Formen["Vokativ Plural"] = arg["Nominativ Plural"]
		end	
		
		if arg["kein Singular"] and arg["kein Singular"] == "ja" then
			for _, form in pairs (FormenSubstantivSingular) do
				Formen[form] = empty
			end
			table.insert (Categories, "Pluraletantum (Tschechisch)")
		end
		if arg["kein Plural"] and arg["kein Plural"] == "ja" then
			for _, form in pairs (FormenSubstantivPlural) do
				Formen[form] = empty
			end
			table.insert (Categories, "Singularetantum (Tschechisch)")
		end		
	elseif wortart == "Verb" then		
		if Formen["Präteritum"] == "" and Formen["Partizip Perfekt"] ~= "" then
			Formen["Präteritum"] = Formen["Partizip Perfekt"]
		end	
			
		if not reflexiv then
			if Formen["Verbaladjektiv"] == "" then
				if not Formen["3. Person Plural"] ~= empty then
					if type(Formen["3. Person Plural"]) == "string" then
						Formen["Verbaladjektiv"] = Formen["3. Person Plural"] .. "cí"
					elseif type(Formen["3. Person Plural"]) == "table" then
						Formen["Verbaladjektiv"] = Formen["3. Person Plural"][1] .. "cí"
					end	
				else
					Formen["Verbaladjektiv"] = false
				end
			end
			if Formen["Verbalsubstantiv"] == "" then
				if Formen["Partizip Passiv"] ~= empty then
					Formen["Verbalsubstantiv"] = Formen["Partizip Passiv"] .. "í"
				else
					Formen["Verbalsubstantiv"] = false
				end	
			end	
		else
			if Formen["Verbaladjektiv"] == "" then
				if Formen["3. Person Plural"] ~= "" then
					local adjroot = mw.ustring.gsub(Formen["3. Person Plural"], " " .. reflexiv .. "$", "")
					Formen["Verbaladjektiv"] = adjroot .. "cí " .. reflexiv
				else
					Formen["Verbaladjektiv"] = false
				end	
			else
				Formen["Verbaladjektiv"] = false
			end			
			if Formen["Verbalsubstantiv"] == "" then
				Formen["Verbalsubstantiv"] = false
			end	
		end	
		if not arg["imperfektiv"] or arg["imperfektiv"] == "" or arg["imperfektiv"] == "-" then
			Formen["imperfektiv"] = empty
		end	
		if not arg["perfektiv"] or arg["perfektiv"] == "" or arg["perfektiv"] == "-" then
			Formen["perfektiv"] = empty
		end		
		
	end	
	

	
	

	return Formen
end

function PrintCategories ()
	local out = ""
	if not arg["Test"] or arg["Test"] ~= "ja" then
		for _, cat in pairs (Categories) do
			out = out .. "[[Category:" .. cat .. "]]"
		end
		return out
	else	
		for n, cat in pairs (Categories) do
			out = out .. "Kategorie:" .. cat .. ""
			if n ~= #Categories then
				out = out .. ", "
			end	
		end

		return "<code>" .. out .. "</code>"
	end	
	return out
end

function PrintForm (form, short)
	local rare = false
	if wortart == "Substantiv" then
		if arg["Singular selten"] and arg["Singular selten"] == "ja" and IsInList (FormenSubstantivSingular, form) then
			rare = true
		end
		if arg["Plural selten"] and arg["Plural selten"] == "ja" and IsInList (FormenSubstantivPlural, form) then
			rare = true
		end
	elseif wortart == "Verb" then
		if aspekt == "perfektiv" and form == "Verbaladjektiv" then
			rare = true
		end	
	end
	
	if not Formen [form .. "*"] and type(Formen[form]) == "string" then
		return PrintLink (Formen[form], rare)
	else
		local out = ""
		if type (Formen[form]) == "string" then
			out = PrintLink (Formen[form], rare)
		elseif type (Formen[form]) == "table" then
			for num, f in pairs (Formen [form]) do
				if not short then
					if num ~= 1 then
						out = out .. "<br />"
					end
					out = out .. PrintLink (f, rare)
				else
					if num ~= 1 then
						out = out .. ",&nbsp;" 
					end	
					out = out .. PrintLink (f, rare)
				end	
			end
		end	
		if type (Formen [form .. "*"]) == "table" then
			for num, f in pairs (Formen [form .. "*"]) do
				if not short then
					out = out .. "<br />" .. PrintLink (f, rare)
				else
					out = out .. ",&nbsp;" .. PrintLink (f, rare)
				end	
			end
		elseif type (Formen [form .. "*"]) == "string" then
			if not short then
				out = out .. "<br />" .. PrintLink (Formen [form .. "*"], rare)
			else
				out = out .. ",&nbsp;" .. PrintLink (Formen [form .. "*"], rare)
			end	
			
		end	
		return out
	end	
end
function PrintLink (link, rare)
	local link = link
	local out = ""
	if link == empty or link == "" then
		return link
	elseif link then
		if link ~= pageName then
			out = "[[" .. link .. "#" .. link .. " (Tschechisch)|" .. link .. "]]"
		else
			out = link
		end
	else
		return ""
	end
	if rare then
		return "(" .. out .. ")"
	else
		return out
	end
end


function PrintSubstantiv (Formen)
	local out = ""
	if keine_positionierung then
		out = "<table class=\"wikitable inflection-table float-right hintergrundfarbe2\" style=\"margin:0 0 .5em .4em;\">"
	else
		out = "<table class=\"wikitable inflection-table hintergrundfarbe2\" style=\"margin:.5em .5em .5em .4em;\">"
	end
	
	out = out .. "<tr>"
	out = out .. "<th></th>"
	out = out .. "<th style=\"text-align: left;\">[[Hilfe:Singular|Singular]]</th>"
	out = out .. "<th>[[Hilfe:Plural|Plural]]</th>"
	out = out .. "</tr>"
	
	out = out .. "<tr>"
	out = out .. "<th style=\"text-align: left;\">[[Hilfe:Nominativ|Nominativ]]</th>"
	out = out .. "<td>" .. PrintForm ("Nominativ Singular") .. "</td>"
	out = out .. "<td>" .. PrintForm ("Nominativ Plural") .. "</td>"
	out = out .. "</tr>"

	out = out .. "<tr>"
	out = out .. "<th style=\"text-align: left;\">[[Hilfe:Genitiv|Genitiv]]</th>"
	out = out .. "<td>" .. PrintForm ("Genitiv Singular") .. "</td>"
	out = out .. "<td>" .. PrintForm ("Genitiv Plural") .. "</td>"
	out = out .. "</tr>"
	
	out = out .. "<tr>"
	out = out .. "<th style=\"text-align: left;\">[[Hilfe:Dativ|Dativ]]</th>"
	out = out .. "<td>" .. PrintForm ("Dativ Singular") .. "</td>"
	out = out .. "<td>" .. PrintForm ("Dativ Plural") .. "</td>"
	out = out .. "</tr>"

	out = out .. "<tr>"
	out = out .. "<th style=\"text-align: left;\">[[Hilfe:Akkusativ|Akkusativ]]</th>"
	out = out .. "<td>" .. PrintForm ("Akkusativ Singular") .. "</td>"
	out = out .. "<td>" .. PrintForm ("Akkusativ Plural") .. "</td>"
	out = out .. "</tr>"
	
	out = out .. "<tr>"
	out = out .. "<th style=\"text-align: left;\">[[Hilfe:Vokativ|Vokativ]]</th>"
	out = out .. "<td>" .. PrintForm ("Vokativ Singular") .. "</td>"
	out = out .. "<td>" .. PrintForm ("Vokativ Plural") .. "</td>"
	out = out .. "</tr>"
	
	out = out .. "<tr>"
	out = out .. "<th style=\"text-align: left;\">[[Hilfe:Lokativ|Lokativ]]</th>"
	out = out .. "<td>" .. PrintForm ("Lokativ Singular") .. "</td>"
	out = out .. "<td>" .. PrintForm ("Lokativ Plural") .. "</td>"
	out = out .. "</tr>"
	
	out = out .. "<tr>"
	out = out .. "<th style=\"text-align: left;\">[[Hilfe:Instrumental|Instrumental]]</th>"
	out = out .. "<td>" .. PrintForm ("Instrumental Singular") .. "</td>"
	out = out .. "<td>" .. PrintForm ("Instrumental Plural") .. "</td>"
	out = out .. "</tr>"
	out = out .. "</table>"
	out = out .. PrintImages ()
	return out
end

function PrintVerb (Formen)
	local praesens_oder_futur
	if aspekt == "imperfektiv" then
		praesens_oder_futur = "[[Hilfe:Präsens|Präsens]]"
	else
		praesens_oder_futur = "[[Hilfe:Futur|Futur]]"
	end	
	
	local out = "<table class=\"wikitable inflection-table float-right hintergrundfarbe2\" style=\"margin:0 0 .5em .4em\">"
	out = out .. "<tr>"
	out = out .. "<td colspan=\"3\" style=\"background: #ccccff; width: 300px; text-align: center\"><b>[[Aspekt]]</b>"
	out = out .. "</td></tr>"
	out = out .. "<tr>"
	out = out .. "<th style=\"width: 130px\"> [[imperfektiv]]es Verb"
	out = out .. "</th>"
	out = out .. "<th colspan=\"2\"> [[perfektiv]]es Verb"
	out = out .. "</th></tr>"
	out = out .. "<tr style=\"text-align: center\">"
	out = out .. "<td>" .. PrintForm ("imperfektiv", true) .. "</td>"
	out = out .. "<td colspan=\"2\">" .. PrintForm ("perfektiv", true) .. "</td>"
	out = out .. "</tr>"
	out = out .. "<tr>"
	out = out .. "<td colspan=\"3\">"
	out = out .. "</td></tr>"
	out = out .. "<tr>"
	out = out .. "<th style=\"background: #ccccff\">[[Hilfe:Tempus|Zeitform]]"
	out = out .. "</th>"
	out = out .. "<th style=\"background: #ccccff\" colspan=\"2\">Wortform"
	out = out .. "</th></tr>"
	out = out .. "<tr>"
	out = out .. "<td style=\"background: #f4f4f4\" rowspan=\"6\"><b>" .. praesens_oder_futur .. "</b>"
	out = out .. "</td>"
	out = out .. "<td>1. Person Sg.</td>"
	out = out .. "<td>" .. PrintForm("1. Person Singular") .. "</td>"
	out = out .. "</tr>"
	out = out .. "<tr>"
	out = out .. "<td>2. Person Sg.</td>"
	out = out .. "<td>" .. PrintForm("2. Person Singular") .. "</td></tr>"
	out = out .. "<tr>"
	out = out .. "<td>3. Person Sg.</td>"
	out = out .. "<td>" .. PrintForm("3. Person Singular") .. "</td></tr>"
	out = out .. "<tr>"
	out = out .. "<td>1. Person Pl.</td>"
	out = out .. "<td>" .. PrintForm("1. Person Plural") .. "</td></tr>"
	out = out .. "<tr>"
	out = out .. "<td>2. Person Pl.</td>"
	out = out .. "<td>" .. PrintForm("2. Person Plural") .. "</td></tr>"
	out = out .. "<tr>"
	out = out .. "<td>3. Person Pl.</td>"
	out = out .. "<td>" .. PrintForm("3. Person Plural") .. "</td></tr>"
	out = out .. "<tr>"
	out = out .. "<td style=\"background: #f4f4f4\"><b>[[Hilfe:Präteritum|Präteritum]]</b>"
	out = out .. "</td>"
	out = out .. "<td>m.</td>"
	out = out .. "<td>" .. PrintForm("Präteritum") .. "</td></tr>"
	out = out .. "<tr>"
	out = out .. "<td style=\"background: #f4f4f4\"><b>[[Hilfe:Partizip|Partizip Passiv]]</b>"
	out = out .. "</td>"
	out = out .. "<td>m.</td>"
	out = out .. "<td>" .. PrintForm("Partizip Passiv") .. "</td>"
	out = out .. "</tr>"
	out = out .. "<tr>"
	out = out .. "<td style=\"background: #f4f4f4\"><b>[[Hilfe:Imperativ|Imperativ Singular]]</b>"
	out = out .. "</td>"
	out = out .. "<td></td>"
	out = out .. "<td>" .. PrintForm("Imperativ Singular") .. "</td>"
	out = out .. "</tr>"
	if Formen["Verbaladjektiv"] then
		out = out .. "<tr>"
		out = out .. "<td style=\"background: #f4f4f4\"><b>[[Hilfe:Verbaladjektiv|Verbaladjektiv]]</b>"
		out = out .. "</td>"
		out = out .. "<td>&#160;</td>"
		out = out .. "<td>" .. PrintForm("Verbaladjektiv") .. "</td>"
		out = out .. "</tr>"
	end	
	if Formen["Verbalsubstantiv"] then
		out = out .. "<tr>"
		out = out .. "<td style=\"background: #f4f4f4\"><b>[[Hilfe:Verbalsubstantiv|Verbalsubstantiv]]</b>"
		out = out .. "</td>"
		out = out .. "<td>&#160;</td>"
		out = out .. "<td>" .. PrintForm("Verbalsubstantiv") .. "</td></tr>"
	end	
	out = out .. "<tr>"
	out = out .. "<td style=\"background: #f4f4f4\" colspan=\"3\"><i>Alle weiteren Formen: [[Flexion:" .. flexion .. "|Flexion:" .. lemma .. "]]</i> "
	out = out .. "</td></tr></table>"
	out = out .. PrintImages ()
	return out
end

function PrintImages ()
	local out = ""
	local Images = {}

	for par in pairs (arg) do
		local found_image = mw.ustring.match (par, "^Bild([ ]*[0-9]*)$")
		if found_image then
			table.insert (Images, found_image)
		end
	end
	Images = alphanumsort (Images)

	if #Images > 0 then
		table.insert (Categories, "Wiktionary:Illustration")
		
		if keine_positionierung then
			out = "<table cellspacing=\"0\" cellpadding=\"0\" class=\"hintergrundfarbe2 rahmenfarbe1\" style=\"float:right; clear:right; margin:0em 0em 1em 1em; empty-cells:show;\">"
		else
			out = "<table cellspacing=\"0\" cellpadding=\"0\" class=\"hintergrundfarbe2 rahmenfarbe1\" style=\"clear:right; margin:0em 0em 1em 1em; empty-cells:show;\">"
		end
	

		for _, image in pairs (Images) do
			local image_file = arg["Bild" .. image]
			
			local image_description = ""
			if arg["Bildbezug" .. image] and arg["Bildbezug" .. image] ~= "" then
				image_description = "[" .. arg["Bildbezug" .. image] .. "]"
			end	

			if arg["Bildbeschreibung" .. image] and arg["Bildbeschreibung" .. image] ~= "" then
				image_description = image_description .. "&nbsp;" .. arg["Bildbeschreibung" .. image]
			end	

			if arg["Bildbeschreibung" .. image .. " Übersetzung"] and arg["Bildbeschreibung" .. image .. " Übersetzung"] ~= "" then
				image_description = image_description .. "<br />" ..  arg["Bildbeschreibung" .. image .. " Übersetzung"]
			end	
			
			local image_size = ""
			if arg["Bildbreite" .. image] and arg["Bildbreite" .. image] ~= "" then
				if arg["Bildbreite" .. image] == "mini" then
					image_size = "thumb"
				else	
					image_size = arg["Bildbreite" .. image]
				end	
			else
				image_size = "thumb"
			end
			
			out = out .. "<tr>"
			out = out .. "<td colspan=\"10\"><div class=\"center\">" .. "[[File:" .. image_file .. "|" .. image_size .. "|" .. image_description .. "]]" .. "</div></td>"
			out = out .. "</tr>"
		end
		out = out .. "</table>"
		if arg["Absatz"] and arg["Absatz"] == "ja" then
			out = out .. "<div style=\"clear: both;\"></div>"	
		end
	end
	
	return out	
end

function p.print (frame)
	local out = ""
	local pargs = frame:getParent().args
	arg = {}
	for name, val in pairs (pargs) do
		if trim(name) ~= "" then
			arg[trim(name)] = trim(val)
		end
	end
	local title = mw.title.getCurrentTitle()
	pageName = title.fullText
	lemma = false
	if arg["Lemma"] and arg["Lemma"] ~= "" then
		lemma = arg["Lemma"]
	else
		lemma = pageName
	end

	--global
	Formen = {}	
	wortart = frame.args["Wortart"]

	if arg["keine Positionierung"] and arg["keine Positionierung"] == "ja" then
		keine_positionierung = false
	else
		keine_positionierung = true
	end
	

	if wortart == "Substantiv" then
		
		genus = frame.args["Genus"]

	
		last_letter = mw.ustring.sub (lemma, -1, -1)
		second_to_last_letter = mw.ustring.sub (lemma, -2, -2)
		last_two_letters = mw.ustring.sub (lemma, -2, -1)
		last_three_letters = mw.ustring.sub (lemma, -3, -1)
		
		lemma_except_last_letter = mw.ustring.sub (lemma, 1, -2)
		lemma_except_last_two_letters = mw.ustring.sub (lemma, 1, -3)
	
		-- ch gilt als eine Buchstabe im Tschechischen
		-- letzter Buchstabe "ch", z. B. "zápach"
		if mw.ustring.sub (lemma, -2, -1) == "ch" then
			last_letter = "ch"
			second_to_last_letter = mw.ustring.sub (lemma, -3, -3)
			last_two_letters = mw.ustring.sub (lemma, -3, -1)	
			last_three_letters = mw.ustring.sub (lemma, -4, -1)
			lemma_except_last_letter = mw.ustring.sub (lemma, 1, -3)
			lemma_except_last_two_letters = mw.ustring.sub (lemma, 1, -4)
			
		--vorletzter Buchstabe "ch", z. B. "břicho"
		elseif mw.ustring.sub (lemma, -3, -2) == "ch" then
			second_to_last_letter = "ch"
			last_two_letters = "ch" .. mw.ustring.sub (lemma, -1, -1)	
			last_three_letters = mw.ustring.sub (lemma, -4, -1)
			lemma_except_last_two_letters = mw.ustring.sub (lemma, 1, -4)
	
		--vorvorletzter Buchstabe "ch", z. B. "východ"
		elseif mw.ustring.sub (lemma, -4, -3) == "ch" then
			last_three_letters = "ch" .. mw.ustring.sub (lemma, -2, -1)
		end		
		
		if genus == "mu" then
			local MU = require ("Module:Tschechisch/Substantiv mu")
			Formen = SubstantivMU()
		elseif genus == "mb" then
			local MB = require ("Module:Tschechisch/Substantiv mb")
			Formen = SubstantivMB()
		elseif genus == "f" then
			local F = require ("Module:Tschechisch/Substantiv f")
			Formen = SubstantivF()
		elseif genus == "n" then
			local N = require ("Module:Tschechisch/Substantiv n")
			Formen = SubstantivN()
		end	
		
		if arg["auch alte Tabelle"] and arg["auch alte Tabelle"] == "ja" then
			out = PrintNewAndOldTable (frame)
		else	
			out = PrintSubstantiv (Formen)	
		end	
	elseif wortart == "Verb" then
		aspekt = frame.args["Aspekt"]

		if mw.ustring.match (lemma, " se$") then
			reflexiv = "se"
		elseif mw.ustring.match (lemma, " si$") then
			reflexiv = "si"
		elseif mw.ustring.match (lemma, " sebou$") then
			reflexiv = "sebou"
		end
		

		Formen = FillFormen ()
	
		if arg["imperfektiv"] and arg["imperfektiv"] ~= "" and arg["imperfektiv*"] and arg["imperfektiv*"] ~= "" then
			table.insert (Categories, "Verb imperfektiv dual (Tschechisch)")
		end
		if arg["perfektiv"] and arg["perfektiv"] ~= "" and arg["perfektiv*"] and arg["perfektiv*"] ~= "" then
			table.insert (Categories, "Verb perfektiv dual (Tschechisch)")
		end		
		if arg["imperfektiv"] and arg["imperfektiv"] ~= "" and arg["perfektiv"] and arg["perfektiv"] ~= "" and arg["imperfektiv"] == arg["perfektiv"] then
			table.insert (Categories, "Verb imperfektiv+perfektiv (Tschechisch)")
			if not IsInList (Categories, "Verb imperfektiv (Tschechisch)") then
				table.insert (Categories, "Verb imperfektiv (Tschechisch)")
			end
			if not IsInList (Categories, "Verb perfektiv (Tschechisch)") then
				table.insert (Categories, "Verb perfektiv (Tschechisch)")
			end
		end			

		if Formen["Partizip Passiv"] == empty then
			table.insert (Categories, "Verb ohne Partizip Passiv (Tschechisch)")
		end		

		if Formen["Verbaladjektiv"] == "" then
			table.insert (Categories, "Wartung fehlendes Verbaladjektiv (Tschechisch)")
		end		
		
		if Formen["Verbalsubstantiv"] == "" then
			table.insert (Categories, "Wartung fehlendes Verbalsubstantiv (Tschechisch)")
		end		
		
		if arg["Weitere Konjugationen"] and arg["Weitere Konjugationen"] ~= "" then
			flexion = mw.ustring.gsub (arg["Weitere Konjugationen"], "Flexion:", "")
		else
			flexion = lemma
		end	

		local flex = mw.title.new( "Flexion:" .. flexion)
		if not flex.exists then
			table.insert (Categories, "Wartung fehlende Flexion (Tschechisch)")
		end
		
		table.insert (Categories, "Verb " .. aspekt .. " (Tschechisch)")
		if Formen["3. Person Singular"] and Formen["3. Person Singular"] ~= "" then
			local function KonjugationKategorie (form)
				if mw.ustring.sub (form, -2, -1) == "je" then
					table.insert (Categories, "Konjugationsklasse " .. aspekt .. " -je (Tschechisch)")
				elseif 	mw.ustring.sub (form, -2, -1) == "ne" then
					table.insert (Categories, "Konjugationsklasse " .. aspekt .. " -ne (Tschechisch)")
				elseif mw.ustring.sub (form, -1, -1) == "e" then
					table.insert (Categories, "Konjugationsklasse " .. aspekt .. " -e (Tschechisch)")
				elseif mw.ustring.sub (form, -1, -1) == "í" then
					table.insert (Categories, "Konjugationsklasse " .. aspekt .. " -í (Tschechisch)")
				elseif mw.ustring.sub (form, -1, -1) == "á" then
					table.insert (Categories, "Konjugationsklasse " .. aspekt .. " -á (Tschechisch)")
				end
			end
			local function RemoveReflexivForm (form)
				if reflexiv then
					return mw.ustring.gsub (form, " " .. reflexiv .. "$", "")
				else
					return form
				end	
			end	
			
			if type (Formen["3. Person Singular"]) == "string" then
				KonjugationKategorie ( RemoveReflexivForm ( Formen["3. Person Singular"] ) )
			elseif type (Formen["3. Person Singular"]) == "table" then
				for _, form in pairs (Formen["3. Person Singular"]) do
						KonjugationKategorie ( RemoveReflexivForm ( form ) )
				end
			end	
				
		end
		out = PrintVerb (Formen)
		out = out .. frame:expandTemplate{ title = 'Anmerkung ', args = { 'zum Aspekt'}  } .. Anmerkung[aspekt]


		if (arg["reflexiv"] and arg["reflexiv"] ~= "") or (arg["irreflexiv"] and arg["irreflexiv"] ~= "") or (arg["iterativ"] and arg["iterativ"] ~= "") or (arg["nicht iterativ"] and arg["nicht iterativ"] ~= "") or (arg["Weitere Links"] and arg["Weitere Links"] ~= "") then
			local function GetOtherLinks (form)
				if arg[form] and arg[form] ~= "" then
					if type (SplitFormen (arg[form])) == "table" then
						for _, link in pairs (SplitFormen (arg[form])) do
							table.insert (OtherLinks, link)
						end
					else
						table.insert (OtherLinks, arg[form])
					end
				end
			end
			local function PrintSection (section)
				if arg[section] and arg[section] ~= "" then
					out = out .. "<dd>" .. Anmerkung [ section ] .. "''" .. lemma .. "'': " .. PrintForm (section, true) .. "</dd>"
				end
			end
			local function PrintOtherSections ()
				OtherLinks = {}
				GetOtherLinks ("reflexiv" ); GetOtherLinks ("irreflexiv" ); GetOtherLinks ("Weitere Links")
				if #OtherLinks > 0 then
					out = out .. "<dd>" .. AnmerkungSieheAuch
					for n, link in pairs (OtherLinks) do
						out = out .. PrintLink (link)
						if n ~= #OtherLinks then
							out = out .. ", "
						end
					end			
					out = out .. "</dd>"	
				end
			end
			
			out = out .. frame:expandTemplate{ title = 'Anmerkung' } .. "<dl>"
			PrintOtherSections ()
			PrintSection ("iterativ")			
			PrintSection ("nicht iterativ")			
			
			out = out .. "</dl>"
		end	
		
		
	end
	out = out .. PrintCategories()
	
	return out

	
end

function PrintNewAndOldTable (frame)
	local out = "<div style=\"display: inline-flex\"> Neu:<br />"
	out = out .. PrintSubstantiv (Formen)
	out = out .. "Alt:<br />"
	local passed_args = { lemma_except_last_two_letters, second_to_last_letter, last_letter }
	for name, val in pairs (arg) do
		if name and name ~= "" then
			passed_args[name] = val
		end
	end	
	out = out .. frame:expandTemplate{ title = 'Tschechisch Substantiv ' .. genus, args = passed_args }
	out = out .. "</div>"
	return out
end	

function p.PrintVerbalAdjSubstTest (frame)
	local out = ""
	local page = tonumber(frame.args[1])
	local number_of_pages = 3
	local Wortliste = require ("Module:Tschechisch/Wortliste")
	local Verben = Wortliste["Verben"]
	local Data = {}
	local err = "ERROR: Seite existiert nicht."
	local a, b
	local missing = 0
	
	if (page ~= 1) then
		a = (page-1)*500
		if (a+500) < #Verben then
			b = a+500
		else
			b = #Verben
		end	
	else
		a=1
		b=500
	end

	while a < b do
		local verb = Verben[a]
		local title = mw.title.new(verb)
		if not title.exists then
			table.insert (Data, { verb, err, err, "", "", "" } )
		else
			local adjroot, substroot, adj, subst
			local refl = ""
			local irrefl = ""
			local iter = ""
			local niter = ""
			
			local content = title:getContent()
			local tab = mw.ustring.match( content, "{{Tschechisch Verb Übersicht [i]*[m]*perfektiv[^}]*" )
			local aspekt
			local aspektpartner = ""
			
			if tab then
				
				if mw.ustring.match (tab, "Tschechisch Verb Übersicht perfektiv") then
					aspekt = "perfektiv"
					if mw.ustring.match( tab, "|imperfektiv=([^|]*)" ) then
						aspektpartner = mw.text.trim ( mw.ustring.match( tab, "|imperfektiv=([^|]*)" ) )
					end							
				else
					aspekt = "imperfektiv"
					if mw.ustring.match( tab, "|perfektiv=([^|]*)" ) then
						aspektpartner = mw.text.trim ( mw.ustring.match( tab, "|perfektiv=([^|]*)" ) )
					end	
				end
				
				
				if mw.ustring.match( tab, "|reflexiv=([^|]*)" ) then
					refl = mw.text.trim ( mw.ustring.match( tab, "|reflexiv=([^|]*)" ) )
				end
				if mw.ustring.match( tab, "|irreflexiv=([^|]*)" ) then
					irrefl = mw.text.trim ( mw.ustring.match( tab, "|irreflexiv=([^|]*)" ) )
				end
				if mw.ustring.match( tab, "|iterativ=([^|]*)" ) then
					iter = mw.text.trim ( mw.ustring.match( tab, "|iterativ=([^|]*)" ) )
					if aspekt == "perfektiv" then
						iter = "<span style=\"color:red;font-weight:bold\">" .. iter .. "</span>"
					end	
				end				
				if mw.ustring.match( tab, "|nicht iterativ=([^|]*)" ) then
					niter = mw.text.trim ( mw.ustring.match( tab, "|nicht iterativ=([^|]*)" ) )
				end	
				if mw.ustring.match( tab, "|Verbaladjektiv=([^|]*)" ) then
					adj = mw.text.trim ( mw.ustring.match( tab, "|Verbaladjektiv=([^|]*)" ) )
					adj = "<span style=\"color:blue;font-weight:bold\">" .. adj .. "</span>"
				else	
					if mw.ustring.match( tab, "|3. Person Plural=([^|]*)" ) then
						adjroot = mw.text.trim ( mw.ustring.match( tab, "|3. Person Plural=([^|]*)" ))
						local reflexiv = false
						if mw.ustring.match (verb, " se$") then
							reflexiv = "se"
						elseif mw.ustring.match (verb, " si$") then
							reflexiv = "si"
						end
		
						if not reflexiv then
							adj = adjroot .. "cí"
						elseif reflexiv == "se" then
							adjroot = mw.ustring.gsub(adjroot, " se$", "")
							adj = adjroot .. "cí se"	
						elseif reflexiv == "si" then
							adjroot = mw.ustring.gsub(adjroot, " si$", "")
							adj = adjroot .. "cí si"	
						end	
							
					else
						adj = "ERROR"
					end
					
				end	
				if mw.ustring.match( tab, "|Verbalsubstantiv=([^|]*)" ) then
					subst = mw.text.trim ( mw.ustring.match( tab, "|Verbalsubstantiv=([^|]*)" ) )
					subst = "<span style=\"color:blue;font-weight:bold\">" .. subst .. "</span>"
				else 
					if mw.ustring.match( tab, "|Partizip Passiv=([^|]*)" ) then
						substroot = mw.text.trim ( mw.ustring.match( tab, "|Partizip Passiv=([^|]*)" ) )
						if substroot == "" or substroot == "-" or substroot == "–" or substroot == "—" then
							missing = missing + 1
							subst = "<span style=\"color:gray;font-weight:italics\">fehlt</span>"
						else	
							subst = substroot .. "í"
						end	
					else	
						missing = missing + 1
						subst = "ERROR"
					end	
				end	
			else
				adj = "ERROR"
				subst = "ERROR"
				missing = missing + 1
			end	

			table.insert (Data, { Verben[a], aspektpartner, adj, subst, refl, irrefl, iter, niter, aspekt } )
			
			
		end	
					
		a = a + 1
	end	
	out = "Seite: "
	local s = 1
	while s <= number_of_pages do
		out = out .. "[[Template:Tschechisch Verb Übersicht imperfektiv/VerbAdjSubst-Test" .. s .."|" .. s .. "]]"
		if s ~= number_of_pages then
			out = out .. ", "
		else
			out = out .. "<br>"
		end
		s = s + 1
	end	
	out = out .. "Anzahl der fehlenden Verbalsubstantive: " .. missing .. "</br>"
	out = out .. "<table class=\"wikitable sortable\">"
	out = out .. "<tr><th>Verb</th><th>Aspektpartner</th><th>Verbaladjektiv</th><th>Verbalsubstantiv</th><th>reflexiv</th><th>irreflexiv</th><th>iterativ</th><th>nicht iterativ</th></tr>"
	for n, verb in pairs (Data) do
		local verb = Data[n][1]
		local aspektpartner = Data[n][2] 
		local adj = Data[n][3]
		local subst = Data[n][4]
		local refl = Data[n][5]
		local irrefl = Data[n][6]
		local iter = Data[n][7]
		local niter = Data[n][8]
		local aspekt = Data[n][9]
		
		out = out .. "<tr>"
		out = out .. "<th>[[" .. verb .. "]]</th>"
		out = out .. "<td>" .. aspektpartner .. "</td>"
		if aspekt == "perfektiv" then
			out = out .. "<td>(" .. adj .. ")</td>"
		else	
			out = out .. "<td>" .. adj .. "</td>"
		end	
		out = out .. "<td>" .. subst .. "</td>"
		out = out .. "<td>" .. refl .. "</td>"
		out = out .. "<td>" .. irrefl .. "</td>"
		out = out .. "<td>" .. iter .. "</td>"
		out = out .. "<td>" .. niter .. "</td>"
		out = out .. "</tr>"
	end
	out = out .. "</table>"
	return out
	
end	

-- just experimenting :)
function p.ExamplesDictionary (frame)
-- "settings"
	local AllLemmas = require ("Module:Tschechisch/Wortliste")
	local entries_on_page = 100
	local linkpage
--
	local wordCategory = frame.args[1]
	local page = tonumber(frame.args[2])
	linkpage = "Wiktionary:Tschechisch/Beispielwörterbuch/" .. wordCategory .. "/Seite "
	local out = ""
	local Errors = {}

	Entries = AllLemmas[wordCategory]

		
	local EntriesHere = {}
	local Data = {}
	
	local FirstLastEntries = {}
	local number_of_pages = math.floor (( #Entries -1) / entries_on_page)+1
	local a, b
	
	if page == 1 then
		a = 1
		b = entries_on_page
	elseif page > 1 then
		a = ((page-1) * entries_on_page)+1
		b = a + entries_on_page-1
	end
	while a <= b do
		table.insert (EntriesHere, Entries[a])
		a = a + 1
	end
	
	CategoriesList = {}
	for name, tab in pairs (AllLemmas) do
		table.insert(CategoriesList, name)
	end
	table.sort(CategoriesList)
	for n, cat in pairs (CategoriesList) do
		link = "Wiktionary:Tschechisch/Beispielwörterbuch/" .. cat .. "/Seite 1"
		out = out .. "[[" .. link .. "|" .. cat .. "]] "
	end
	out = out .. "<br />"
	a = 1
	local first, last
	while a < #Entries do
		if a + entries_on_page < #Entries then
			b = a + (entries_on_page-1)
		else
			b = #Entries
		end
		first = Entries [a]
		last = Entries [b]
		table.insert (FirstLastEntries, { first, last })
		a = b + 1
	end
	out = out .. "Seite: "
	local seite = 1

	while seite <= number_of_pages do
		out = out .. "[[" .. linkpage .. seite .."|" .. FirstLastEntries[seite][1] .. "-" .. FirstLastEntries[seite][2] .. "]]"
		if seite ~= number_of_pages then
			out = out .. ", "
		else
			out = out .. "<br>"
		end
		seite = seite + 1
	end	

	for _, pagename in pairs (EntriesHere) do
		title = mw.title.new(pagename)
		if not title.exists then
			table.insert (Errors, "Die Seite " .. pagename .. " existiert nicht. ")
		else
			local bedeutungen = false
			local beispiele = false
			local content = title:getContent()
			content = mw.ustring.gsub( content, '<!%-%-.-%-%->', '' )
			content = mw.ustring.gsub( content, '<nowiki>.-</nowiki>', '' )
			content = mw.ustring.gsub( content, '<pre[^>]->.-</pre>', '' )
			local languages = 0
			for lang in mw.ustring.gmatch (content, "{{Sprache|") do
				languages = languages + 1
			end	
	
			if languages > 1 then
				content = mw.ustring.gsub (content, "^.*(==[^{]*{{Sprache|Tschechisch}})", "%1")
				content = mw.ustring.gsub (content, "(==[^{]*{{Sprache|[^T]*[^s]*[^e]*[^c]*[^h]*[^i]*[^s]*[^c]*[^h]*)", "")
			end	
			for line in mw.text.gsplit( content, '\n' ) do
				if mw.ustring.match (line, "[{][{]Bedeutungen}}") then
					bedeutungen = true
					if not Data[pagename] then
						Data[pagename] = {}
					end
				else 
					if bedeutungen then
						local num, def
						if mw.ustring.match (line, "^:[[][0-9]+[]]") then
							num = mw.ustring.match (line, "^:[[]([0-9]+)[]]")
							if not (Data[pagename][num]) then
								Data[pagename][num] = {}
							end		
							def = mw.ustring.gsub (line, "^:[[]([0-9]+)[]]", "")
							def = mw.ustring.gsub (def, "{{K[^}]*}}", "")
							Data[pagename][num]["Def"] = def
						else
							if not mw.ustring.match (line, "^*[ ]*{{K|.*") then
								bedeutungen = false
							end	
						end	
					end	
				end	
				if mw.ustring.match (line, "[{][{]Beispiele}}") then
					local bsp, trans, num
					beispiele = true
				else 
					if beispiele then
						if mw.ustring.match (line, "^:[[][0-9]+[]]") then
							num = mw.ustring.match (line, "^:[[]([0-9]+)[]]")
							if num then
								if not Data[pagename] then
									Data[pagename] = {}
								end	
								if not Data[pagename][num] then
									Data[pagename][num] = {}
								end
								if not Data[pagename][num]["Bsp"] then
									Data[pagename][num]["Bsp"] = {}
								end
								bsp = mw.ustring.gsub (line, "^:[[]([0-9]+)[]]", "")
								bsp = mw.ustring.gsub (bsp, "''", "'''")
								local ref = mw.ustring.match (bsp, "<ref>([^<]*)</ref>")
								if ref then
									bsp = mw.ustring.gsub (bsp, "<ref>([^<]*)</ref>", frame:callParserFunction{ name = '#tag:ref', args = { ref } })
								else
									--e. g. <ref name="švejk">Jaroslav Hašek: Osudy dobrého vojáka Švejka za světové války</ref>
									local refname, ref = mw.ustring.match (bsp, "<ref[ ]*name[ ]*=[ ]*[\"']*([^\"']*)[\"']*>([^<]*)</ref>")
									if refname and ref then
										bsp = mw.ustring.gsub (bsp, "<ref[ ]*name[ ]*=[ ]*[\"']*([^\"']*)[\"']*>([^<]*)</ref>", frame:callParserFunction{ name = '#tag:ref', args = { ref, name = refname } })
									else
										--e. g. “<ref name="švejk" />
										local refname = mw.ustring.match (bsp, "<ref[ ]*name[ ]*=[ ]*[\"']*([^\"']*)[\"']*[ ]*[/]*>")
										if refname then
											bsp = mw.ustring.gsub (bsp, "<ref[ ]*name[ ]*=[ ]*[\"']*([^\"']*)[\"']*[ ]*[/]*>", frame:callParserFunction{ name = '#tag:ref', args = { name = refname } })
										end
									end	
								end	
							end
						elseif mw.ustring.match (line, "^::") then
							trans = mw.ustring.gsub (line, "^::", "")
							trans = mw.ustring.gsub (trans, "''", "'''")
							local ref = mw.ustring.match (trans, "<ref>([^<]*)</ref>")
							if ref then
								trans = mw.ustring.gsub (trans, "<ref>([^<]*)</ref>", frame:callParserFunction{ name = '#tag:ref', args = { ref } })
							end
							if Data[pagename][num]["Bsp"] then
								table.insert (Data[pagename][num]["Bsp"], { bsp, trans } )
							else
								Data[pagename][num]["Bsp"] = { { bsp, trans } }
							end
						else		
							beispiele = false
						end	
					end	
				end	
	
			end
		end	

	out = out .. "<table style=\"width:100%;border:1px dotted #DAEAFA; border-collapse:collapse; padding:5px;\">"
			
		if Data[pagename] then
			out = out .. "<tr><td colspan=\"2\" style=\"background-color: #DAEAFA; color: #2c87f0; padding: 12px; font-size: 2em\">[[" .. pagename .. "]]</td></tr>"

			local BedSorted = {}
			for bed in pairs (Data[pagename]) do
				table.insert (BedSorted, bed)
			end	
			table.sort (BedSorted)

			for _, bed in pairs (BedSorted) do
				local def = ""
				if Data[pagename][bed]["Def"] and Data[pagename][bed]["Def"] ~= "" then
					def = Data[pagename][bed]["Def"]
					out = out .. "<tr><td colspan=\"2\" style=\"background-color:#EBF4FA; color: #2B3856; padding: 0px; font-size: 0.8em; text-align: center\">" .. def .. "</td></tr>"
				end	

				if Data[pagename] and Data[pagename][bed] and Data[pagename][bed]["Bsp"] then
					for ex in pairs (Data[pagename][bed]["Bsp"]) do
						out = out .. "<tr>"
						out = out .. "<td style=\"border:1px dotted #C0C0C0; width:50%\">" .. Data[pagename][bed]["Bsp"][ex][1] .. "</td>"
						out = out .. "<td style=\"border:1px dotted #C0C0C0; width:50%\">" .. Data[pagename][bed]["Bsp"][ex][2] .. "</td>"
						out = out .. "</tr>"
					end
				end
			end

		end	
out = out .. "</table>"	
	end
	
	return out
	
end	
return p