မဝ်ဂျူ:ine-headword

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

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

local export = {}
local pos_functions = {}

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

-- The main entry point.
-- This is the only function that can be invoked from a template.
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.")
	
	local data = {lang = lang, pos_category = poscat, categories = {}, heads = {}, inflections = {}}
	
	local head = args["head"] or ""
	local i = 1
	
	while head do
		if head then
			table.insert(data.heads, head)
		end
		
		i = i + 1
		head = args["head" .. i]; if head == "" then head = nil end
	end
	
	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end
	
	return require("Module:headword").full_headword(data)
end

local consonants = {
	["p"] = "C",
	["t"] = "C",
	["ḱ"] = "C",
	["k"] = "C",
	["kʷ"] = "C",
	
	["b"] = "C",
	["d"] = "C",
	["ǵ"] = "C",
	["g"] = "C",
	["gʷ"] = "C",
	
	["bʰ"] = "C",
	["dʰ"] = "C",
	["ǵʰ"] = "C",
	["gʰ"] = "C",
	["gʷʰ"] = "C",
	
	["s"] = "š",  -- Placeholder symbol
	
	["w"] = "ṁ",  -- Placeholder symbol
	["m"] = "ṁ",  -- Placeholder symbol
	
	["y"] = "R",
	["l"] = "R",
	["r"] = "R",
	["n"] = "R",
	
	["h₁"] = "H",
	["h₂"] = "H",
	["h₃"] = "H",
	["H"] = "H",
}

local function split(rest)
	local ret = {}
	
	while mw.ustring.len(rest) > 0 do
		local longestmatch = ""
		
		for cons, _ in pairs(consonants) do
			if mw.ustring.len(cons) > mw.ustring.len(longestmatch) and mw.ustring.sub(rest, 1, mw.ustring.len(cons)) == cons then
				longestmatch = cons
			end
		end
		
		if mw.ustring.len(longestmatch) == 0 then
			return nil
		end
		
		table.insert(ret, consonants[longestmatch])
		rest = mw.ustring.sub(rest, mw.ustring.len(longestmatch) + 1)
	end
	
	return ret
end

local function get_root_shape(root)
	root = mw.ustring.gsub(root, "[()⁽⁾]", "")
	root = mw.ustring.gsub(root, "-$", "")
	local onset, coda = mw.ustring.match(root, "([^e]+)e([^e]+)")
	
	if not onset then
		return nil
	end
	
	onset = split(onset)
	coda = split(coda)
	
	if not onset or not coda then
		return nil
	end
	
	onset = table.concat(onset)
	coda = table.concat(coda)
	
	onset = mw.ustring.gsub(onset, "ṁR", "MR")
	onset = mw.ustring.gsub(onset, "ṁ", "R")
	coda = mw.ustring.gsub(coda, "ṁ", "R")
	
	onset = mw.ustring.gsub(onset, "šC", "sC")
	onset = mw.ustring.gsub(onset, "Cš", "Cs")
	onset = mw.ustring.gsub(onset, "š", "C")
	
	coda = mw.ustring.gsub(coda, "šC", "sC")
	coda = mw.ustring.gsub(coda, "Cš", "Cs")
	coda = mw.ustring.gsub(coda, "š", "C")
	
	if not (
		onset == "C" or
		onset == "CH" or
		onset == "CR" or
		
		onset == "H" or
		onset == "HC" or
		onset == "HR" or
		
		onset == "R" or
		onset == "MR" or
		
		onset == "sC" or
		onset == "sCR") then
		return nil
	end
	
	if not (
		coda == "C" or
		coda == "HC" or
		coda == "RHC" or
		coda == "RC" or
		coda == "HRC" or
		coda == "sC" or
		coda == "RsC" or
		
		coda == "H" or
		coda == "CH" or
		coda == "RCH" or
		coda == "RH" or
		
		coda == "R" or
		coda == "HR" or
		
		coda == "Cs") then
		return nil
	end
	
	return onset .. "e" .. coda
end

pos_functions["တံရိုဟ်"] = function(args, data)
	local repr = get_root_shape(mw.title.getCurrentTitle().subpageText)
	
	if repr then
		
	else
		
	end
	
	if mw.ustring.find(mw.title.getCurrentTitle().subpageText, "^%(s%)") then
		
	end
	
	local aspect = args[1]; if aspect == "" then aspect = nil end
	
	if aspect == "impf" then
		table.insert(data.inflections, {label = "imperfective"})
		
	elseif aspect == "pf" then
		table.insert(data.inflections, {label = "perfective"})
		
	elseif aspect == "stat" then
		table.insert(data.inflections, {label = "stative"})
		
	elseif aspect == "noun" or aspect == "nom" then
		table.insert(data.inflections, {label = "nominal"})
		
	elseif aspect == "adj" then
		table.insert(data.inflections, {label = "adjectival"})
		
	elseif aspect then
		error("Invalid aspect")
	end
end

return export