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

มอดูล:te-headword

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

local export = {}
local pos_functions = {}
local match = mw.ustring.match
local gsub = mw.ustring.gsub

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

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:th-utilities").th_pos(poscat)
 
	local data = {lang = lang, sc = script, pos_category = poscat_th, categories = {}, heads = {args["head"] or PAGENAME}, genders = {}, inflections = {}}

	if pos_functions[poscat_th] then
		pos_functions[poscat_th](args, data)
	end
 
	return require("Module:headword").full_headword(data)

end

-- TODO
local function pluralize(sn)

	local pn

	-- do not swap
	if match(sn, "ుడు$") then -- -uDu > -ulu
		pn = gsub(sn, "ుడు$", "ులు")
	elseif match(sn, "డ్డ[ిు]$") then -- -DDi,-DDu > -Dlu
		pn = gsub(sn, "డ్డ[ిు]$", "డ్లు")
	elseif match(sn, "డి$") then -- -Di > -LLu
		pn = gsub(sn, "డి$", "ళ్ళు")
	elseif match(sn, "[డరల]ు$") then -- -Du,-lu,-ru > -LLu
		pn = gsub(sn, "[డరల]ు$", "ళ్ళు")
	elseif match(sn, "ట్ట[ిు]$") then -- -TTi,-TTu > -Tlu
		pn = gsub(sn, "ట్ట[ిు]$", "ట్లు")
	elseif match(sn, "టు$") then -- -Tu > -Tlu
		pn = gsub(sn, "టు$", "ట్లు")
	elseif match(sn, "([అక-హౘ-ౚ])ం$") then -- -aM > -Alu
		pn = gsub(sn, "([అక-హౘ-ౚ])ం$", "%1ాలు")
	elseif match(sn, "ెం$") then -- -eM > -Elu
		pn = gsub(sn, "ెం$", "ేలు")
	elseif match(sn, "ి$") then -- -i > -ulu
		pn = gsub(sn, "ి$", "ులు")
	else
		pn = sn .. "లు"
	end

	return pn

end

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

	local plurals = {label = "พหูพจน์", accel = "plural-of"}

	if not args[1] then
		table.insert(plurals, pluralize(PAGENAME))
		table.insert(data.inflections, plurals)
	elseif args[1] == "-" then
		table.insert(data.inflections, {label = "เอกพจน์เท่านั้น"})
		table.insert(data.categories, "คำนามเอกพจน์เท่านั้นภาษาเตลูกู")
	elseif args[1] == "+" then
		table.insert(data.inflections, {label = "พหูพจน์เท่านั้น"})
		table.insert(data.categories, "คำนามพหูพจน์เท่านั้นภาษาเตลูกู")
	else
		for _,par in ipairs(args) do
			table.insert(plurals, par)
		end
		table.insert(data.inflections, plurals)
	end

	table.insert(data.genders, args["g"] or "?")

end

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

	local plurals = {label = "พหูพจน์", accel = "plural-of"}

	if not args[1] then
		-- do nothing
	elseif args[1] == "+" then
		table.insert(data.inflections, {label = "พหูพจน์เท่านั้น"})
		table.insert(data.categories, "คำนามพหูพจน์เท่านั้นภาษาเตลูกู")
	else
		for _,par in ipairs(args) do
			table.insert(plurals, par)
		end
		table.insert(data.inflections, plurals)
	end

	table.insert(data.genders, args["g"] or "?")

end

return export