বিষয়বস্তুতে চলুন

মডিউল:ms-headword

উইকিঅভিধান, মুক্ত অভিধান থেকে

এই মডিউলের জন্য মডিউল:ms-headword/নথি-এ নথিপত্র তৈরি করা হয়ে থাকতে পারে

local export = {}
local pos_functions = {}

local u = require("Module:string/char")
local lang = require("Module:languages").getByCode("ms")
local PAGENAME = mw.loadData("Module:headword/data").pagename
local script = lang:findBestScript(PAGENAME) -- Latn or ms-Arab

local trackfn = require("Module:debug").track

local function track(page)
	trackfn("ms-headword/" .. page)
	return true
end

function export.show(frame)
	-- FIXME: use [[Module:parameters]].
	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 head = args["head"]; if head == "" then head = nil end
	if (mw.ustring.find(PAGENAME, "اء[وي]")) then
		head = mw.ustring
			.gsub(PAGENAME, "(ا)(ء)([وي])", "%1<sup>%2</sup>%3") -- superscript hamza
	end

	if args["ku"] ~= nil or args["mu"] ~= nil or args["nya"] ~= nil then
		track("clean up kumunya")
	end

	if args["r"] ~= nil then
		track("clean up r")
	end

	local data = {
		lang = lang,
		pos_category = poscat,
		categories = {},
		heads = { head },
		translits = { "-" },
		inflections = {},
		altform = script:getCode() == "ms-Arab"
	}

	if (head and mw.ustring.find(head, "[كڬ]")) or
		(args["j"] and mw.ustring.find(args["j"], "[كڬ]")) or
		(args["j2"] and mw.ustring.find(args["j2"], "[كڬ]")) or
		(args["j3"] and mw.ustring.find(args["j3"], "[كڬ]")) or
		(args["j4"] and mw.ustring.find(args["j4"], "[كڬ]")) then

		track("incorrect Jawi spelling")

		error("Please use ک in place of ك and ݢ in place of ڬ.")
	end

	local special_marks = "[" .. u(0x200B) .. "-" .. u(0x200F) .. "]" -- ZWSP, ZWNJ, ZWJ, LRM, RLM
	if (head and mw.ustring.find(head, special_marks)) or
		(args["j"] and mw.ustring.find(args["j"], special_marks)) or
		(args["j2"] and mw.ustring.find(args["j2"], special_marks)) or
		(args["j3"] and mw.ustring.find(args["j3"], special_marks)) or
		(args["j4"] and mw.ustring.find(args["j4"], special_marks)) then

		track("incorrect Jawi spelling")

		error("Please remove ZWSP, ZWNJ, ZWJ, LRM, and RLM from title/headword.")
	end

	local letter_replacements = { ["M"] = "m", ["N#"] = "ng", ["R#"] = "r" }
	local pattern_replacements = { }

	function export.affixation(text, affix)
		local first_consonant = ""
		if affix == "-" then
			text = text .. "-" .. text
		elseif mw.ustring.match(affix, "^%-.+%-$") then
			first_consonant = mw.ustring.match(text, "^[^aeiou]+")
			text = first_consonant .. mw.ustring.sub(affix, 2, -2) ..
				mw.ustring.sub(text, mw.ustring.len(first_consonant) + 1,
					-1)
		else
			text = gsub(affix, "%-", "#" .. text)
			text = gsub(text, "N([^aeiou]*)([aeiou])([^aeiou]*)$", "nge%1%2%3")
			text = gsub(text, "meN#p", "memp")
			for pattern, replacement in pairs(pattern_replacements) do
				text = gsub(text, pattern, replacement)
			end
			text = gsub(text, "[MNR]#?", letter_replacements)
			text = gsub(text, "#", "")
		end
		return text
	end

	local jawi = { label = "Jawi spelling" }

	if args["j"] then table.insert(jawi, { term = args["j"] }) end
	if args["j2"] then table.insert(jawi, { term = args["j2"] }) end
	if args["j3"] then table.insert(jawi, { term = args["j3"] }) end
	if args["j4"] then table.insert(jawi, { term = args["j4"] }) end
	if #jawi > 0 then table.insert(data.inflections, jawi) end

	if script:getCode() == "ms-Arab" then
		table.insert(data.categories, "Malay terms in Arabic script")
	end

	if pos_functions[poscat] then pos_functions[poscat](args, data) end

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

