ข้ามไปเนื้อหา

มอดูล:got-headword

จาก วิกิพจนานุกรม พจนานุกรมเสรี

local export = {}
local pos_functions = {}

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

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	PAGENAME = mw.title.getCurrentTitle().text
	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:th-utilities").th_pos(poscat)

	local cat = args["cat"]; if cat == "" then cat = nil end
	local cat2 = args["cat2"]; if cat2 == "" then cat2 = nil end
	local cat3 = args["cat3"]; if cat3 == "" then cat3 = nil end
	
	local head = args["head"]; if head == "" then head = nil end
	local tr = args["tr"]; if tr == "" then tr = nil end
	
	local data = {lang = lang, pos_category = cat or poscat_th, categories = {}, heads = {head}, translits = {tr}, genders = {}, inflections = {}}
	
	if cat2 then table.insert(data.categories, cat2 .. "ภาษากอท") end
	if cat3 then table.insert(data.categories, cat3 .. "ภาษากอท") end
	
	if pos_functions[poscat_th] then
		pos_functions[poscat_th](args, data)
	end
	
	return require("Module:headword").full_headword(data)
end

pos_functions["คำนาม"] = function(args, data)
	-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
	local g = args[1] or ""; if g == "" then g = "?" end
	local i = 2
	
	while g ~= "" do
		-- If any of the specifications is a "?", add the entry
		-- to a cleanup category.
		if g == "m-p" or g == "f-p" or g == "n-p" then
			table.insert(data.categories, "คำนามพหูพจน์เท่านั้นภาษากอท")
		end
		
		table.insert(data.genders, g)
		g = args["g" .. i] or ""
		i = i + 1
	end
	
	if #data.genders == 0 then
		table.insert(data.genders, "?")
	end
end

pos_functions["คำวิสามานยนาม"] = pos_functions["คำนาม"]

pos_functions["คำคุณศัพท์"] = function(args, data)
	local adverb = args["adv"]; if adverb == "" then adverb = nil end
	local comparative = args[1]; if comparative == "" then comparative = nil end
	local superlative = args[2]; if superlative == "" then superlative = nil end
	
	if adverb then
		table.insert(data.inflections, {label = "คำกริยาวิเศษณ์", adverb})
	end
	
	if comparative then
		table.insert(data.inflections, {label = "ขั้นกว่า", comparative})
	end
	
	if superlative then
		table.insert(data.inflections, {label = "ขั้นสุด", superlative})
	end
end

pos_functions["คำกริยาวิเศษณ์"] = function(args, data)
	local adjective = args["adj"]; if adjective == "" then adjective = nil end
	local comparative = args[1]; if comparative == "" then comparative = nil end
	local superlative = args[2]; if superlative == "" then superlative = nil end
	
	if adjective then
		table.insert(data.inflections, {label = "คำคุณศัพท์", adjective})
	end
	
	if comparative then
		table.insert(data.inflections, {label = "ขั้นกว่า", comparative})
	end
	
	if superlative then
		table.insert(data.inflections, {label = "ขั้นสุด", superlative})
	end
end

return export