มอดูล:th-headword

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

local lang = require("Module:languages").getByCode("th")
local script = require('Module:scripts').getByCode("Thai")
local PAGENAME = mw.title.getCurrentTitle().text
local pron = require("Module:th-pron")

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 data = {lang = lang, sc = script, pos_category = poscat_th, categories = {}, heads = {args["head"]}, inflections = {}, sort_key = args["sort"]}
	
	if args["cat2"] then
		table.insert(data.categories, args["cat2"] .. "ภาษาไทย")
	end
	if args["cat3"] then
		table.insert(data.categories, args["cat3"] .. "ภาษาไทย")
	end
	
	if pos_functions[poscat_th] then
		pos_functions[poscat_th](args, data)
	end
	
	local content = mw.title.new(PAGENAME):getContent()
	if content then
		local phon
		local code = mw.ustring.match(content, '{{th%-pron[^o}]*}}')
		local false_positive = mw.ustring.match(content, 'note=') or mw.ustring.match(content, 'obsolete spelling of') or mw.ustring.match(content, 'obsolete form of') or mw.ustring.match(content, 'alternative spelling of') or mw.ustring.match(content, 'archaic spelling of') or mw.ustring.match(PAGENAME, 'ชื่อไม่รองรับ')
	
		if not code then
			phon = args["phon"] or args["mono"] or "-"
			--data.translits = {pron.translit(phon , "th", "Thai", "paiboon")}
			if not false_positive then
				table.insert(data.categories, "ศัพท์ภาษาไทยที่ไม่มี th-pron")
			end
		else
			phon = args["phon"] or args["mono"] or mw.ustring.match(code, '|([^|}]+)') or PAGENAME -- detects only first one
			--data.translits = {pron.translit(phon, "th", "Thai", "paiboon")}
		end
		
		local code2 = mw.ustring.match(content, '{{audio|th|[^}]*}}')
		if code2 then
			table.insert(data.categories, "Thai terms with redundant audio template")
		end	
	end
	
	if mw.ustring.match(PAGENAME, '.-[ก-ฮ](รร)$') or mw.ustring.match(PAGENAME, '.-[ก-ฮ](รร)[^ะ-ฺๅ็-๎].-') then
		if PAGENAME ~= 'วงจรรวม' and PAGENAME ~= 'สรรวง' then
			table.insert(data.categories, "ศัพท์ภาษาไทยที่สะกดด้วย รร")
		end
	end
	
	local letter = true
	local specialLetter = mw.ustring.gmatch(PAGENAME, '.-([ฤฦ]ๅ?).-')
	while true do
		letter = specialLetter()
		if (not letter) then break end
		table.insert(data.categories, "ศัพท์ภาษาไทยที่สะกดด้วย " .. letter)
	end
	local specialLetter2 = mw.ustring.gmatch(PAGENAME, '.-([ฃ๊ฅ๋ฆ็ฌฎฏฐฑฒฬฮใๆ]).-')
	while true do
		letter = specialLetter2()
		if (not letter) then break end
		if letter == "๊" or 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
	--"หมวดหมู่:ศัพท์ภาษาไทยที่สะกดด้วย ทร ออกเสียง ซ" ตรวจจับอยู่ใน มอดูล:th-pron
	local specialLetter3 = mw.ustring.gmatch(PAGENAME, '.-([ิุ]์).-')  -- I or U + KARAN
	while true do
		letter = specialLetter3()
		if (not letter) then break end
		table.insert(data.categories, "ศัพท์ภาษาไทยที่สะกดด้วย ◌" .. letter)
	end
	if mw.ustring.find(PAGENAME, '[0-9⁰¹²³⁴-⁹₀-₉๐-๙]') then
		table.insert(data.categories, "ศัพท์ภาษาไทยที่สะกดด้วยตัวเลข")
	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 par3 = args[3]; if par3 == "" then par3 = nil end
	local abstract_forms = {label = "คำอาการนาม", accel = {pos = "คำนาม", 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)
				table.insert(abstract_forms, par3)
			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 par3 = args[3]; if par3 == "" then par3 = nil end
	local abstract_forms = {label = "คำอาการนาม", accel = {pos = "คำนาม", 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)
			table.insert(abstract_forms, par3)
		end
		table.insert(data.inflections, abstract_forms)
	end

end

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

return export