pos_functions["nouns"] = function(args, data)
	local pl = { label = "plural" }
	if args["pl"] == "-" then
		if script:getCode() ~= "ms-Arab" then table.insert(data.categories, "Malay uncountable nouns") end
	else
		if args["pl"] == nil then
			-- common plural
			local subwords = mw.text.split(PAGENAME, "%s")
			local firstword = subwords[1]
			subwords[1] = mw.ustring.gsub(
				"[[" .. firstword .. "]]-[[" .. firstword .. "]]",
				"([a-z]+%-)%1%1", "%1") -- reduplicate only first word
			table.insert(pl, table.concat(subwords, " "))
			if script:getCode() == "ms-Arab" then
				-- reduplicated form in Jawi
				subwords[1] = mw.ustring.gsub(
					"[[" .. firstword .. "]][[ـ٢|٢]]",
					"([a-z]+%-)%1%1", "%1") -- add "2" only first word
				table.insert(pl, table.concat(subwords, " "))
			end
		else
			table.insert(pl, args["pl"])
			if args["pl2"] then table.insert(pl, args["pl2"]) end
			if args["pl3"] then table.insert(pl, args["pl3"]) end
		end
		table.insert(data.inflections, pl)
	end
end

pos_functions["proper nouns"] = function(args, data)
	local pl = { label = "plural" }
	-- not necessary to have plural(s)
	if args["pl"] then table.insert(pl, args["pl"]) end
	if args["pl2"] then table.insert(pl, args["pl2"]) end
	if args["pl3"] then table.insert(pl, args["pl3"]) end
	if #pl > 0 then table.insert(data.inflections, pl) end
end

local aliases = {
	['transitive (person)'] = 'trp',
	['trans (person)'] = 'trp',
	['transitive (object)'] = 'tro',
	['trans (object)'] = 'tro',
	['intransitive'] = 'in',
	['intrans'] = 'in',
	['intr'] = 'in',
	['feeling'] = 'fl',
	['feel.'] = 'fl'
}

pos_functions["verbs"] = function(args, data)
	local tv = args["tv"] or ""
	tv = aliases[tv] or tv
	if tv ~= "" then
		if tv == "t" or tv == "tr" or tv == "tran" or tv == "transitive" then
			table.insert(data.inflections, { label = "transitive" })
			if script:getCode() ~= "ms-Arab" then table.insert(data.categories, "Malay transitive verbs") end
		end
		if tv == "i" or tv == "in" or tv == "intr" or tv == "intransitive" then
			table.insert(data.inflections, { label = "intransitive" })
			if script:getCode() ~= "ms-Arab" then table.insert(data.categories, "Malay intransitive verbs") end
		end
		if tv == "s" or tv == "st" or tv == "stat" or tv == "stative" then
			table.insert(data.inflections, { label = "stative" })
			if script:getCode() ~= "ms-Arab" then table.insert(data.categories, "Malay stative verbs") end
		end
	end
end

pos_functions["adjectives"] = function(args, data)
	local aform = { label = "used in the form" }
	for _, a in ipairs(args) do table.insert(aform, a) end
	if #aform > 0 then
		table.insert(data.inflections, aform)
	end
end

pos_functions["classifiers"] = function(args, data)
	local se = { label = "singular" }
	if args["se"] ~= "-" or args["se"] == nil then
		table.insert(data.inflections, se)
		if script:getCode() == "ms-Arab" then
			table.insert(se, mw.ustring.format("[[سي%s]]", PAGENAME))
		else
			table.insert(se, mw.ustring.format("[[se%s]]", PAGENAME))
		end
	end
end

return export