モジュール:ain-headword/verb

このモジュールについての説明文ページを モジュール:ain-headword/verb/doc に作成できます

local export = {}

local lang = "ain"

local VERB_TYPE_MAP = {
	{"完全動詞", "0項動詞"},
	{"自動詞", "1項動詞"},
	{"他動詞", "2項動詞"},
	{"複他動詞", "3項動詞"}
}

function export.show(frame)
	local params = {
		[1] = { required = true, type = "number" },
		["sg"] = {},
        ["pl"] = { list = true },
        ["ctx"] = { list = true },
        ["cat"] = { list = true },
        ["head"] = { list = true },
		["pl_alt"] = { list = true },
		["caus"] = {},
		["base"] = {}
	}

	local args = require("Module:parameters").process(frame:getParent().args, params)

	local verb_map = VERB_TYPE_MAP[args[1] + 1]
	if not verb_map then
		error("Invalid verb slot number provided. Must be between 0 and 3.")
	end

	local sg_form = args["sg"]

	local verb_type = verb_map[1]
	local verb_slot_type = verb_map[2]

	local head_args = {
		lang,
		'verb',
		cat2 = verb_type,
	}

	local form_count = 0

	if sg_form then
		table.insert(head_args, "単数形")
		table.insert(head_args, sg_form)
		form_count = form_count + 1
	end

	for i, cat in ipairs(args["cat"]) do
		table["cat" .. (2 + i)] = cat
	end
	
    if args["pl"] then
        for i, pl in ipairs(args["pl"]) do
			if i == 1 then
				table.insert(head_args, "複数形")
			else
				table.insert(head_args, "or")
			end
            table.insert(head_args, pl)
			form_count = form_count + 1
			if args["pl_alt"] and args["pl_alt"][i] then
				head_args["f" .. form_count .. "alt"] = args["pl_alt"][i]
			end
        end
    end

    if args["head"] then
		for i, v in ipairs(args["head"]) do
			head_args["head" .. i] = v
		end
    end

	if args["caus"] then
	    table.insert(head_args, "使役形")
	    table.insert(head_args, args["caus"])
	    form_count = form_count + 1
	end
	
	if args["base"] then
	    table.insert(head_args, "基本形")
	    table.insert(head_args, args["base"])
	    form_count = form_count + 1
	end

	local head = frame:expandTemplate{ title = 'head', args = head_args }

	local context_args = {
		verb_type,
		verb_slot_type,
		lang = lang
	}

	for _, ctx in ipairs(args["ctx"]) do
		table.insert(context_args, ctx)
	end

	local context = frame:expandTemplate{ title = 'context', args = context_args }

	local output = head .. " " .. context

	return output
end

return export