Jump to content

Module:dsb-adecl

From Wiktionary, the free dictionary


local export = {}

-- based on [[Module:hsb-adecl]]

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, "^((.+)([gktdłčćšśžnw]))([iy])$")
	end
	if not extra then
		stem, substem, ending = mw.ustring.match(lemma, "^((.+))([iy])$")
	end
	local soft = ending == "i" and mw.ustring.match(extra, "^[čćšśžnw]$")
	local addj = ending == "i" and mw.ustring.match(extra, "^[nw]$")
	return {
		[1] = lemma,
		[2] = stem .. (addj and "j" or "") .. "e",
		[3] = stem .. (addj and "j" or "") .. "a",
		[4] = stem .. (addj and "j" or "") .. "ej",
		[5] = stem .. (addj and "j" or "") .. "ego",
		[6] = stem .. (addj and "j" or "") .. "eg",
		[7] = stem .. (addj and "j" or "") .. "eje",
		[8] = stem .. (addj and "j" or "") .. "eju",
		[9] = lemma .. "ch",
		[10] = stem .. (addj and "j" or "") .. "emu",
		[11] = stem .. (addj and "j" or "") .. "em",
		[12] = lemma .. "ma",
		[13] = lemma .. "m",
		[14] = stem .. (addj and "j" or "") .. "u",
		[15] = lemma .. "mi",
	}
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" and "tuni")
	
	local declinfo = autoinflect(lemma, pargs) or error(("No declension pattern matches "%s""):format(lemma))
	return frame:expandTemplate{ title = "dsb-decl-adj", args = declinfo }
end

return export