Jump to content

Module:li-verb-eupen

From Wiktionary, the free dictionary

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local m_utilities = require("Module:utilities")
local m_links = require("Module:links")

local lang = require("Module:languages").getByCode("li")

local export = {}

-- Devoices the stem.
local function devoice_stem(stem)
	if mw.ustring.find(stem, "gg$") then
		return (mw.ustring.gsub(stem, "gg$", "kk"))
	elseif mw.ustring.find(stem, "dd$") then
		return (mw.ustring.gsub(stem, "dd$", "tt"))
	elseif mw.ustring.find(stem, "vv$") then
		return (mw.ustring.gsub(stem, "vv$", "ff"))
	elseif mw.ustring.find(stem, "g$") then
		return (mw.ustring.gsub(stem, "g$", "ch"))
	elseif mw.ustring.find(stem, "d$") then
		return (mw.ustring.gsub(stem, "d$", "t"))
	elseif mw.ustring.find(stem, "v$") then
		return (mw.ustring.gsub(stem, "v$", "f"))
	elseif mw.ustring.find(stem, "w$") then
		return (mw.ustring.gsub(stem, "w$", ""))
	else
		return stem
	end
end

local function postprocess(args, data)
	if args["prefix"] then
		table.insert(data.categories, lang:getCanonicalName() .. " separable verbs")
		data.info = data.info .. ", separable"
		
		-- Add the separable part to all the verb forms
		for key, _ in pairs(data.forms) do
			if key:find("_indc$") or key:find("_cond$") or key:find("_impr$") then
				-- For main-clause finite forms, add the separable part after the form, separated by a space
				for i, subform in ipairs(data.forms[key]) do
					data.forms[key][i] = data.forms[key][i] .. " " .. args["prefix"] .. (args["pref-n"] and "n" or "")
				end
			elseif key == "inf" then
				for i, subform in ipairs(data.forms[key]) do
					data.forms[key][i] = args["prefix"] .. (args["pref-inf-n"] and "n" or "") .. data.forms[key][i]
				end
			elseif key ~= "aux" then
				-- For all other forms, add the separable part before the form, with no space
				for i, subform in ipairs(data.forms[key]) do
					data.forms[key][i] = args["prefix"] .. subform
				end
			end
		end
	end
	
	-- Check if the lemma form matches the page name
	if data.forms["inf"] and (lang:makeEntryName(data.forms["inf"][1])) ~= mw.title.getCurrentTitle().text then
		table.insert(data.categories, lang:getCanonicalName() .. " entries with inflection not matching pagename")
	end
	
	if args["only3s"] or args["only3sp"] then
		for key, _ in pairs(data.forms) do
			 if key:find("^1") or key:find("^2") or (args["only3s"] and key:find("^3pl")) then
			 	data.forms[key] = nil
			 end
		end
	end
end


