Module:pmh-decl-noun-Deva

From Wiktionary, the free dictionary
Jump to navigation Jump to search

local export = {}

local m_links = require("Module:links")
local m_translit = require("Module:sa-translit")
local lang = require("Module:languages").getByCode("inc-pra") or error("Language object not got.")
local PAGENAME = mw.title.getCurrentTitle().text

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

local genders = {
	["m"] = "masculine", ["f"] = "feminine", ["n"] = "neuter",
}

local cases = {
	"Nominative", "Accusative", "Instrumental", "Dative", "Ablative",
	"Genitive", "Locative", "Vocative"
}

function ending(tr)
	return sub(tr, -1, -1)
end


function export.joinSuffix(frame, stem, suffixes)

	local output = ""
	local term
	
	local function to_Deva(tr)
		local result = frame:expandTemplate{ title = 'chars', args = { 'sa', tr } }
		return result
	end

	for _,suffix in ipairs(suffixes) do
		if match(suffix, "^⌫⌫") then --backspace
			term = sub(stem, 1, -3) .. sub(suffix, 3, -1)
		elseif match(suffix, "^⌫") then --backspace
			term = sub(stem, 1, -2) .. sub(suffix, 2, -1)
		else
			term = stem .. suffix
		end
		
		if output ~= "" then
			output = output .. " <small style=\"color:888\">or</small> "
		end
		output = output .. m_links.full_link({lang = lang, sc = require("Module:scripts").getByCode("Deva"),	term = to_Deva(term)})
	end
	
	if output == "" then
		output = "—"
	end

	return output

end

function export.select(dialect, word, g, sc)	
	local data = {}

data['a'] = {
	m = {{'⌫o'}, {'⌫ā'}, -- nom
		 {'ṃ'}, {'⌫e', '⌫ā'}, -- acc
		 {'⌫eṇa', '⌫eṇaṃ'}, {'⌫ehi', '⌫ehiṃ'}, -- ins
		 {'⌫āa'}, {nil}, -- dat
		 {'⌫āo', '⌫āu', '⌫ā', '⌫āhi', '⌫āhiṃto'}, {nil}, --abl
		 {'ssa'}, {'⌫āṇa', '⌫āṇaṃ'}, -- gen
		 {'mmi', '⌫e'}, {'⌫esu', '⌫esuṃ'}, -- loc
		 {'', '⌫ā'}, {'⌫ā'}, -- voc
	},
	n = {{'ṃ'}, {'⌫āiṃ', '⌫āi'}, -- nom
		 {'ṃ'}, {'⌫āiṃ', '⌫āi'}, -- acc
		 {'⌫eṇa', '⌫eṇaṃ'}, {'⌫ehi', '⌫ehiṃ'}, -- ins
		 {'⌫āa'}, {nil}, -- dat
		 {'⌫āo', '⌫āu', '⌫ā', '⌫āhi', '⌫āhiṃto'}, {nil}, --abl
		 {'ssa'}, {'⌫āṇa', '⌫āṇaṃ'}, -- gen
		 {'mmi', '⌫e'}, {'⌫esu', '⌫esuṃ'}, -- loc
		 {'', '⌫ā'}, {'⌫āiṃ', '⌫āi'}, -- voc
	}
}

data['ā'] = {
	f = {{''}, {'o', 'u', ''}, -- nom
		 {'⌫aṃ'}, {'o', 'u', ''}, -- acc
		 {'e', 'i', 'a'}, {'hi', 'hiṃ'}, -- ins
		 {nil}, {nil}, -- dat
		 {'o', 'u'}, {'hiṃto'}, --abl
		 {'e', 'i', 'a'}, {'ṇa', 'ṇaṃ'}, -- gen
		 {'e', 'i', 'a'}, {'su', 'suṃ'}, -- loc
		 {'⌫e', ''}, {'o', 'u', ''}, --voc
	},
}

data['ā̈'] = data['ā']

data['i'] = {
	f = {{'⌫ī'}, {'⌫īo', '⌫ī'}, -- nom
		 {'⌫iṃ'}, {'⌫īo', '⌫ī'}, -- acc
		 {'⌫īe'}, {'⌫īhi', '⌫īhiṃ'}, -- ins
		 {nil}, {nil}, -- dat
		 {'⌫īo'}, {'⌫īhiṃto'}, --abl
		 {'⌫īe'}, {'⌫īṇa', '⌫īṇaṃ'}, -- gen
		 {'⌫īe'}, {'⌫īsu', '⌫īsuṃ'}, -- loc
		 {'⌫i', '⌫ī'}, {'⌫īo', '⌫ī'}, -- voc
	},
	m = {{'⌫ī'}, {'ṇo', '⌫ī', '⌫īo', '⌫ao', '⌫a-u'}, -- nom
		 {'ṃ'}, {'ṇo', '⌫ī', '⌫ao'}, -- acc
		 {'ṇā'}, {'⌫īhi', '⌫īhiṃ'}, -- ins
		 {nil}, {nil}, -- dat
		 {'⌫īo', '⌫īu', 'ṇo', '⌫īhiṃto'}, {nil}, --abl
		 {'ssa', 'ṇo'}, {'⌫īṇa', '⌫īṇaṃ'}, -- gen
		 {'mmi'}, {'⌫īsu', '⌫īsuṃ'}, -- loc
		 {'', '⌫ī'}, {'ṇo', '⌫ī'}, -- voc
	},
	n = {{'ṃ', ''}, {'⌫īiṃ', '⌫īṇi', '⌫ī'}, -- nom
		 {'ṃ', ''}, {'⌫īiṃ', '⌫īṇi', '⌫ī'}, -- acc
		 {'ṇā'}, {'⌫īhi', '⌫īhiṃ'}, -- ins
		 {nil}, {nil}, -- dat
		 {'⌫īo', '⌫īu', 'ṇo', '⌫īhiṃto'}, {nil}, --abl
		 {'ssa', 'ṇo'}, {'⌫īṇa', '⌫īṇaṃ'}, -- gen
		 {'mmi'}, {'⌫īsu', '⌫īsuṃ'}, -- loc
		 {'', '⌫ī'}, {'⌫īiṃ', '⌫īṇi', '⌫ī'}, -- voc
	},
}

