Module:User:沈澄心/sandbox

local export = {}

local function autoinflect(lemma) local stem, substem, extra, ending = mw.ustring.match(lemma, "^((.+)(ch))([iy])$") if not extra then stem, substem, extra, ending = mw.ustring.match(lemma, "^((.+)([hktdłčšžnw]))([iy])$") end if not extra then stem, substem, ending = mw.ustring.match(lemma, "^((.+))([iy])$") end local extra_alt = { ["h"] = "z", ["ch"] = "š", ["k"] = "c", ["t"] = "ć", ["d"] = "dź", ["ł"] = "l" } local soft = ending == "i" and mw.ustring.match(extra, "^[čšžnw]$") return { [1] = lemma, [2] = stem .. (soft and "j" or "") .. "e", [3] = stem .. (soft and "j" or "") .. "a", [4] = stem .. (soft and "jej" or "aj"), [5] = stem .. (soft and "j" or "") .. "ej", [6] = substem .. (extra_alt[extra] or extra or "") .. (ending == "y" and "i" or (extra_alt[extra] and mw.ustring.match(extra_alt[extra], "^[cz]$") and "y" or "i")), [7] = stem .. (soft and "j" or "") .. "eho", [8] = stem .. (soft and "j" or "") .. "eje", [9] = stem .. (soft and "j" or "") .. "eju", [10] = lemma .. "ch", [11] = stem .. (soft and "j" or "") .. "emu", [12] = lemma .. "maj", [13] = lemma .. "m", [14] = stem .. (soft and "j" or "") .. "u", [15] = lemma .. "mi", [16] = (ending == "i" and not soft) and (stem .. "ej") or nil, [17] = stem .. (soft and "j" or "") .. "oh", [18] = stem .. (soft and "j" or "") .. "om", } end

function export.show(frame) local title = mw.title.getCurrentTitle local pargs = frame:getParent.args local lemma = frame.args[1] or pargs[1]; if lemma == "" then lemma = nil end lemma = lemma or (title.namespace == 0 and title.text) or (title.nsText == "Template" or title.nsText == "User" and "tuni") local declinfo = autoinflect(lemma, pargs) or error(("No declension pattern matches "%s""):format(lemma)) return frame:expandTemplate{ title = "User:沈澄心/sandbox2", args = declinfo } end

return export