မော်ဂျူး:ko-headword

ဝစ်ရှင်နရီ မှ

Documentation for this module may be created at မော်ဂျူး:ko-headword/doc

local m_translit = require("Module:ko-translit")
local PAGENAME = mw.title.getCurrentTitle().text

local export = {}
local pos_functions = {}

local lang = require("Module:languages").getByCode("ko")

pos_functions["ကြိယာများ"] = function(args, data)
	-- infinitive(s)
	local m_conj = require("Module:ko-conj").verb
	local hae = args["hae"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hae" })
	if hae == "" then hae = nil end
	local hae2 = args["hae2"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hae2" })
	if hae2 == "" then hae2 = nil end
	
	local infinitives = {label = "infinitive"}
	if hae then table.insert(infinitives, hae) end
	if hae2 then table.insert(infinitives, hae2) end
	if #infinitives > 0 then table.insert(data.inflections, infinitives) end
	
	-- sequential
	local hani = args["hani"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hani" })
	if hani == "" then hani = nil end
	
	if hani then table.insert(data.inflections, {label = "sequential", hani}) end
end

pos_functions["နာမဝိသေသနများ"] = function(args, data)
	local m_conj = require("Module:ko-conj").adjective
	local hae = args["hae"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hae" })
	if hae == "" then hae = nil end
	local hae2 = args["hae2"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hae2" })
	if hae2 == "" then hae2 = nil end
	
	local infinitives = {label = "infinitive"}
	if hae then table.insert(infinitives, hae) end
	if hae2 then table.insert(infinitives, hae2) end
	if #infinitives > 0 then table.insert(data.inflections, infinitives) end
	
	-- sequential
	local hani = args["hani"] or m_conj(nil, { PAGENAME, irreg = args["irreg"], form = "hani" })
	
	if hani then table.insert(data.inflections, {label = "sequential", hani}) end
end

pos_functions["suffixes"] = function(args, data)
	local hae = args["hae"]; if hae == "" then hae = nil end
	local hae2 = args["hae2"]; if hae2 == "" then hae2 = nil end
	
	local infinitives = {label = "infinitive"}
	if hae then table.insert(infinitives, hae) end
	if hae2 then table.insert(infinitives, hae2) end
	if #infinitives > 0 then table.insert(data.inflections, infinitives) end
	
	-- sequential
	local hani = args["hani"]; if hani == "" then hani = nil end
	
	if hani then table.insert(data.inflections, {label = "sequential", hani}) end
end

pos_functions["adjective forms"] = function(args, data)
	local root = args["root"]; if root == "" then root = nil end
	local form = args["form"]; if form == "" then form = nil end
	
	if form and root then
		table.insert(data.inflections, {label = form .. " of", root})
	end
end

pos_functions["verb forms"] = pos_functions["adjective forms"]

pos_functions["determiners"] = function(args, data)
	local root = args["root"]; if root == "" then root = nil end

	if root then table.insert(data.inflections, {label = "determinative form of", root}) end
end

pos_functions["နာမ်များ"] = function(args, data)
	local count = args["count"]; if count == "" then count = nil end
	
	if count == '-' then 
		table.insert(data.inflections, "ရေတွက်မရ")
	elseif count then
		table.insert(data.inflections, {label = "counter", count})
	end
end

-- other parts of speech: nothing special is done for adverbs, interjections, suffixes

-- 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 hangeul_pattern = '[ᄀ-ᄒ".."ᅡ-ᅵ".."ᆨ-ᇂ" .. "ㄱ-ㆎ가-힣 ]' -- includes a space character too
	local hanja_pattern = '[一-鿌]'
	
	local head = args["head"]; if head == "" then head = nil end
	local hangeul = args["hangeul"]; if hangeul == "" then hangeul = nil end
	local hanja = args["hanja"]; if hanja == "" then hanja = nil end
	local rv = args["rv"] or args["rr"]; if rv == "" then rv = nil end
	local mr = args["mr"]; if mr == "" then mr = nil end
	local y = args["y"]; if y == "" then y = nil end
	
	local data = {lang = lang, pos_category = poscat, categories = {}, heads = {head}, translits = {}, inflections = {}, sort_key = hangeul, sc = require("Module:scripts").getByCode(hangeul and "Hani" or "Kore")}
	
	-- categorize by part of speech
	if poscat == "hada verbs" then
		data.pos_category = "ကြိယာများ"
		table.insert(data.categories, "Korean hada verbs")
	elseif poscat == "အကူကြိယာများ" then
		data.pos_category = "ကြိယာများ"
		table.insert(data.categories, "ကိုရီးယား အကူကြိယာများ")
	end
	
	if args["irreg"] then table.insert(data.inflections, { label = "irregular" }) end
	
	-- grammatical forms etc. for each respective part of speech
	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end	
	
	-- >>> transliterations <<<
	-- if this entry is hangeul and no transliteration is provided, add auto transliteration
	-- if this entry is NOT hangeul and no translit is provided, add auto translit if there is hangeul 
	if mw.ustring.gsub(PAGENAME, hangeul_pattern, '') == "" and rv == nil then 
		rv = m_translit.tr(PAGENAME) 
	elseif hangeul and rv == nil then 
		rv = m_translit.tr(hangeul) end 
	if poscat == 'တစ်ဦးဆိုင်နာမ်များ' then
		rv = mw.ustring.upper(mw.ustring.sub(rv,1,1)) .. mw.ustring.sub(rv,2,-1)
	end
	
	-- add -hada to the revised romanization for 하다 (hada)  verbs
	if poscat == "hada verbs" then 
		rv = rv .. "-hada" 
		data.heads[1] = PAGENAME .. " + 하다"	
	end
	
	if poscat == "suffixes" then
		rv = "-" .. rv
		data.heads[1] = "—" .. PAGENAME
	elseif poscat == "prefixes" then
		rv = rv .. "-"
		data.heads[1] = PAGENAME .. "—"
	end
	
	if rv then table.insert(data.translits, rv) end
	if mr then table.insert(data.translits, "McCune-Reischauer: " .. mr) end
	if y then table.insert(data.translits, "Yale: " .. y) end
	data.translits = {table.concat(data.translits, ", ")}
	
	if hangeul then
		table.insert(data.inflections, {label = "hangeul", { term = hangeul, sc = require("Module:scripts").getByCode("Kore") }})
	end
	
	if hanja then
		table.insert(data.inflections, {label = "hanja", { term = hanja, sc = require("Module:scripts").getByCode("Hani") }})
	end
	
	-- and categorize hanja terms
	if mw.ustring.match(PAGENAME, hanja_pattern) then
		table.insert(data.categories, "Korean Han characters")
		if poscat == "နာမ်များ" then 
			table.insert(data.categories, "Korean nouns in Han script") 
		elseif poscat == "တစ်ဦးဆိုင်နာမ်များ" then 
			table.insert(data.categories, "Korean proper nouns in Han script") 
		end
	elseif mw.ustring.match(PAGENAME, hangeul_pattern) then
		local content = mw.title.new(PAGENAME):getContent()
		local code = mw.ustring.match(content, '{{ko%-IPA[^}]*}}')
		if not code then local code = mw.ustring.match(content, '{{ko%-ipa[^}]*}}') end
		if not code then local code = mw.ustring.match(content, '{{ko%-pron[|}]') end
		if not code then table.insert(data.categories, "Korean terms without ko-IPA template") end
	end
	
	-- maintenance category for hanja terms without hangeul
	if mw.ustring.match(PAGENAME, hanja_pattern) and hangeul == nil then 
		table.insert(data.categories, "Korean hanja terms lacking hangeul")
	end
	
	return require("Module:headword").full_headword(data)
end

return export