မဝ်ဂျူ:io-headword

နူ ဝိက်ရှေန်နရဳ

Documentation for this module may be created at မဝ်ဂျူ:io-headword/doc

local export = {}
local pos_functions = {}

local PAGENAME = mw.title.getCurrentTitle().text 
local lang = require("Module:languages").getByCode("io")
local except = require("Module:io-headword/exceptions")
local participle_pattern = "[aio]n?t[aeo]?$"

local function monosyllabic(word)
	local _, n = mw.ustring.gsub(word, "[AEIOUaeiou]", "")
	return n == 1
end

local function check(data, tracking_categories)
	
	
	for _,entry in ipairs(data.check) do
		local t = mw.title.new(entry)
		if t and not t.exists then
			table.insert(tracking_categories, catname)
		end
	end
end

local function getPOS(word)
	-- delete anything after "de"
	word = mw.ustring.gsub(word, " de .+$", "")
	
	-- deal with letters
	if mw.ustring.match(word,"^[aeiou]$") or mw.ustring.match(word,"^[bcdefghijklmnoprstuvwxyz]o$") then
		return "နာမ်"
	end
	
	-- deal with some exceptions
	if except[word] then
		return except[word]
	end
	
	-- Words with only one vowel are always irregular
	if monosyllabic(word) then
		return nil
	elseif word:find(participle_pattern) then -- detect this firstly
		return "လုပ်ကၠောန်စွံလဝ်"
	elseif word:find("a$") then
		return "နာမဝိသေသန"
	elseif word:find("e$") then
		return "ကြိယာဝိသေသန"
	elseif word:find("u$") then
		return "သဗ္ဗနာမ်"
	elseif word:find("o$") then
		if mw.ustring.find(word, "^%u") then
			return "နာမ်မကိတ်ညဳ"
		else
			return "နာမ်"
		end
	elseif word:find("i$") then
		if mw.ustring.find(word, "^%u") then
			return "ဗီုပြင်နာမ်မကိတ်ညဳ"
		else
			return "ဗီုပြင်နာမ်"
		end
	elseif word:find("ar$") then
		return "ကြိယာ"
	elseif word:find("[iaou]s$") or word:find("ez$") then
		return "ဗီုပြင်ကြိယာ"
	else
		return nil
	end
end

-- The main entry point
function export.show(frame)
	local tracking_categories = {}
	
	local poscat = frame:getParent().args["pos"] or frame.args["poscat"] or getPOS(PAGENAME)
	
	if not poscat then
		if mw.title.getCurrentTitle().nsText == "Template" then
			poscat = "နာမ်"
		else
			error("Part of speech of \"" .. PAGENAME .. "\" cannot be automatically determined.")
		end
	end
	
	local params = {
		["head"] = {list = true, default = ""},
		["pos"] = {},
		["suff"] = {type = "boolean"},
	}
	
	if pos_functions[poscat] then
		for key, val in pairs(pos_functions[poscat].params) do
			params[key] = val
		end
	end
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = poscat, categories = {}, heads = args["head"], genders = {}, inflections = {}, check = {}}
	
	if pos_functions[poscat] then
		pos_functions[poscat].func(args, data)
	end
	
	check(data, tracking_categories)
	
	return require("Module:headword").full_headword(data) .. require("Module:utilities").format_categories(tracking_categories, lang)
end

pos_functions["determiners"] = {
	params = {
	},
	func = function(args, data)
		table.insert(data.inflections, {label = "ကိုန်ဗဟုဝစ်", accel = {form = "p"}, PAGENAME .. "i"})
		table.insert(data.check, PAGENAME .. "i")
	end
}

pos_functions["နာမ်"] = {
	params = {
		[1] = {list = true, allow_holes = true},
	},
	func = function(args, data)
		local stem = PAGENAME:sub(1, -2)
		-- Get the parameters
		local inflected_words_specified = false
		local inflected_words = {}
		
		for i = 1, args[1].maxindex do
			local word = args[1][i]
			
			if word == "+" or word == "-" then
				word = nil
			end
			
			if word then
				inflected_words[word] = true
				inflected_words_specified = true
			end
		end
		
		local pl = {}

		-- Split multi-word terms
		for word in mw.text.gsplit(PAGENAME, " ", true) do
			local pos = getPOS(word)
			
			-- Inflect each word separately
			if (not inflected_words_specified or inflected_words[word]) and (pos == "နာမဝိသေသန" or pos == "နာမ်" or pos == "နာမ်မကိတ်ညဳ") then
				local is_letter = ""
				if mw.ustring.match(word,"^[aeiou]$") or mw.ustring.match(word,"^[bcdefghijklmnoprstuvwxyz]o$")then
					is_letter = "-o"
				end
				table.insert(pl, stem .. "i")
			else
				table.insert(pl, word)
			end
		end
		
		-- Merge back together
		pl = table.concat(pl, " ")

		local pl2
		
		if args[1][1] == "-" then
			table.insert(data.inflections, {label = "[[Appendix:Glossary#uncountable|တော်ဟွံမာန်]]"})
			
		else
			table.insert(data.inflections, {label = "ကိုန်ဗဟုဝစ်", accel = {form = "p"}, pl, pl2})
			table.insert(data.check, pl)
		end
	end
}

