বিষয়বস্তুতে চলুন

মডিউল:ta-decl

উইকিঅভিধান, মুক্ত অভিধান থেকে

এই মডিউলের জন্য মডিউল:ta-decl/নথি-এ নথিপত্র তৈরি করা হয়ে থাকতে পারে

local export = {}
local m_translit = require("Module:ta-translit")
local m_tamil = require("Module:ta-conj")

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

local long_vowels = {
	['ா']= 'ā' , ['ீ']='ī' , ['ூ']='ū' ,
	['ே']='ē' , ['ோ']='ō' 
}

-- Clone parent’s args while also assigning nil to empty strings.
local function clone_args(frame)
	local args = {}
	for pname, param in pairs(frame:getParent().args) do
		if param == "" then args[pname] = nil
		else args[pname] = param
		end
	end
	return args
end

function export.do_generate_forms(args)
	local data = {}

	local base = args[1] or ""
	local PAGENAME = mw.title.getCurrentTitle().text
	if base == "" then
		base = PAGENAME
	end
	
	local type_stem = args.type
	data.type_stem = ""
	
	local oblique_sg_base = ""
	local plu_base = ""
	local special_vocative = nil
	
	oblique_sg_base = base -- default
	plu_base = m_tamil.agglutinate(base, 'கள்', {}) -- default
	if (type_stem == "root" or type_stem == "basic" or type_stem == "none") then
		-- do nothing
		data.type_stem = "root-stem"
	elseif (type_stem == "m" or (type_stem == nil and sub(base, -2) == 'ம்')) then
		data.type_stem = "m-stem, ம்-த்து-ங்-altering"
		oblique_sg_base = sub(base, 1, -3) .. 'த்து'
	elseif (type_stem == "i" or (type_stem == nil and sub(base, -1) == 'ி')) then
		data.type_stem = "i-stem, இ-throughout"
	elseif (type_stem == "ai" or (type_stem == nil and sub(base, -1) == 'ை')) then
		data.type_stem = "ai-stem, ஐ-throughout"
	elseif (type_stem == "y" or (type_stem == nil and sub(base, -2) == 'ய்')) then
		data.type_stem = "y-stem, ய்-throughout"
	elseif (type_stem == "ā" or (type_stem == nil and sub(base, -1) == 'ா')) then
		data.type_stem = "ā-stem, ஆ-throughout"
		plu_base = m_tamil.agglutinate(base, 'க்கள்', {})
	elseif (type_stem == "ī" or (type_stem == nil and sub(base, -1) == "ீ")) then
		data.type_stem = "ī-stem, ஈ-throughout"
		plu_base = m_tamil.agglutinate(base, 'க்கள்', {})
	elseif (type_stem == "ṟu" or (type_stem == nil and sub(base, -2) == "று" and sub(base, 3) ~= "ற்று")) then
		data.type_stem = "ṟu-stem, று-ற்று-altering"
		oblique_sg_base = sub(base, 1, -3) .. 'ற்று'
	elseif (type_stem == "ṭu" or (type_stem == nil and sub(base, -2) == "டு" and sub(base, 3) ~= "ட்டு")) then
		data.type_stem = "ṭu-stem, டு-ட்டு-altering"
		oblique_sg_base = sub(base, 1, -3) .. 'ட்டு'
	elseif (type_stem == "u" or (type_stem == nil and sub(base, -1) == 'ு')) then
		data.type_stem = "u-stem, உ deleted in oblique singular"
	elseif (type_stem == "l" or (type_stem == nil and sub(base, -2) == "ல்")) then
		data.type_stem = "l-stem, ல்-ல்லு-ற்-altering"
		special_vocative = base .. 'லே'
		oblique_sg_base = base .. 'லு'
		plu_base = sub(base, 1, -3) .. 'ற்கள்'
	elseif (type_stem == "ṉ" or (type_stem == nil and sub(base, -2) == "ன்")) then
		data.type_stem = "ṉ-stem, ன்-ர்-altering"
		oblique_sg_base = sub(base, 1, -3) .. 'னு'
		plu_base = sub(base, 1, -3) .. "ர்கள்"
	elseif (type_stem == "ū" or (type_stem == nil and sub(base, -1) == "ூ")) then
		data.type_stem = "ū-stem, ஊ-throughout"
		oblique_sg_base = base .. "வு"
		plu_base = base .. 'க்கள்'
	elseif (type_stem == "ḷ" or (type_stem == nil and sub(base, -2) == "ள்")) then
		data.type_stem = "ḷ-stem, ள்-ட்-altering"
		oblique_sg_base = sub(base, 1, -3) .. 'ளு'
		plu_base = m_tamil.agglutinate(sub(base, 1, -3), 'ட்கள்', {})
	else
		data.type_stem = "root-stem"
	end

	if ((args.oblique_sg_base or args[4]) and (args.plu_base or args[2])) then
		oblique_sg_base = args.oblique_sg_base or args[4]
		plu_base = args.plu_base or args[2]
	end
	
	data.nom_sg = base
	data.voc_sg = args.voc_s or args[3] or special_vocative or m_tamil.agglutinate(base, "ஏ", {["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true })
	-- mw.log(oblique_sg_base)
	data.acc_sg = args.acc_s or m_tamil.agglutinate(oblique_sg_base, 'ஐ', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true })
	data.dat_sg = args.dat_s or m_tamil.agglutinate(oblique_sg_base, 'க்கு', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true  })
	data.dat_sg_2 = args.ben_s or m_tamil.agglutinate(oblique_sg_base, 'க்காக', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true  })
	if (data.type_stem == "root-stem") then
		if not args.dat_s then
			data.dat_sg = m_tamil.agglutinate(oblique_sg_base, 'உக்கு', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true  })
		end
		if not args.ben_s then
			data.dat_sg_2 = m_tamil.agglutinate(oblique_sg_base, 'உக்காக', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true  })
		end
	end
	data.gen_sg = args.gen_s or m_tamil.agglutinate(oblique_sg_base, 'உடைய', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true  })
	data.gen_sg_2 = args.gen2_s or m_tamil.agglutinate(oblique_sg_base, 'இன்', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true  })
	data.loc_sg = args.loc_s or m_tamil.agglutinate(oblique_sg_base, 'இல்', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true  })
	data.loc_sg_2 = args.loc2_s or m_tamil.agglutinate(oblique_sg_base, 'இடம்', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true  })
	data.soc_sg = args.soc_s or m_tamil.agglutinate(oblique_sg_base, 'ஓடு', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true  })
	data.soc_sg_2 = args.soc2_s or m_tamil.agglutinate(oblique_sg_base, 'உடன்', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true })
	data.ins_sg = args.ins_s or m_tamil.agglutinate(oblique_sg_base, 'ஆல்', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true })
	data.abl_sg = args.abl_s or m_tamil.agglutinate(oblique_sg_base, 'இலிருந்து', {["delete_final_a"] = true, ["delete_final_u"] = true, [ "do_not_duplicate_nasals"] = true, [ "do_not_duplicate_laterals"] = true  })
	
	data.nom_pl = plu_base
	data.voc_pl = args.voc_p or m_tamil.agglutinate(plu_base, 'ஏ', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.acc_pl = args.acc_p or m_tamil.agglutinate(plu_base, 'ஐ', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.dat_pl = args.dat_p or m_tamil.agglutinate(plu_base, 'உக்கு', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.dat_pl_2 = args.ben_p or m_tamil.agglutinate(plu_base, 'உக்காக', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.gen_pl = args.gen_p or m_tamil.agglutinate(plu_base, 'உடைய', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.gen_pl_2 = args.gen2_p or m_tamil.agglutinate(plu_base, 'இன்', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.loc_pl = args.loc_p or m_tamil.agglutinate(plu_base, 'இல்', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.loc_pl_2 = args.loc2_p or m_tamil.agglutinate(plu_base, 'இடம்', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.soc_pl = args.soc_p or m_tamil.agglutinate(plu_base, 'ஓடு', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.soc_pl_2 = args.soc2_p or m_tamil.agglutinate(plu_base, 'உடன்', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.ins_pl = args.ins_p or m_tamil.agglutinate(plu_base, 'ஆல்', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	data.abl_pl = args.abl_p or m_tamil.agglutinate(plu_base, 'இலிருந்து', {["delete_final_a"] = true, [ "do_not_duplicate_laterals"] = true })
	
	if (args.num == "sg") or args[2] == "-" then
		if (data.type_stem == "" or data.type_stem == "root-stem") then 
			data.type_stem = "singular only"
		else 
			data.type_stem = data.type_stem .. ", singular only"
		end
		data.nom_pl = "-"
		data.voc_pl = "-"
		data.acc_pl = "-"
		data.dat_pl = "-"
		data.dat_pl_2 = "-"
		data.gen_pl = "-"
		data.gen_pl_2 = "-"
		data.loc_pl = "-"
		data.loc_pl_2 = "-"
		data.soc_pl = "-"
		data.soc_pl_2 = "-"
		data.ins_pl = "-"
		data.abl_pl = "-"
	elseif (args.num == "pl") then 
		if (data.type_stem == "" or data.type_stem == "root-stem") then 
			data.type_stem = "plural only"
		else 
			data.type_stem = data.type_stem .. ", plural only"
		end
		data.nom_sg = "-"
		data.voc_sg = "-"
		data.acc_sg = "-"
		data.dat_sg = "-"
		data.dat_sg_2 = "-"
		data.gen_sg = "-"
		data.gen_sg_2 = "-"
		data.loc_sg = "-"
		data.loc_sg_2 = "-"
		data.soc_sg = "-"
		data.soc_sg_2 = "-"
		data.ins_sg = "-"
		data.abl_sg = "-"
	end
	
	local data_type = data.type_stem
	for k, v in pairs(data) do
		if type(v) == "table" then
			for k1, v1 in pairs(v) do
				if (v1 ~= "-") then
					data[k][k1] = '<span class="Taml">[[' .. v1 .. ']]</span> ' .. ' <br/><small style="color: #888">' .. m_translit.tr(v1) .. '</small>'
				end
			end
		else
			if (v ~= "-") then
				data[k] = '<span class="Taml">[[' .. v .. ']]</span>' .. ' <br/><small style="color: #888">' .. m_translit.tr(v) .. '</small>'
			end
		end
	end
	data.base = base .. ' (' .. m_translit.tr(base) .. ')'
	data.type_stem = data_type
	
	return data
end

function export.show(frame)
	local args = clone_args(frame)
	local data = export.do_generate_forms(args)
	
	local type_stem_info = ""
	if (data.type_stem ~= "" and data.type_stem ~= "root-stem") then
		type_stem_info = ' <small>(' .. data.type_stem .. ')</small>'
	end
	
	if (args.notes) then
		if (data.type_stem == "") then 
			data.type_stem = args.notes
		else 
			data.type_stem = data.type_stem .. ", " .. args.notes
		end
	end
	
	local res = {'{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="background:#FEFEFE; text-align:center; border: 1px solid #CCC;"'}
	table.insert(res, '|- style="background: #d9ebff;"')
	table.insert(res, '! class="vsToggleElement" style="text-align: left;" colspan="3" | Declension of ' .. data.base .. type_stem_info)
	table.insert(res, '|- class="vsShow"')
	table.insert(res, '! style="background:#eff7ff; width: 7em;" | ')
	table.insert(res, '! style="background:#eff7ff; width: 10em;" | একবচন')
	table.insert(res, '! style="background:#eff7ff; width: 10em;" | বহুবচন')
	table.insert(res, '|- class="vsShow"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| কর্তৃকারক') 
	table.insert(res, '| ' .. data.nom_sg)
	table.insert(res, '| ' .. data.nom_pl)
	table.insert(res, '|- class="vsShow"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| Vocative') 
	table.insert(res, '| ' .. data.voc_sg)
	table.insert(res, '| ' .. data.voc_pl)
	table.insert(res, '|- class="vsShow"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| কর্মকারক') 
	table.insert(res, '| ' .. data.acc_sg)
	table.insert(res, '| ' .. data.acc_pl)
	table.insert(res, '|- class="vsShow"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| সম্প্রদান কারক') 
	table.insert(res, '| ' .. data.dat_sg)
	table.insert(res, '| ' .. data.dat_pl)
	table.insert(res, '|- class="vsShow"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| সম্বন্ধ পদ') 
	table.insert(res, '| ' .. data.gen_sg)
	table.insert(res, '| ' .. data.gen_pl)
	
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '! style="background:#eff7ff; width: 7em;" | ')
	table.insert(res, '! style="background:#eff7ff; width: 10em;" | একবচন') 
	table.insert(res, '! style="background:#eff7ff; width: 10em;" | বহুবচন') 
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| কর্তৃকারক') 
	table.insert(res, '| ' .. data.nom_sg)
	table.insert(res, '| ' .. data.nom_pl)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| Vocative') 
	table.insert(res, '| ' .. data.voc_sg)
	table.insert(res, '| ' .. data.voc_pl)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| কর্মকারক') 
	table.insert(res, '| ' .. data.acc_sg)
	table.insert(res, '| ' .. data.acc_pl)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| সম্প্রদান কারক') 
	table.insert(res, '| ' .. data.dat_sg)
	table.insert(res, '| ' .. data.dat_pl)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| Benefactive') 
	table.insert(res, '| ' .. data.dat_sg_2)
	table.insert(res, '| ' .. data.dat_pl_2)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| সম্বন্ধ পদ ১') 
	table.insert(res, '| ' .. data.gen_sg)
	table.insert(res, '| ' .. data.gen_pl)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| সম্বন্ধ পদ ২') 
	table.insert(res, '| ' .. data.gen_sg_2)
	table.insert(res, '| ' .. data.gen_pl_2)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| অধিকরণ কারক ১') 
	table.insert(res, '| ' .. data.loc_sg)
	table.insert(res, '| ' .. data.loc_pl)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| অধিকরণ কারক ২') 
	table.insert(res, '| ' .. data.loc_sg_2)
	table.insert(res, '| ' .. data.loc_pl_2)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| Sociative ১') 
	table.insert(res, '| ' .. data.soc_sg)
	table.insert(res, '| ' .. data.soc_pl)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| Sociative ২') 
	table.insert(res, '| ' .. data.soc_sg_2)
	table.insert(res, '| ' .. data.soc_pl_2)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| করণ কারক') 
	table.insert(res, '| ' .. data.ins_sg)
	table.insert(res, '| ' .. data.ins_pl)
	table.insert(res, '|- class="vsHide"')
	table.insert(res, '!style="background:#eff7ff; width: 5em"| অপাদান কারক') 
	table.insert(res, '| ' .. data.abl_sg)
	table.insert(res, '| ' .. data.abl_pl)
	table.insert(res, '|}')
	
	return table.concat(res, "\n")
end

return export