Module:User:Kutchkutch/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 tc = table.concat

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

function export.wordify(text, text_translit) local words, translits = {}, {} for word in mw.text.gsplit(text, ",") do		table.insert(words, mr_format(word)) end

table.insert(translits, text_translit)

text = table.concat(words, ", ") .. " " .. table.concat(translits, ", ") .. " "	return text end

function mr_format(text) text = (' '):format(gsub(text, "़", "")) .. 		('%s '):format(text) return text end

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

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

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

local function get_penultimate_letter(word) return sub(word, -2, -2) end

local function weaken_penultimate_iu(word) local weakened_stem = "" local last_letter = get_last_letter(word) local penultimate_letter = get_penultimate_letter(word) local penultimate_stem = get_without_last_two_letters(word)

-- īC stem if penultimate_letter == "ी" then weakened_stem = penultimate_stem .. "ि" .. last_letter elseif penultimate_letter == "ई" then weakened_stem = penultimate_stem .. "इ" .. last_letter

-- ūC stem elseif penultimate_letter == "ू" then weakened_stem = penultimate_stem .. "ु" .. last_letter elseif penultimate_letter == "ऊ" then weakened_stem = penultimate_stem .. "उ" .. last_letter end return weakened_stem end

local function get_s_obl(word, g)

local penultimate_letter = get_penultimate_letter(word) local stem = get_without_last_letter(word) local ending = get_last_letter(word)

-- masc rā-stem if g == "m" and penultimate_letter == "र" then stem = get_without_last_two_letters(word) ending = "र" .. get_last_letter(word) end data = { ["m"] = { ["default"] = word .. "ा",					["ा"] = stem .. "्या", ["रा"] = stem .. "ऱ्या",

["ी"] = stem .. "्या", ["ू"] = stem .. "वा", ["ृ"] = word, ["ो"] = word, },		["f"] = { ["default"] = word .. "ी",					["ा"] = stem .. "े", 					["ी"] = word, ["ू"] = stem .. "वे", ["ृ"] = word, ["ै"] = stem .. "या", ["ो"] = word, },		["f-e"] = { ["default"] = word .. "े"				},		["n"] = { ["default"] = word .. "ा",					["ी"] = stem .. "्या", ["ू"] = stem .. "वा", ["े"] = stem .. "्या", }	}	return data[g][ending] or data[g]["default"] end

local function get_p_dir(word, g)	local ending = get_last_letter(word) local stem = get_without_last_letter(word) data = { ["m"] = { ["default"] = {word} , ["ा"] = {stem .. "े"}, 						["ृ"] = {word}, ["ो"] = {word}, },		["f"] = { ["default"] = {word .. "ी"},						["ा"] = {word}, ["ी"] = {stem .. "्या"}, ["ू"] = {stem .. "वा"}, ["ृ"] = {word}, ["ै"] = {stem .. "या"}, ["ो"] = {stem .. "ा"}, 				},		["f-e"] = { ["default"] = {word .. "ा"},				},		["n"] = { ["default"] = {word .. "े", word .. "ं"},						["ू"] = {stem .. "वे", stem .. "वं"}, ["े"] = {stem .. "ी"},				}	}	-- it's ugly but it works ^_^ if g == "n" and (get_last_letter(m_translit.tr(word)) == "a" or ending == "ी") then return {word} end return data[g][ending] or data[g]["default"] end

local function get_p_obl(word, g)	local ending = get_last_letter(word) local stem = get_without_last_letter(word)

local plural_direct = get_p_dir(word, g)[1] local singular_oblique = get_s_obl(word, g)

data = { ["m"] = { ["default"] = singular_oblique .. "ं",

["ा"] = singular_oblique .. "ं", 					["ी"] = singular_oblique .. "ं", 					["ू"] = singular_oblique .. "ं", 					["ृ"] = singular_oblique .. "ं", 					["ो"] = singular_oblique .. "ं", 				},		["f"] = { ["default"] = plural_direct .. "ं",					["ा"] = plural_direct .. "ं", 					["ी"] = plural_direct .. "ं", 					["ू"] = plural_direct .. "ं", 					["ृ"] = plural_direct .. "ं", 					["ै"] = plural_direct .. "ं", 					["ो"] = plural_direct .. "ं",				},		["f-e"] = { ["default"] = plural_direct .. "ं",				},		["n"] = { ["default"] = singular_oblique .. "ं",					["ी"] = singular_oblique.. "ं",					["ू"] = singular_oblique .. "ं", 					["े"] = singular_oblique .. "ं",				}	}	return data[g][ending] or data[g]["default"] end

function get_weakened_cases(word, g, case) local weakened_stem = weaken_penultimate_iu(word) weakened_iu_cases = { ["m"] = { ["direct plural"] = get_p_dir(word, g), ["oblique singular"] = get_s_obl(weakened_stem, g), ["oblique plural"] = get_p_obl(weakened_stem, g), },		["f"] = { ["direct plural"] = get_p_dir(weakened_stem, g), ["oblique singular"] = get_s_obl(weakened_stem, g), ["oblique plural"] = get_p_obl(weakened_stem, g), },		["f-e"] = { ["direct plural"] = get_p_dir(weakened_stem, g), ["oblique singular"] = get_s_obl(weakened_stem, g), ["oblique plural"] = get_p_obl(weakened_stem, g), },		["n"] = { ["direct plural"] = get_p_dir(weakened_stem, g), ["oblique singular"] = get_s_obl(weakened_stem, g), ["oblique plural"] = get_p_obl(weakened_stem, g), }	}	return weakened_iu_cases[g][case] end

