local export = {}
local pos_functions = {}
local lang = require("Module:languages").getByCode("id")
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local iparams = {
= {required = true},
}
local iargs = require("Module:parameters").process(frame.args, iparams)
local args = frame:getParent().args
local poscat = iargs
local parargs = frame:getParent().args
local params = {
= {list = true, disallow_holes = true},
= true,
= true,
= {type = "boolean"},
= {type = "boolean"},
= true, -- for testing
}
if pos_functions then
local posparams = pos_functions.params
if type(posparams) == "function" then
posparams = posparams(lang)
end
for key, val in pairs(posparams) do
params = val
end
end
local args = require("Module:parameters").process(parargs, params)
local pagename = args.pagename or mw.title.getCurrentTitle().text
local user_specified_heads = args.head
local heads = user_specified_heads
if args.nolinkhead then
if #heads == 0 then
heads = {pagename}
end
end
for i, head in ipairs(heads) do
if head == "+" or head == "*" then
head = nil
end
heads = {
term = head,
tr = "-",
}
end
local data = {
lang = lang,
pos_category = poscat,
categories = {},
heads = heads,
user_specified_heads = user_specified_heads,
no_redundant_head_cat = #user_specified_heads == 0,
inflections = {},
pagename = pagename,
id = args.id,
sort_key = args.sort,
force_cat_output = force_cat,
is_suffix = false,
}
if pagename:find("^%-") and poscat ~= "suffix forms" then
data.is_suffix = true
data.pos_category = "suffixes"
table.insert(data.categories, langname .. " " .. singular_poscat .. "-forming suffixes")
table.insert(data.inflections, {label = singular_poscat .. "-forming suffix"})
end
if pos_functions and pos_functions.func then
pos_functions.func(args, data)
end
if args.json then
return require("Module:JSON").toJSON(data)
end
return require("Module:headword").full_headword(data)
end
-- Function for nouns (common and proper)
local function make_default_plural(pagename)
local subwords = mw.text.split(pagename, "%s")
local firstword = subwords
subwords = mw.ustring.gsub("]-]", "(+%-)%1%1", "banyak %1")
return table.concat(subwords, " ")
end
-- Shortcuts for the plural markings
pos_functions = {
params = {
= {list = "pl"},
= {alias_of = 1},
},
func = function(args, data)
-- Auto-detect full reduplication
local pagename = mw.title.getCurrentTitle().text -- Get the current page name
if pagename:match("^(+)%-%1$") then
local pl = {label = "plural"}
table.insert(pl, mw.ustring.format("]", PAGENAME))
if args then table.insert(pl, args) end
if args then table.insert(pl, args) end
table.insert(data.inflections, pl)
return -- Stop further processing
end
-- Main code for noun plurality
local pl1 = args
-- Unknown or uncertain and requests
if pl1 == "req" then
table.insert(data.categories, "Requests for plural forms in Indonesian entries")
elseif pl1 == "?" then
table.insert(data.categories, "Indonesian nouns with unknown or uncertain plurals")
-- Uncountable and semi-countable
elseif pl1 == "-" then
table.insert(data.categories, "Indonesian uncountable nouns")
table.insert(data.inflections, {label = "]"})
elseif pl1 == "0" then
table.insert(data.categories, "Indonesian uncountable nouns")
elseif pl1 == "u" then
local pl_countable = {label = "usually ]"}
local pl_plural = {label = "plural"}
table.insert(data.categories, "Indonesian countable nouns")
table.insert(data.categories, "Indonesian uncountable nouns")
local subwords = mw.text.split(PAGENAME, "%s")
local firstword = subwords
local plural_form = mw.ustring.gsub("]-]", "(+%-)%1%1", "banyak %1")
table.insert(pl_plural, plural_form)
table.insert(data.inflections, pl_countable)
table.insert(data.inflections, pl_plural)
elseif pl1 == "~" then
local pl_countable = {label = "] and ]"}
local pl_plural = {label = "plural"}
table.insert(data.categories, "Indonesian countable nouns")
table.insert(data.categories, "Indonesian uncountable nouns")
local subwords = mw.text.split(PAGENAME, "%s")
local firstword = subwords
local plural_form = mw.ustring.gsub("]-]", "(+%-)%1%1", "banyak %1")
table.insert(pl_plural, plural_form)
table.insert(data.inflections, pl_countable)
table.insert(data.inflections, pl_plural)
elseif pl1 == "pt" or pl1 == "p" then
table.insert(data.categories, "Indonesian pluralia tantum")
table.insert(data.inflections, {label = "]"})
elseif pl1 == "st" or pl1 == "s" then
table.insert(data.categories, "Indonesian singularia tantum")
table.insert(data.inflections, {label = "]"})
elseif pl1 == "1" then
error("The parameter |pl=1 is invalid. Please specify the plurality with an existing value.")
-- Countable
else
local pl = {label = "plural"}
if not pl1 or pl1 == "+" then
table.insert(pl, make_default_plural(data.pagename))
elseif pl1 == "a" then
table.insert(pl, make_default_plural(data.pagename))
table.insert(pl, "] " .. data.pageanme)
elseif pl1 == "*" then
table.insert(pl, data.pagename)
else
table.insert(pl, pl1)
end
for i = 2, #args do
table.insert(pl, args)
end
table.insert(data.inflections, pl)
end
if args == "-" then
error("Please replace |pl=- with |-. Please make sure that the noun is really UNCOUNTABLE not COUNTABLE.")
end
if args == "0" then
require("Module:debug/track")("id-noun/pl0")
end
if args then -- Only for tracking purpose
require("Module:debug/track")("id-noun/pl2")
end
if args then -- Only for tracking purpose
require("Module:debug/track")("id-noun/pl3")
end
end
}
return export