モジュール:krj-headword
このモジュールについての説明文ページを モジュール:krj-headword/doc に作成できます
--Based on [[モジュール:hil-headword]] by TagaSanPedroAko, rewritten by Benwing2
local export = {}
local pos_functions = {}
local force_cat = false -- for testing
local lang = require("モジュール:languages").getByCode("krj")
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("モジュール: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("モジュール: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 = "suffixes"
local singular_poscat = require("モジュール:string utilities").singularize(poscat)
table.insert(data.categories, langname .. " " .. singular_poscat .. "-forming suffixes")
table.insert(data.inflections, {label = singular_poscat .. "-forming suffix"})
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, "{{krj%-IPA[^}]*}}")
--Categorize words without [[テンプレート:krj-IPA]]
if not code then
table.insert(data.categories, langname .. " terms without hil-IPA template")
end
if args.json then
return require("モジュール:JSON").toJSON(data)
end
return require("モジュール: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", "realis")
handle_infl(args, data, "imp", "命令形", "imp")
handle_infl(args, data, "dim", "指小辞")
handle_infl(args, data, "caus", "causative")
handle_infl(args, data, "freq", "frequentative")
end
}
pos_functions["形容詞"] = {
params = {
["最上級"] = {list = true},
[2] = {alias_of = "sup"}, --superlative
["指小辞"] = {list = true},
["使役"] = {list = true},
},
func = function(args, data)
handle_infl(args, data, "sup", "最上級", "superlative")
handle_infl(args, data, "caus", "使役")
handle_infl(args, data, "dim", "指小辞")
end
}
pos_functions["名詞"] = {
params = {
["複数"] = {list = true},
[2] = {alias_of = "pl"}, --special plural cases only
["指小辞"] = {list = true},
["男性"] = {list = true},
["女性"] = {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