data['ī'] = {
	f = {{''}, {'o', ''}, -- nom
		 {'⌫iṃ'}, {'o', ''}, -- acc
		 {'⌫īe'}, {'⌫īhi', '⌫īhiṃ'}, -- ins
		 {nil}, {nil}, -- dat
		 {'o'}, {'hiṃto'}, --abl
		 {'e'}, {'ṇa', 'ṇaṃ'}, -- gen
		 {'e'}, {'su', 'suṃ'}, -- loc
		 {'⌫i', ''}, {'o', ''}, -- voc
	},
}

data['u'] = {
	f = {{'⌫ū'}, {'⌫ūo', '⌫ū'}, -- nom
		 {'⌫uṃ'}, {'⌫ūo', ''}, -- acc
		 {'⌫ūe'}, {'⌫ūhi', '⌫ūhiṃ'}, -- ins
		 {nil}, {nil}, -- dat
		 {'⌫ūo'}, {'⌫ūhiṃto'}, --abl
		 {'⌫ūe'}, {'⌫ūṇa', '⌫ūṇaṃ'}, -- gen
		 {'⌫ūe'}, {'⌫ūsu', '⌫ūsuṃ'}, -- loc
		 {'⌫u', '⌫ū'}, {'⌫ūo', '⌫ū'}, -- voc
	},
	m = {{'⌫ū'}, {'ṇo', '⌫ū', '⌫ūo', '⌫ao', '⌫a-u'}, -- nom
		 {'ṃ'}, {'ṇo', '⌫ū'}, -- acc
		 {'ṇā'}, {'⌫ūhi', '⌫ūhiṃ'}, -- ins
		 {'⌫ūo', '⌫ūu'}, {nil}, -- dat
		 {nil}, {nil}, --abl
		 {'ṇo', 'ssa'}, {'⌫ūṇa', '⌫ūṇaṃ'}, -- gen
		 {'mmi'}, {'⌫ūsu', '⌫ūsuṃ'}, -- loc
		 {'', '⌫ū'}, {nil}, -- voc
	},
	n = {{'ṃ', ''}, {'⌫ūiṃ', '⌫ūṇi', '⌫ū'}, -- nom
		 {'ṃ', ''}, {'⌫ūiṃ', '⌫ūṇi', '⌫ū'}, -- acc
		 {'ṇā'}, {'⌫ūhi', '⌫ūhiṃ'}, -- ins
		 {'⌫ūo', '⌫ūu'}, {nil}, -- dat
		 {nil}, {nil}, --abl
		 {'ṇo', 'ssa'}, {'⌫ūṇa', '⌫ūṇaṃ'}, -- gen
		 {'mmi'}, {'⌫ūsu', '⌫ūsuṃ'}, -- loc
		 {'', '⌫ū'}, {'⌫ūiṃ', '⌫ūṇi', '⌫ū'}, -- voc
	},
}

data['ū'] = {
	f = {{''}, {'o', ''}, -- nom
		 {'⌫uṃ'}, {'o', ''}, -- acc
		 {'e'}, {'hi', 'hiṃ'}, -- ins
		 {nil}, {nil}, -- dat
		 {'o'}, {'hiṃto'}, --abl
		 {'e'}, {'ṇa', 'ṇaṃ'}, -- gen
		 {'e'}, {'su', 'suṃ'}, -- loc
		 {'⌫u', ''}, {'o', ''}, -- voc
	},
}
	local word_tr = lang:transliterate(word)
	local ending = ending(word_tr)
	if ending == '̈' then 
		ending = sub(word_tr, -2,-2) 
	end
	return data[ending][g], word_tr
end

function export.show(frame)
	local args = frame:getParent().args
	local g = args[1]
	local word = args[2] or PAGENAME
	local selected_data, word_tr = export.select(dialect, word, g)

	local output = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="background:#FEFEFE; text-align:center; border: 1px solid #CCC;"
|- style="background: #d9ebff;"
! class="vsToggleElement" style="text-align: left;" colspan="3" |Maharastri declension of ]=] .. word .. " (" .. genders[g] .. ")"

	output = output .. [=[

|- class="vsHide"
! style="background:#eff7ff" | 
! style="background:#eff7ff" | singular
! style="background:#eff7ff" | plural	
	]=]

	for i,v in ipairs(cases) do
		output = output .. "\n|- class=\"vsHide\"\n! style=\"background-color:#eff7ff;\" | " .. v
		output = output .. "\n| " .. export.joinSuffix(frame, word_tr, selected_data[2 * i - 1])
		output = output .. "\n| " .. export.joinSuffix(frame, word_tr, selected_data[2 * i])
	end

	output = output .. "\n|}"
	return output
end

return export