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

মডিউল:gem-decl-adj

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

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

local export = {}

local m_pron = require("Module:gem-pronunc")
local m_links = require("Module:links")
local m_utils = require("Module:utilities")

local lang = require("Module:languages").getByCode("gem-pro")

local i_muts = m_pron.i_mutations

local decl_data = require("Module:gem-decl-adj/data")
--local decl_data_irreg = require("Module:gem-decl-adj/data/irreg")

local endings = {
	["az"] = "a", ["iz"] = "i", ["ô"] = "an/in", ["uz"] = "u",
}

local endings_reverse = {
	["a"] = "az", ["i"] = "iz", ["an/in"] = "ô", ["u"] = "uz",
}

local function detect_decl(word, stem)
	if stem then
		return decl, {mw.ustring.sub(word, 1, -(mw.ustring.len(endings_reverse[stem]) + 1))}
	else
		for ending, decl in pairs(endings) do
			if mw.ustring.find(word, ending .. "$") then
				return decl, {mw.ustring.sub(word, 1, -(mw.ustring.len(ending) + 1))}
			end
		end
	end
end
		
	
local function add_asterisks(forms, data)
	for _, form in ipairs(forms) do
		for i, subform in ipairs(data.forms[form]) do
			data.forms[form][i] = "*" .. subform
		end
	end
end

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local parent_args = frame:getParent().args
	if mw.title.getCurrentTitle().nsText ~= "Reconstruction" then return end
	
	local stems = nil
	local decl_type = {}
	local word = mw.title.getCurrentTitle().subpageText
	local args = {}

--	if not decl_data_irreg[word] then
		if frame.args.decl then
			decl_type = frame.args.decl
		else
			if parent_args.stem and parent_args[1] then
				decl_type = parent_args.stem
				stems = {parent_args[1]}
			else
				decl_type, stems = detect_decl(word, parent_args.stem)
			end
		end
		
		if not decl_type then
			error("Unknown declension '" .. decl_type .. "'")
		end
		
		args = require("Module:parameters").process(parent_args, decl_data[decl_type].params, true)
	
		if stems then
			for i, stem in ipairs(stems) do
				args[i] = stem
			end
		end
--	end

	local data = {forms = {}, categories = {}}
	
	data.head = parent_args["head"] or nil
	
	-- Generate the forms
	decl_data[decl_type](args, data)

	-- Make the table
	return make_table(data)
end

local function show_form(form)
	if not form then
		return "—"
	end
	
	local ret = {}
	
	for key, subform in ipairs(form) do
		if mw.ustring.find(subform, "[iīįǐj]") or mw.ustring.find(subform, "e[mn]") then
			subform = i_muts(subform)
		end
		if subform ~= "—" then
			subform = "*" .. subform
		end
		table.insert(ret, subform)
	end
		
	return table.concat(ret, ", ")
end

local function make_caseline(data, prefix)
	local line = {"sg_m", "sg_f", "sg_n", "pl_m", "pl_f", "pl_n"}
	local ret = {}
	for _, lineform in ipairs(line) do
		table.insert(ret, "| " .. show_form(data.forms[prefix .. "_" .. lineform]) .. "\n")
	end
	return table.concat(ret)
end

local function make_inner_table(data, tcode, str_or_wk)
	table.insert(tcode, '! colspan="999" | ' .. (str_or_wk == "s_" and "Strong" or "Weak") .. [=[ declension
|-
! class="outer" |
! class="outer" colspan="3" | singular
| class="separator" rowspan="7" |
! class="outer" colspan="3" | plural
|-
! 
! masculine
! feminine
! neuter
! masculine
! feminine
! neuter
|-
! [[Appendix:Glossary#nominative case|nominative]]
]=])
	table.insert(tcode, make_caseline(data, str_or_wk .. "nom"))
	table.insert(tcode, '|-\n! [[Appendix:Glossary#accusative case|accusative]]\n')
	table.insert(tcode, make_caseline(data, str_or_wk .. "acc"))
	table.insert(tcode, '|-\n! [[Appendix:Glossary#genitive case|genitive]]\n')
	table.insert(tcode, make_caseline(data, str_or_wk .. "gen"))
	table.insert(tcode, '|-\n! [[Appendix:Glossary#dative case|dative]]\n')
	table.insert(tcode, make_caseline(data, str_or_wk .. "dat"))
	table.insert(tcode, '|-\n! [[Appendix:Glossary#instrumental case|instrumental]]\n')
	table.insert(tcode, make_caseline(data, str_or_wk .. "ins"))
end


function make_table(data)
	local pagename = mw.title.getCurrentTitle().subpageText
	local wikicode = {}
	
	table.insert(wikicode, mw.getCurrentFrame():expandTemplate{
		title = 'inflection-table-top',
		args = {
			title = "Declension of ''*" .. pagename .. "'' (" .. data.decl_type .. ")",
			palette = 'orange',
			tall = 'yes',
		}
	})

	if not decl_data.weak_only[pagename] then
		make_inner_table(data, wikicode, "s_")
		if not decl_data.strong_only[pagename] then
			table.insert(wikicode, '|-\n| class="separator" colspan="999" |\n|-\n')
		end
	end
	if not decl_data.strong_only[pagename] then
		make_inner_table(data, wikicode, "w_")
	end
	
	table.insert(wikicode, mw.getCurrentFrame():expandTemplate{ title = 'inflection-table-bottom' })

	return table.concat(wikicode) .. m_utils.format_categories(data.categories, lang)
end

return export