Modul:ms-headword/ujian
Penampilan
- Modul ini kekurangan sublaman pendokumenan. Sila mencipta laman pendokumenan berkaitan.
- Pautan berguna: laman akar • sublaman • pautan • transklusi • kes ujian • kotak pasir
local export = {}
local pos_functions = {}
local lang = require("Module:languages").getByCode("ms")
local PAGENAME = mw.title.getCurrentTitle().text
local script = require("Module:scripts").findBestScript(PAGENAME, lang) -- Latn or ms-Arab
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 head = args["head"] or ""
if (mw.ustring.find(PAGENAME, "اء[وي]")) then
head = mw.ustring.gsub(PAGENAME, "(ا)(ء)([وي])", "%1<sup>%2</sup>%3") -- superscript hamza
end
local data = {lang = lang, sc = script, pos_category = poscat, categories = {}, heads = {head}, translits = {"-"}, inflections = {}}
if (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"], "[كڬ]")) then
table.insert(data.categories, "Istilah Bahasa Melayu dengan ejaan Jawi yang salah")
error("Sila guna ک daripada ك dan ݢ daripada ڬ.")
end
function export.affixation(text, affix)
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 letter_replacements = {
["M"] = "m", ["N#"] = "ng", ["R#"] = "r"
}
local jawi = {label = "Ejaan Jawi"}
local sc_Arab = require("Module:scripts").getByCode("ms-Arab")
if args["j"] then table.insert(jawi, { term = args["j"], sc = sc_Arab }) end
if args["j2"] then table.insert(jawi, { term = args["j2"], sc = sc_Arab }) end
if args["j3"] then table.insert(jawi, { term = args["j3"], sc = sc_Arab }) end
if #jawi > 0 then table.insert(data.inflections, jawi) end
local rumi = {label = "Ejaan rumi"}
local sc_Latn = require("Module:scripts").getByCode("Latn")
if args["r"] then table.insert(rumi, { term = args["r"], sc = sc_Latn }) end
if args["r2"] then table.insert(rumi, { term = args["r2"], sc = sc_Latn }) end
if args["r3"] then table.insert(rumi, { term = args["r3"], sc = sc_Latn }) end
if #rumi > 0 then table.insert(data.inflections, rumi) end
if script:getCode() == "ms-Arab" then
table.insert(data.categories, "Istilah Bahasa Melayu dengan ejaan Jawi")
end
if pos_functions[poscat] then
pos_functions[poscat](args, data)
end
return require("Module:headword").full_headword(data)
end
pos_functions["kata nama"] = function(args, data)
local pl = {label = "jamak"}
if args["pl"] == "-" then
table.insert(data.categories, "Kata nama tak terhitung Bahasa Melayu")
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 .. "]][[۲#Malay|۲]]", "([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["kata nama khas"] = function(args, data)
local pl = {label = "jamak"}
-- 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["kata kerja"] = function(args, data)
local tr = args["tr"] or ""
tr = aliases[tr] or tr
if tr ~= "" then
if tr == "tr" then table.insert(data.inflections, {label = "transitive"})
table.insert(data.categories, "Malay transitive verbs") end
if tr == "in" then table.insert(data.inflections, {label = "intransitive"})
table.insert(data.categories, "Malay intransitive verbs") end
if tr == "st" then table.insert(data.inflections, {label = "stative"})
table.insert(data.categories, "Malay stative verbs") end
else
table.insert(data.categories, "Malay verbs without transitivity")
end
end
pos_functions["adjektif"] = 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
local pl = {label = "jamak"}
if args["pl"] ~= "-" then
if args["pl"] == nil then
-- common plural
local subwords = mw.text.split(PAGENAME, "%s")
local firstword = subwords[1]
subwords[1] = "[[" .. firstword .. "]]-[[" .. firstword .. "]]" -- reduplicate only first word
table.insert(pl, table.concat(subwords, " "))
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["kata penentu"] = 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("[[سي%]]",
PAGENAME))
else
table.insert(se, mw.ustring.format("[[se%s]]",
PAGENAME))
end
end
end
return export