Module:lb-verbs

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

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

local export = {}

local function devoice_stem(stem) if mw.ustring.find(stem, "w$") then return (mw.ustring.gsub(stem, "w$", "f")) elseif mw.ustring.find(stem, "dd$") then return (mw.ustring.gsub(stem, "dd$", "tt")) elseif mw.ustring.find(stem, "d$") then return (mw.ustring.gsub(stem, "d$", "t")) 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

function export.regular(frame) local params = { [1] = {required = true, default = ""}, [2] = {required = true, default = ""}, [3] = {required = true, default = ""}, ["alt"] = {}, ["long"] = {}, ["prefix"] = {}, ["pref-n"] = {type = "boolean"}, ["pref-cons"] = {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 e = mw.ustring.find(stem, "ee$") and "ë" or "e" local s = mw.ustring.find(stem_long, "[sxz]$") and "" or "s" local t = mw.ustring.find(stem_long, "t$") and "" or "t" local data = {forms = {}, info = "regular", categories = {}} data.forms["inf"] = {stem .. e .. "n"} data.forms["ptcp"] = {args[2]} data.forms["aux"] = {args[3]} data.forms["1sg_pres_indc"] = {stem .. e .. (args["pref-cons"] and "" or "n")} 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-cons"] and "" or "n")} data.forms["2pl_pres_indc"] = {stem_long .. t} data.forms["3pl_pres_indc"] = {stem .. e .. (args["pref-cons"] and "" or "n")} 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(frame) local params = { [1] = {required = true, default = ""}, [2] = {required = true, default = ""}, [3] = {required = true, default = ""}, [4] = {required = true, default = ""}, [5] = {required = true, default = ""}, ["prefix"] = {}, ["pref-n"] = {type = "boolean"}, ["pref-cons"] = {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, "[sxz]$") and "" 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, "[sxz]$") and "" or "s" local tu = mw.ustring.find(stem_uml, "t$") and "" or "t" local data = {forms = {}, info = "irregular", categories = {}} data.forms["inf"] = {stem .. "en"} data.forms["ptcp"] = {args[4]} data.forms["aux"] = {args[5]} data.forms["1sg_pres_indc"] = {stem .. "e" .. (args["pref-cons"] and "" or "n")} 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-cons"] and "" or "n")} data.forms["2pl_pres_indc"] = {stem_long .. t} data.forms["3pl_pres_indc"] = {stem .. "e" .. (args["pref-cons"] and "" or "n")} 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 = ""}, [2] = {required = true, default = ""}, [3] = {required = true, default = ""}, [4] = {required = true, default = ""}, [5] = {required = true, default = ""}, [6] = {required = true, default = ""}, [7] = {required = true, default = ""}, ["no-t"] = {type = "boolean"}, ["prefix"] = {}, ["pref-n"] = {type = "boolean"}, ["pref-cons"] = {type = "boolean"}, ["pref-inf-n"] = {type = "boolean"}, ["only3s"] = {type = "boolean"}, ["only3sp"] = {type = "boolean"}, }	local args = require("Module:parameters").process(frame:getParent.args, params) if args["no-t"] then require("Module:debug").track("lb-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, "[sxz]$") and "" 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, "[sxz]$") and "" 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) local sp = mw.ustring.find(stem_past_dev, "[sxz]$") and "" or "s" local tp = mw.ustring.find(stem_past_dev, "t$") and "" or "t" local stem_cond = args[7] local stem_cond_dev = devoice_stem(stem_cond) local sc = mw.ustring.find(stem_cond_dev, "[sxz]$") and "" or "s" local tc = mw.ustring.find(stem_cond_dev, "t$") and "" or "t" local data = {forms = {}, info = "irregular with past tense", categories = {lang:getCanonicalName .. " verbs with past tense"}} data.past = true data.forms["inf"] = {stem .. "en"} data.forms["ptcp"] = {args[4]} data.forms["aux"] = {args[5]} data.forms["1sg_pres_indc"] = {stem .. "e" .. (args["pref-cons"] and "" or "n")} 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-cons"] and "" or "n")} data.forms["2pl_pres_indc"] = {stem_long .. t} data.forms["3pl_pres_indc"] = {stem .. "e" .. (args["pref-cons"] and "" or "n")} data.forms["2sg_impr"] = {stem_final} data.forms["2pl_impr"] = {stem_long .. t}	data.forms["1sg_past_indc"] = {stem_past_dev} data.forms["2sg_past_indc"] = {stem_past_dev .. sp} data.forms["3sg_past_indc"] = {stem_past_dev} data.forms["1pl_past_indc"] = {stem_past .. "e" .. (args["pref-cons"] and "" or "n")} data.forms["2pl_past_indc"] = {stem_past_dev .. tp} data.forms["3pl_past_indc"] = {stem_past .. "e" .. (args["pref-cons"] and "" or "n")} data.forms["1sg_cond"] = {stem_cond_dev} data.forms["2sg_cond"] = {stem_cond_dev .. sc} data.forms["3sg_cond"] = {stem_cond_dev} data.forms["1pl_cond"] = {stem_cond .. "e" .. (args["pref-cons"] and "" or "n")} data.forms["2pl_cond"] = {stem_cond_dev .. tc} data.forms["3pl_cond"] = {stem_cond .. "e" .. (args["pref-cons"] and "" or "n")} 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 indicative", ["past_indc"] = "past 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.past then columns = {"pres_indc", "past_indc", "cond", "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) .. "\" | ") table.insert(wikicode, "|- class=\"vsHide\"") table.insert(wikicode, "! style=\"background: #e2e4c0; min-width: 9em;\" | infinitive") table.insert(wikicode, "| colspan=\"" .. tostring(#columns) .. "\" | ") table.insert(wikicode, "|- class=\"vsHide\"") table.insert(wikicode, "! style=\"background: #e2e4c0;\" | participle") table.insert(wikicode, "| colspan=\"" .. tostring(#columns) .. "\" | ") table.insert(wikicode, "|- class=\"vsHide\"") table.insert(wikicode, "! style=\"background: #e2e4c0;\" | auxiliary") table.insert(wikicode, "| colspan=\"" .. tostring(#columns) .. "\" | ") 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;\" | ") end end table.insert(wikicode, "|- class=\"vsHide\"") table.insert(wikicode, "| colspan=\"" .. tostring(#columns + 1) .. "\" | (n) or (nn) indicates the Eifeler Regel.") table.insert(wikicode, "|}") wikicode = table.concat(wikicode, "\n") return mw.ustring.gsub(wikicode, "", repl) end

return export