Module:User:AryamanA/mr-decl

local export = {} local m_translit = require("Module:mr-translit")

local gsub = mw.ustring.gsub local sub = mw.ustring.sub local match = mw.ustring.match local len = mw.ustring.len

local genders = { ['m'] = 'masculine', ['f'] = 'feminine', ['f-e'] = 'feminine (exception)', ['n'] = 'neuter', }

local function wordify(text) local words, translits = {}, {} for word in mw.text.gsplit(text, ",") do		table.insert(words, mr_format(word)) table.insert(translits, m_translit.tr(word, "mr", "Deva")) end text = table.concat(words, ", ") .. " " .. table.concat(translits, ", ") .. " "	return text end

function mr_format(text) text = (' %s '):format(text) return text end

local function stem(word) return sub(word, 1, -2) end

local function stem_2(word) return sub(word, 1, -3) end

local function stem_ending(word) return sub(word, -1) end

local function generate(word, stem, g, num) paradigms = { ["m"] = { "रा", "[^र]ा", "ी", "ू", "[क-ह]" }, ["f"] = { "ा", "री", "[^र]ी", "ू", "[क-ह]" }, ["f-e"] = { "." },		["n"] = { "ी", "ू", "[क-ह]", "[ें]" }, }

-- plural, obl. sg, obl. pl (if needed) data = { ["m"] = { ["रा"] = { stem .. "े", stem_2(word) .. "ऱ्या" }, ["[^र]ा"] = { stem .. "े", stem .. "्या" }, ["ी"] = { word, word }, ["ू"] = { word, stem .. "वा" }, ["[क-ह]"] = { word, stem .. "ा" },		},		["f"] = { ["री"] = { stem_2(word) .. "ऱ्या", stem .. "ी", stem_2(word) .. "ऱ्यां" }, ["ा"] = { word, stem .. "े", word .. "ं" },			["[^र]ी"] = { word, stem .. "्या" }, ["ू"] = { word, stem .. "वा" }, ["[क-ह]"] = { stem .. "ी", stem .. "ी" },		},		["f-e"] = { ["."] = { word .. "ा", word .. "े", word .. "ां" },		},		["n"] = { ["ी"] = { word, stem .. "्या" }, ["ू"] = { stem .. "े", stem .. "ा" },			["[ें]"] = { stem .. "ी", stem .. "्या"}, ["[क-ह]"] = { stem .. "े", stem .. "ा"},		}	}	for _,paradigm in pairs(paradigms[g]) do if match(word, paradigm .. "$") then if num == 3 then if data[g][paradigm][3] then return data[g][paradigm][3] else return data[g][paradigm][2] .. "ं"				end else return data[g][paradigm][num] end end end end

local function decline(word, g, num) local c, v, v_s = "[क-ह]", "[ा-ौ]", "[अ-औ]" local ending = stem_ending(word) local stem = stem(word) -- consonant stem if match(word, c .. "$") then stem = word end -- rules for stem changes if (g == "m" or g == "n") and match(word, "." .. c .. "[ीू]" .. c .. "$") then stem = sub(word, 1, -3) .. ending end if match(word, v .. "ऊ" .. c .. "$") then stem = sub(word, 1, -3) .. "व" .. ending end return generate(word, stem, g, num) end

function export.show(frame) local args = frame:getParent.args local word = args[1] or mw.title.getCurrentTitle.text local g = args["g"] or args[2] data = [=[ return data end

return export