function handle_options(word, g, options)

local singular_oblique, plural_oblique, plural_direct = "", "", ""

-- no options if options == nil then plural_direct = get_p_dir(word, g)		singular_oblique = get_s_obl(word, g)		plural_oblique = get_p_obl(word, g)

-- weaken_iu option elseif options["weaken_iu"] == "true" then plural_direct = get_weakened_cases(word, g, "direct plural") singular_oblique = get_weakened_cases(word, g, "oblique singular") plural_oblique = get_weakened_cases(word, g, "oblique plural") elseif options["number"] == "sg-only" then plural_direct = "-" singular_oblique = get_s_obl(word, g)		plural_oblique = "-" end

return singular_oblique, plural_oblique, plural_direct end

function export.forms(word, g, options)

local singular_oblique, plural_oblique, plural_direct = handle_options(word, g, options)

form = {} translit_form = {}

-- dir. sg. form.dirs = {word} translit_form.dirs = {m_translit.tr(word, "mr", "Deva")} -- dir. pl.	if plural_direct == "-" then form.dirp = {"-"} translit_form.dirp = {"-"} elseif plural_direct[2] == nil then form.dirp = {plural_direct[1]} translit_form.dirp = {m_translit.tr(plural_direct[1])} else form.dirp = {plural_direct[1], plural_direct[2]} translit_form.dirp = {m_translit.tr(plural_direct[1]), m_translit.tr(plural_direct[2])} end -- obl. sg. form.obls = {singular_oblique} translit_form.obls = {m_translit.tr(singular_oblique)} -- obl. pl.	form.oblp = {plural_oblique} translit_form.oblp = {m_translit.tr(plural_oblique)}

-- dative form.dats = {singular_oblique .. "ला"} translit_form.dats = {m_translit.tr(singular_oblique .. "ला")}

form.datp = {plural_oblique .. "ना"} translit_form.datp = {m_translit.tr(plural_oblique .. "ना")}

-- ergative form.ergs = {singular_oblique .. "ने"} translit_form.ergs = {m_translit.tr(singular_oblique .. "ने")}

form.ergp = {plural_oblique .. "नी"} translit_form.ergp = {m_translit.tr(plural_oblique .. "नी")}

-- instrumental form.inss = {singular_oblique .. "शी"} translit_form.inss = {m_translit.tr(singular_oblique .. "शी")}

form.insp = {plural_oblique .. "शी"} translit_form.insp = {m_translit.tr(plural_oblique .. "शी")}

-- locative form.locs = {singular_oblique .. "त"} translit_form.locs = {m_translit.tr(singular_oblique .. "त")} form.locp = {plural_oblique .. "त"} translit_form.locp = {m_translit.tr(plural_oblique .. "त")}

-- vocative form.vocs = {singular_oblique} translit_form.vocs = {m_translit.tr(singular_oblique)}

form.vocp = {plural_oblique .. "नो"} translit_form.vocp = {m_translit.tr(plural_oblique .. "नो")}

-- genitive singular form.gsns = {singular_oblique .. "च़े", singular_oblique .. "च़ं"} translit_form.gsns = {m_translit.tr(singular_oblique .. "च़े"), m_translit.tr(singular_oblique .. "च़ं")}

form.gsnp = {singular_oblique .. "ची"} translit_form.gsnp = {m_translit.tr(singular_oblique .. "ची")}

form.gsms = {singular_oblique .. "च़ा"} translit_form.gsms = {m_translit.tr(singular_oblique .. "च़ा")}

form.gsmp = {singular_oblique .. "च़े"} translit_form.gsmp = {m_translit.tr(singular_oblique .. "च़े")}

form.gsfs = {singular_oblique .. "ची"} translit_form.gsfs = {m_translit.tr(singular_oblique .. "ची")}

form.gsfp = {singular_oblique .. "च्या"} translit_form.gsfp = {m_translit.tr(singular_oblique .. "च्या")}

form.gso = {singular_oblique .. "च्या"} translit_form.gso = {m_translit.tr(singular_oblique .. "च्या")}

-- genitive plural form.gpns = {plural_oblique .. "च़े", plural_oblique .. "च़ं"} translit_form.gpns = {m_translit.tr(plural_oblique .. "च़े"), m_translit.tr(plural_oblique .. "च़ं")}

form.gpnp = {plural_oblique .. "ची"} translit_form.gpnp = {m_translit.tr(plural_oblique .. "ची")}

form.gpms = {plural_oblique .. "च़ा"} translit_form.gpms = {m_translit.tr(plural_oblique .. "च़ा")}

form.gpmp = {plural_oblique .. "च़े"} translit_form.gpmp = {m_translit.tr(plural_oblique .. "च़े")}

form.gpfs = {plural_oblique .. "ची"} translit_form.gpfs = {m_translit.tr(plural_oblique .. "ची")}

form.gpfp = {plural_oblique .. "च्या"} translit_form.gpfp = {m_translit.tr(plural_oblique .. "च्या")}

form.gpo = {plural_oblique .. "च्या"} translit_form.gpo = {m_translit.tr(plural_oblique .. "च्या")}

return form, translit_form end

local function tcc(words) return tc(words, ', ') 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] local form, translit_form = export.forms(word, g, args[3]) data = [=[ ]=]   data = data .. [=[ ]=]

return data end

return export