local export = {}
local pos_functions = {}
local force_cat = false -- for testing
local lang = require("Module:languages").getByCode("hil")
local langname = lang:getCanonicalName()
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local poscat = frame.args[1] or require("Module:string utilities").pluralize(args["pos"]) or error("Part of speech has not been specified. Please pass parameter 1= or pos= to the module invocation.")
local params = {
["head"] = {list = true, allow_holes = true},
[1] = {alias_of = "head"},
["id"] = {},
["suff"] = {type = "boolean"},
["nolinkhead"] = {type = "boolean"},
["json"] = {type = "boolean"},
["pagename"] = {}, -- for testing
}
if pos_functions[poscat] then
for key, val in pairs(pos_functions[poscat].params) do
params[key] = val
end
end
local args = require("Module:parameters").process(frame:getParent().args, params)
local pagename = args.pagename or mw.title.getCurrentTitle().subpageText
local user_specified_heads = args.head
local data = {
lang = lang,
pos_category = poscat,
categories = {},
heads = args.head,
user_specified_heads = user_specified_heads,
inflections = {},
pagename = pagename,
id = args.id,
force_cat_output = force_cat,
}
local is_suffix = false
if args.suff then
is_suffix = true
data.pos_category = "後綴"
local singular_poscat = require("Module:string utilities").singularize(poscat)
table.insert(data.categories, "構成" .. singular_poscat .. "的" .. langname .. "後綴")
table.insert(data.inflections, {label = "構成" .. singular_poscat .. "的後綴"})
end
if pos_functions[poscat] then
pos_functions[poscat].func(args, data, is_suffix)
end
local content = mw.title.new(pagename):getContent()
local code = content and mw.ustring.match(content, "{{hil%-IPA[^}]*}}")
--Categorize words without [[Template:hil-IPA]]
if not code then
table.insert(data.categories, "沒有hil-IPA模板的" .. langname .. "詞")
end
if args.json then
return require("Module:JSON").toJSON(data)
end
return require("Module:headword").full_headword(data)
end
local function handle_infl(args, data, argpref, label, accelform)
local forms = args[argpref]
if #forms > 0 then
forms.label = label
if accelform then
forms.accel = {form = accelform}
end
table.insert(data.inflections, forms)
end
end
pos_functions["動詞"] = {
params = {
["real"] = {list = true},
[2] = {alias_of = "real"}, --realis aspect
["imp"] = {list = true},
[3] = {alias_of = "imp"}, --imperative
["dim"] = {list = true},
["caus"] = {list = true},
["freq"] = {list = true},
},
func = function(args, data)
handle_infl(args, data, "real", "已然式", "realis")
handle_infl(args, data, "imp", "命令式", "imp")
handle_infl(args, data, "dim", "指小詞")
handle_infl(args, data, "caus", "使役態")
handle_infl(args, data, "freq", "反覆態")
end
}
pos_functions["形容詞"] = {
params = {
["sup"] = {list = true},
[2] = {alias_of = "sup"}, --superlative
["dim"] = {list = true},
["caus"] = {list = true},
},
func = function(args, data)
handle_infl(args, data, "sup", "最高級", "最高級")
handle_infl(args, data, "caus", "使役態")
handle_infl(args, data, "dim", "指小詞")
end
}
pos_functions["名詞"] = {
params = {
["pl"] = {list = true},
[2] = {alias_of = "pl"}, --special plural cases only
["dim"] = {list = true},
["m"] = {list = true},
["f"] = {list = true},
},
func = function(args, data)
handle_infl(args, data, "pl", "複數", "p")
handle_infl(args, data, "dim", "指小詞")
handle_infl(args, data, "f", "陰性")
handle_infl(args, data, "m", "陽性")
end
}
return export