--- Inflection functions
--- regular
function export.regular(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		[2] = {required = true, default = "{{{2}}}"},
		[3] = {required = true, default = "{{{3}}}"},
		["alt"] = {},
		["long"] = {},
		["2p"] = {},
		
		["prefix"] = {},
		["pref-n"] = {type = "boolean"},
		["pref-vow"] = {type = "boolean"},
		["pref-inf-n"] = {type = "boolean"},
		["only3s"] = {type = "boolean"},
		["only3sp"] = {type = "boolean"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local stem = args[1]
	local stem_final = devoice_stem(args["alt"] or stem)
	local stem_long = devoice_stem(args["long"] or args["alt"] or stem)
	local pst = mw.ustring.find(stem, "[dt]$") and "e" or mw.ustring.find(stem, "ss$") and "te" or "de"
	local e = mw.ustring.find(stem, "ee$") and "ë" or "e"
	local s = mw.ustring.find(stem_long, "s$") and "" or mw.ustring.find(stem_long, "ch$") and "ts" or "s"
	local t = mw.ustring.find(stem_long, "t$") and "" or "t"
	
	local data = {forms = {}, info = "regular", categories = {lang:getCanonicalName() .. " weak verbs"}}
	data.past = true
	
	data.forms["inf"] = {stem .. "e"}
	data.forms["ptcp"] = {args[2]}
	data.forms["aux"] = {args[3]}
	
	data.forms["1sg_pres_indc"] = {stem_final}
	data.forms["2sg_pres_indc"] = {stem_long .. s}
	data.forms["3sg_pres_indc"] = {stem_long .. t}
	data.forms["1pl_pres_indc"] = {stem .. e .. (args["pref-vow"] and "n" or "")}
	data.forms["2pl_pres_indc"] = {(args["2p"] or stem) .. t}
	data.forms["3pl_pres_indc"] = {stem .. e .. (args["pref-vow"] and "n" or "")}
	
	data.forms["2sg_impr"] = {stem_final}
	data.forms["2pl_impr"] = {stem_long .. t}
	
	data.forms["1sg_past_indc"] = {stem .. pst .. (args["pref-vow"] and "n" or "")}
	data.forms["2sg_past_indc"] = {stem .. pst .. "s"}
	data.forms["3sg_past_indc"] = {stem .. pst .. (args["pref-vow"] and "n" or "")}
	data.forms["1pl_past_indc"] = {stem .. pst .. (args["pref-vow"] and "n" or "")}
	data.forms["2pl_past_indc"] = {stem .. pst .. (args["pref-vow"] and "n" or "")}
	data.forms["3pl_past_indc"] = {stem .. pst .. (args["pref-vow"] and "n" or "")}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end

--- irregular
function export.irregular(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		[2] = {required = true, default = "{{{2}}}"},
		[3] = {required = true, default = "{{{3}}}"},
		[4] = {required = true, default = "{{{4}}}"},
		[5] = {required = true, default = "{{{5}}}"},
		
		["prefix"] = {},
		["pref-n"] = {type = "boolean"},
		["pref-vow"] = {type = "boolean"},
		["pref-inf-n"] = {type = "boolean"},
		["only3s"] = {type = "boolean"},
		["only3sp"] = {type = "boolean"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local stem = args[1]
	local stem_final = devoice_stem(stem)
	local stem_long = devoice_stem(args[3])
	local s = mw.ustring.find(stem_long, "s$") and "" or mw.ustring.find(stem_long, "ch$") and "ts" or "s"
	local t = mw.ustring.find(stem_long, "t$") and "" or "t"
	
	local stem_uml = devoice_stem(args[2])
	local su = mw.ustring.find(stem_uml, "s$") and "" or mw.ustring.find(stem_uml, "ch$") and "ts" or "s"
	local tu = mw.ustring.find(stem_uml, "t$") and "" or "t"
	
	local data = {forms = {}, info = "irregular", categories = {}}
	
	data.forms["inf"] = {stem .. "e"}
	data.forms["ptcp"] = {args[4]}
	data.forms["aux"] = {args[5]}
	
	data.forms["1sg_pres_indc"] = {stem .. "e" .. (args["pref-vow"] and "n" or "")}
	data.forms["2sg_pres_indc"] = {stem_uml .. su}
	data.forms["3sg_pres_indc"] = {stem_uml .. tu}
	data.forms["1pl_pres_indc"] = {stem .. "e" .. (args["pref-vow"] and "n" or "")}
	data.forms["2pl_pres_indc"] = {stem_long .. t}
	data.forms["3pl_pres_indc"] = {stem .. "e" .. (args["pref-vow"] and "n" or "")}
	
	data.forms["2sg_impr"] = {stem_final}
	data.forms["2pl_impr"] = {stem_long .. t}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


function export.irregular_full(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		[2] = {required = true, default = "{{{2}}}"},
		[3] = {required = true, default = "{{{3}}}"},
		[4] = {required = true, default = "{{{4}}}"},
		[5] = {required = true, default = "{{{5}}}"},
		[6] = {required = true, default = "{{{6}}}"},
		[7] = {required = true, default = "{{{7}}}"},
		["no-t"] = {type = "boolean"},
		
		["prefix"] = {},
		["pref-n"] = {type = "boolean"},
		["pref-vow"] = {type = "boolean"},
		["pref-inf-n"] = {type = "boolean"},
		["plus-t"] = {type = "boolean"},
		["plus-tpl"] = {type = "boolean"},
		["3s-t"] = {type = "boolean"},
		["only3s"] = {type = "boolean"},
		["only3sp"] = {type = "boolean"},
		["weak"] = {type = "boolean"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	if args["no-t"] then
		require("Module:debug").track("li-verbs/no-t")
	end
	
	local stem = args[1]
	local stem_final = devoice_stem(stem)
	local stem_long = devoice_stem(args[3] or stem)
	local s = mw.ustring.find(stem_long, "s$") and "" or mw.ustring.find(stem_long, "ch$") and "ts" or "s"
	local t = mw.ustring.find(stem_long, "t$") and "" or "t"
	
	local stem_uml = devoice_stem(args[2])
	local su = mw.ustring.find(stem_uml, "s$") and "" or mw.ustring.find(stem_uml, "ch$") and "ts" or "s"
	local tu = mw.ustring.find(stem_uml, "t$") and "" or args["no-t"] and "" or "t"
	
	local stem_past = args[6]
	local stem_past_dev = devoice_stem(stem_past)
	if args["weak"] then
		stem_past_dev = stem_past
	end
	local sp = mw.ustring.find(stem_past_dev, "s$") and "" or args["weak"] and "" or mw.ustring.find(stem_past_dev, "ch$") and "ts" or "s" 
	local tp = mw.ustring.find(stem_past_dev, "t$") and "" or "t"
	local ssp = mw.ustring.find(stem_past_dev, "ss$") and "te" or args["plus-tpl"] and "te" or args["weak"] and "" or "e"
	
	local stem_cond = args[7]
	local stem_cond_dev = devoice_stem(stem_cond)
	if args["weak"] then
		stem_cond_dev = stem_cond
	end
	local sc = mw.ustring.find(stem_cond_dev, "s$") and "" or args["weak"] and "" or mw.ustring.find(stem_cond_dev, "ch$") and "ts" or "s"
	local tc = mw.ustring.find(stem_cond_dev, "t$") and "" or "t"
	local ssc = mw.ustring.find(stem_cond_dev, "ss$") and "te" or args["plus-tpl"] and "te" or args["weak"] and "" or "e"
	
	local plust = args["plus-t"] and "t" or ""
	local plt = args["weak"] and "" or mw.ustring.find(stem_past, "[aeëïioöuü]$") and "t" or ""
	local threet = args["3s-t"] and "t" or ""
	local de = args["weak"] and "de" or ""
	local des = args["weak"] and "des" or ""
	
	local data = {forms = {}, info = "irregular with past tense", categories = {lang:getCanonicalName() .. " irregular verbs"}}
	data.cond = true
	
	data.forms["inf"] = {stem .. "e"}
	data.forms["ptcp"] = {args[4]}
	data.forms["aux"] = {args[5]}
	
	data.forms["1sg_pres_indc"] = {stem_final}
	data.forms["2sg_pres_indc"] = {stem_uml .. su}
	data.forms["3sg_pres_indc"] = {stem_uml .. tu}
	data.forms["1pl_pres_indc"] = {stem .. "e" .. (args["pref-vow"] and "n" or "")}
	data.forms["2pl_pres_indc"] = {stem_long .. t}
	data.forms["3pl_pres_indc"] = {stem .. "e" .. (args["pref-vow"] and "n" or "")}
	
	data.forms["2sg_impr"] = {stem_final}
	data.forms["2pl_impr"] = {stem_long .. t}
	
	data.forms["1sg_past_indc"] = {stem_past_dev .. plust .. de}
	data.forms["2sg_past_indc"] = {stem_past_dev .. sp .. des}
	data.forms["3sg_past_indc"] = {stem_past_dev .. plust .. threet .. de}
	data.forms["1pl_past_indc"] = {stem_past .. plt .. ssp .. de .. (args["pref-vow"] and "n" or "")}
	data.forms["2pl_past_indc"] = {stem_past_dev .. de .. tp}
	data.forms["3pl_past_indc"] = {stem_past .. plt .. ssp .. de .. (args["pref-vow"] and "n" or "")}
	
	data.forms["1sg_cond"] = {stem_cond_dev .. plust .. de}
	data.forms["2sg_cond"] = {stem_cond_dev .. sc .. des}
	data.forms["3sg_cond"] = {stem_cond_dev .. plust .. threet .. de}
	data.forms["1pl_cond"] = {stem_cond .. plt .. ssc .. de ..(args["pref-vow"] and "n" or "")}
	data.forms["2pl_cond"] = {stem_cond_dev .. de .. tc}
	data.forms["3pl_cond"] = {stem_cond .. plt .. ssc .. de .. (args["pref-vow"] and "n" or "")}
	
	postprocess(args, data)
	
	return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end


local names = {
	["inf"] = "infinitive",
	["ptcp"] = "participle",
	["aux"] = "auxiliary",
	
	["pres_indc"] = "present<br/>indicative",
	["past_indc"] = "past<br/>indicative",
	["cond"] = "conditional",
	["impr"] = "imperative",
	
	["1sg"] = "1st singular",
	["2sg"] = "2nd singular",
	["3sg"] = "3rd singular",
	["1pl"] = "1st plural",
	["2pl"] = "2nd plural",
	["3pl"] = "3rd plural",
}

-- Make the table
function make_table(data)
	local function repl(param)
		if param == "info" then
			return mw.getContentLanguage():ucfirst(data.info or "")
		end
		
		local forms = data.forms[param]
		
		if not forms then
			return "&mdash;"
		end
		
		local ret = {}
		
		for _, form in ipairs(forms) do
			table.insert(ret, m_links.full_link({lang = lang, term = form}))
		end
		
		return table.concat(ret, ", ")
	end
	
	local rows = {"1sg", "2sg", "3sg", "1pl", "2pl", "3pl"}
	local columns = {"pres_indc", "impr"}
	
	if data.cond then
		columns = {"pres_indc", "past_indc", "cond", "impr"}
		else
			columns = {"pres_indc", "past_indc", "impr"}
	end
	
	
	local wikicode = {}
	
	table.insert(wikicode, "{| class=\"inflection-table vsSwitcher\" data-toggle-category=\"inflection\" style=\"background: #F9F9F9; border: 1px solid #aaa;\"")
	table.insert(wikicode, "|- style=\"background: #ccc; text-align: left;\"")
	table.insert(wikicode, "! class=\"vsToggleElement\" style=\"min-width: 33em;\" colspan=\"" .. tostring(#columns + 1) .. "\" | {{{info}}} (Eupen dialect)")
	table.insert(wikicode, "|- class=\"vsHide\"")
	table.insert(wikicode, "! style=\"background: #e2e4c0; min-width: 9em;\" | infinitive")
	table.insert(wikicode, "| colspan=\"" .. tostring(#columns) .. "\" | {{{inf}}}")
	table.insert(wikicode, "|- class=\"vsHide\"")
	table.insert(wikicode, "! style=\"background: #e2e4c0;\" | participle")
	table.insert(wikicode, "| colspan=\"" .. tostring(#columns) .. "\" | {{{ptcp}}}")
	table.insert(wikicode, "|- class=\"vsHide\"")
	table.insert(wikicode, "! style=\"background: #e2e4c0;\" | auxiliary")
	table.insert(wikicode, "| colspan=\"" .. tostring(#columns) .. "\" | {{{aux}}}")
	table.insert(wikicode, "|- class=\"vsHide\" style=\"background: #e2e4c0;\"")
	table.insert(wikicode, "!")
	
	for _, col in ipairs(columns) do
		table.insert(wikicode, "! " .. names[col])
	end
	
	for _, row in ipairs(rows) do
		table.insert(wikicode, "|- class=\"vsHide\"")
		table.insert(wikicode, "! style=\"background:#DEDEDE\" | " .. names[row])
		
		for _, col in ipairs(columns) do
			table.insert(wikicode, "| style=\"min-width: 12em;\" | {{{" .. row .. "_" .. col .. "}}}")
		end
	end
	
	table.insert(wikicode, "|- class=\"vsHide\"")
--	table.insert(wikicode, "| colspan=\"" .. tostring(#columns + 1) .. "\" | (n) or (nn) indicates the [[w:Eifeler Regel#Luxembourgish|Eifeler Regel]].")
	table.insert(wikicode, "|}")
	
	wikicode = table.concat(wikicode, "\n")
	
	return mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)
end

return export