မာတိကာသို့ ခုန်သွားရန်

မဝ်ဂျူ:bar-headword

နူ ဝိက်ရှေန်နရဳ
ထာမ်ပလိက်တဏအ်ဒးနွံကဵုလိက်စၟတ်သမ္တီမချူလဝ်သာဓက။
သ္ပဂုန်တုဲထာမ်ပလိက်တဏအ်ဒးစၟတ်သမ္တီကဵုလိက်မချူလဝ်နူကဵုဓမံက်ထ္ၜးကဵုဗီုပြၚ်ကိစ္စမရန်တၟအ်လဝ် ကဵု ပရေၚ်မရပ်စပ်လ္တူမုက်လိက်နကဵုလိက်စၟတ်သမ္တီမချူလဝ်သာဓက

local export = {}
local pos_functions = {}

local lang = require("Module:languages").getByCode("bar")
local script = require('Module:scripts').getByCode("Latn")

-- If Not Empty
local function ine(arg)
	if arg == "" then
		return nil
	else
		return arg
	end
end

local function list_to_set(list)
	local set = {}
	for _, item in ipairs(list) do
		set[item] = true
	end
	return set
end

local function append_cat(data, pos)
	table.insert(data.categories, pos ..lang:getCanonicalName() .. "ဂမၠိုင်")
end

local function handle_infl(args, data, argpref, label)
	if args[argpref] and args[argpref..'2'] then
		local forms = {}
		local form = argpref
		local i = 1
		while args[form] do
			table.insert (forms, args[form])
			i = i + 1
			form = argpref..i
		end
		forms.label = mw.ustring.gsub(label, 'form', 'forms')
		table.insert(data.inflections, forms )
	elseif args[argpref] then
		table.insert(data.inflections, { label = label, args[argpref]})
	end
end

function export.show(frame)

	local args = frame:getParent().args
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	poscat = string.gsub(poscat, 'form', 'forms')
	local data = {lang = lang, sc = script, pos_category = poscat, categories = {}, heads = {args["head"] or PAGENAME}, genders = {}, inflections = {}, sort_key = args["sort"]}
	
	if poscat == 'နာမ်' then
		if ine(args[1]) then
			args['g'] = args[1]
		end
		if ine(args[2]) then
			args['pl'] = args[2]
		end
		if ine(args[3]) then
			args['gen'] = args[3]
		end
	end
	
	if args["cat2"] then

	end
	if args["cat3"] then
	
	end
	
	handle_infl(args, data, "stem", "stem")
	
	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end
	
	return require("Module:headword").full_headword(data)
end

local valid_genders = list_to_set(
		{ "m", "m-p",
		  "f", "f-p",
		  "n", "n-p"
		})

local function handle_gender(args, data, default, nonlemma, optional)

	local g = ine(args["g"]) or default
	local g2 = ine(args["g2"])

	local function process_gender(gender)
		if not gender and not optional then
			table.insert(data.genders, "?")
		elseif not gender and optional then
			-- do nothing
		elseif valid_genders[g] then
			table.insert(data.genders, gender)
		else
			error("Unrecognized gender: " .. gender)
		end
	end

	process_gender(g)
	if g2 then
		process_gender(g2)
	end

	if nonlemma then
		return
	end

	if g and g2 then
		
	end
end

local function is_masc_sg(g)
	return g == "m" or g == "m-p"
end
local function is_fem_sg(g)
	return g == "f" or g == "f-p"
end
local function is_neut_sg(g)
	return g == "n" or g == "n-p"
end


pos_functions["နာမဝိသေသန"] = function(args, data)
	handle_infl(args, data, "cp", "သဒ္ဒာ")
	handle_infl(args, data, "sup", "သဒ္ဒာ")
end

pos_functions["articles"] = function(args, data)
	handle_gender(args, data)
	handle_infl(args, data, "acc", "accusative")
	handle_infl(args, data, "dat", "dative")
end

pos_functions["နာမ်"] = function(args, data)
	handle_gender(args, data)
	handle_infl(args, data, "gen", "ဗဳဇဂကူ")
	handle_infl(args, data, "pl", "ကိုန်ဨကဝုစ်")
	handle_infl(args, data, "f", "ဣတ္တိလိင်")
	
	local g = ine(args["g"]) or default
	local g2 = ine(args["g2"])

		if is_masc_sg(g) or is_masc_sg(g2) then
			append_cat(data, "နာမ်ပုလ္လိင်")
		elseif is_fem_sg(g) or is_fem_sg(g2) then
			append_cat(data, "နာမ်ဣတ္တိလိင်")
		elseif is_neut_sg(g) or is_neut_sg(g2) then
			append_cat(data, "နာမ်နပုလ္လိင်")
		end
end

pos_functions["သဗ္ဗနာမ်"] = function(args, data)
	handle_infl(args, data, "pl", "plural")
end

pos_functions["ကြိယာ"] = function(args, data)
	handle_infl(args, data, "pp", "past participle")
	handle_infl(args, data, "past", "3rd person singular past")
	if ine(args['past']) then
		handle_infl(args, data, "subj", "subjunctive")
	else
		handle_infl(args, data, "subj", "3rd person singular subjunctive")
	end
end

return export