มอดูล:lo-headword

จาก วิกิพจนานุกรม พจนานุกรมเสรี
local export = {}
local pos_functions = {}

local lang = require("Module:languages").getByCode("lo")
local script = require("Module:scripts").getByCode("Laoo")
local PAGENAME = mw.title.getCurrentTitle().text

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 poscat_th = require("Module:utilities").translate_term(poscat)
 
	local head = args["head"] or PAGENAME
	local tr = args["tr"]
	
	local data = {lang = lang, pos_category = poscat_th, categories = {}, heads = {head}, translits = {tr}, inflections = {}}
	
	if pos_functions[poscat_th] then
		pos_functions[poscat_th](args, data)
	end

	local letter = true
	local specialLetter = mw.ustring.gmatch(PAGENAME, '.-([ໃໆ໊໋]).-')
	while true do
		letter = specialLetter()
		if (not letter) then break end
		if letter == "໊" or letter == "໋" then
			table.insert(data.categories, "ศัพท์ภาษาลาวที่สะกดด้วย ◌" .. letter) -- add dotted circle for above/below marks
		else
			table.insert(data.categories, "ศัพท์ภาษาลาวที่สะกดด้วย " .. letter)
		end
		if letter == "ໆ" and PAGENAME ~= "ໆ" then
			table.insert(data.categories, "คำซ้ำภาษาลาว")
		end
	end
	if mw.ustring.match(PAGENAME, '.-([^ຫ]ຼ).-') then
		table.insert(data.categories, "ศัพท์ภาษาลาวที่สะกดด้วย ◌ຼ ที่ไม่ใช่ ຫຼ")
	end

	local content = mw.title.new(PAGENAME):getContent()
	local code = mw.ustring.match(content, "{{lo%-pron[^o}]*}}")
	local unclearAdjunct = mw.ustring.match(content, "คำวิเศษณ์")

	if not code then
		table.insert(data.categories, "ศัพท์ภาษาลาวที่ไม่มี lo-pron")
	end
	
	if unclearAdjunct then
		table.insert(data.categories, "ศัพท์ภาษาลาวที่ยังใช้คำวิเศษณ์อยู่")
	end

	if mw.ustring.match(PAGENAME, "[​­]") then
		table.insert(data.categories, "ศัพท์ภาษาลาวที่มี zero-width space")
	end

	return require("Module:headword").full_headword(data)

end

pos_functions["คำนาม"] = function(args, data)

	local classifiers = {label = "คำลักษณนาม"}

	if args[1] then
		for _,par in ipairs(args) do
			if par == "*" then
				table.insert(classifiers, PAGENAME) -- shorthand
				table.insert(data.categories, "คำลักษณนามภาษาลาว")
				table.insert(data.categories, "คำนามภาษาลาวที่ใช้คำลักษณนาม " .. PAGENAME)
			else
				table.insert(classifiers, par)
				table.insert(data.categories, "คำนามภาษาลาวที่ใช้คำลักษณนาม " .. par)
			end
		end
		table.insert(data.inflections, classifiers)
	end

end

pos_functions["คำกริยา"] = function(args, data)

	local par1 = args[1]; if par1 == "" then par1 = nil end
	local par2 = args[2]; if par2 == "" then par2 = nil end
	local abstract_forms = {label = "คำอาการนาม", accel = {form = "abstract-noun"}}

	if par1 ~= "-" then
		if not par1 then
			table.insert(abstract_forms, "ການ" .. PAGENAME)
		else
			if par1 == "~" then
				table.insert(abstract_forms, "ການ" .. PAGENAME)
				table.insert(abstract_forms, "ຄວາມ" .. PAGENAME)
			else
				table.insert(abstract_forms, par1)
				table.insert(abstract_forms, par2)
			end
		end
		table.insert(data.inflections, abstract_forms)
	end

end

pos_functions["คำคุณศัพท์"] = function(args, data)

	local par1 = args[1]; if par1 == "" then par1 = nil end
	local par2 = args[2]; if par2 == "" then par2 = nil end
	local abstract_forms = {label = "คำอาการนาม", accel = {form = "abstract-noun"}}

	if par1 ~= "-" then
		if not par1 then
			table.insert(abstract_forms, "ຄວາມ" .. PAGENAME)
		else
			table.insert(abstract_forms, par1)
			table.insert(abstract_forms, par2)
		end
		table.insert(data.inflections, abstract_forms)
	end

end

-- same logic
pos_functions["คำกริยาวิเศษณ์"] = pos_functions["คำคุณศัพท์"]
-- same logic
pos_functions["คำวิสามานยนาม"] = pos_functions["คำนาม"]

return export