pos_functions["နာမ်မကိတ်ညဳ"] = {
	params = {
		[1] = {list = true, allow_holes = true},
	},
	func = function(args, data)
		-- Get the parameters
		local inflected_words_specified = false
		local inflected_words = {}
		
		for i = 1, args[1].maxindex do
			local word = args[1][i]
			
			if word == "+" or word == "-" then
				word = nil
			end
			
			if word then
				inflected_words[word] = true
				inflected_words_specified = true
			end
		end
		
		local pl = {}

		local de = false
		
		-- Split multi-word terms
		for word in mw.text.gsplit(PAGENAME, " ", true) do
			local pos = getPOS(word)
			
			if word == "de" then de = true end
			
			-- Inflect each word separately
			if (not inflected_words_specified or inflected_words[word]) and (pos == "နာမဝိသေသန" or pos == "နာမ်" or pos == "နာမ်မကိတ်ညဳ" or mw.ustring.match(word,'[aio]$') and not monosyllabic(word)) and not de then
				table.insert(pl, word .. "i")
			else
				table.insert(pl, word)
			end
		end
		
		-- Merge back together
		pl = table.concat(pl, " ")

		if args[1][1] == "+" then
			table.insert(data.inflections, {label = "ကိုန်ဗဟုဝစ်", accel = {form = "p"}, pl})
			table.insert(data.check, pl)
		else
		end
	end
}

pos_functions["ကြိယာ"] = {
	params = {
	},
	func = function(args, data)
		local stem = PAGENAME:sub(1, -3)
		
		table.insert(data.inflections, {label = "ပစ္စုပ္ပန်", stem .. "as"})
		table.insert(data.inflections, {label = "အတိတ်", stem .. "is"})
		table.insert(data.inflections, {label = "အနာဂတ်", stem .. "os"})
		table.insert(data.inflections, {label = "မနွံအကာဲအရာဗွဲတၟေၚ်", stem .. "us"})
		table.insert(data.inflections, {label = "မနွံကဵုပၟိက်အကာဲအရာ", stem .. "ez"})
	end
}

pos_functions["ဗီုပြင်နာမ်"] = {
	params = {
		[1] = {},
	},
	func = function(args, data)
		if args[1] == "p" or args[1] == "p+" then
			table.insert(data.genders, "p")
			data.categories = {"နာမ် ဣဒဝ်"}
			if args[1] == "p+" then
				local singular = mw.ustring.gsub(PAGENAME, "i$", "")
				table.insert(data.inflections, {label = "ကိုန်ဨကဝုစ်", singular})
				table.insert(data.check, singular)
			end
		end
	end
}

pos_functions["pluralia tantum"] = {
	params = {
		[1] = {},
	},
	func = function(args, data)
		table.insert(data.categories, 1, "နာမ် ဣဒဝ်")
		if args[1] == "+" then
			local singular = mw.ustring.gsub(PAGENAME, "i$", "")
			table.insert(data.inflections, {label = "ကိုန်ဨကဝုစ်", singular})
			table.insert(data.check, singular)
		end
	end
}

pos_functions["လုပ်ကၠောန်စွံလဝ်"] = {
	params = {
		[1] = {}, [2] = {}, --these will be phased out
	},
	func = function(args, data)
		local ending = mw.ustring.match(PAGENAME, participle_pattern)
		if ending then
			local vowel, consonant = ending:match("([aeio])$")
			if consonant == "" then
				if vowel == "a" or vowel == "o" then
					table.insert(data.inflections, {label = "ကိုန်ဗဟုဝစ်", PAGENAME .. "j"})
					table.insert(data.check, PAGENAME .. "i")
				elseif vowel == "e" then
					
				end
			elseif vowel == "e" then
				error("-e" .. consonant .. " is not a valid participle ending!")
			end
			if vowel == "a" then
				
			elseif vowel == "o" then
				
			end
		else
			error("This term is not a participle!")
		end
	end
}

return export