コンテンツにスキップ

モジュール:rup-headword

出典: フリー多機能辞典『ウィクショナリー日本語版(Wiktionary)』

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

local export = {}
local pos_functions = {}

local force_cat = false -- for testing; if true, categories appear in non-mainspace pages

local lang = require("モジュール:languages").getByCode("rup")
local langname = "アルーマニア語"

local function track(track_id)
	require("モジュール:debug/track")("rup-headword/" .. track_id)
	return true
end

local function glossary_link(anchor, text)
	text = text or anchor
	return "[[付録:用語集#" .. anchor .. "|" .. text .. "]]"
end

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local iparams = {
		[1] = {required = true},
		["def"] = {},
	}
	local iargs = require("モジュール:parameters").process(frame.args, iparams)
	local args = frame:getParent().args
	local poscat = iargs[1]
	local def = iargs.def

	local parargs = frame:getParent().args

	local params = {
		["head"] = {list = true},
		["id"] = {},
		["sort"] = {},
		["splithyph"] = {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(parargs, params)

	local pagename = args.pagename or mw.title.getCurrentTitle().text

	local data = {
		lang = lang,
		pos_category = poscat,
		categories = {},
		heads = args.head,
		genders = {},
		inflections = {},
		pagename = pagename,
		id = args.id,
		sort_key = args.sort,
		force_cat_output = force_cat,
	}

	local is_suffix = false
	if pagename:find("^%-") and poscat ~= "接尾辞 定形" 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(def, args, data, is_suffix)
	end

    if args.json then
        return require("モジュール:JSON").toJSON(data)
    end
	
	return require("モジュール:headword").full_headword(data)
end

local function insert_inflection(data, list, label)
	if #list > 0 then
		list.label = label
		table.insert(data.inflections, list)
	end
end

pos_functions["動詞"] = {
	params = {
		["pres2s"] = {list = true},
		["pres3s"] = {list = true},
		["pres2p"] = {list = true},
		["impf"] = {list = true},
		["sperf"] = {list = true},
		["pp"] = {list = true},
		["impers"] = {type = "boolean"},
		["thirdonly"] = {type = "boolean"},
	},
	func = function(def, args, data, is_suffix)
		if args.impers then
			table.insert(data.inflections, {label = "非人称"})
			data.gloss = "直説法現在第三人称単数"
		elseif args.thirdonly then
			data.gloss = "直説法現在第三人称単数"
		else
			data.gloss = "直説法現在第一人称単数"
		end
		insert_inflection(data, args.pres2s, "直説法現在第二人称単数")
		insert_inflection(data, args.pres3s, "直説法現在第三人称単数")
		insert_inflection(data, args.pres2p, "直説法現在第二人称複数")
		insert_inflection(data, args.impf, "半過去")
		insert_inflection(data, args.sperf, "単純過去")
		insert_inflection(data, args.pp, "過去分詞")
	end,
}

return export