モジュール:cs-headword

出典: フリー多機能辞典『ウィクショナリー日本語版(Wiktionary)』
ナビゲーションに移動 検索に移動

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

local export = {}
local pos_functions = {}

local lang = require("モジュール:languages").getByCode("cs")

-- Table of all valid genders, mapping to the spelled-out base gender
-- (used for validation and categorization).
local valid_genders_to_base_gender = {
	["m"] = "男性",
	["m-an"] = "男性活動体",
	["m-in"] = "男性不活動体",
	["m-p"] = "男性",
	["f"] = "女性",
	["f-p"] = "女性",
	["n"] = "中性",
	["n-p"] = "中性",
}

local rfind = mw.ustring.find

local function format(array, concatenater)
	if #array == 0 then
		return ""
	else
		local concatenated = table.concat(array, concatenater)
		if concatenated == "" then
			return ""
		elseif concatenated:find("'$") then
			concatenated = concatenated .. " "
		end
		return "; ''" .. concatenated .. "''"
	end
end


-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local NAMESPACE = mw.title.getCurrentTitle().nsText
	local PAGENAME = mw.title.getCurrentTitle().text

	local iparams = {
		[1] = {required = true},
		["def"] = {},
		["suff_type"] = {},
	}
	local iargs = require("モジュール:parameters").process(frame.args, iparams)
	local args = frame:getParent().args
	local poscat = iargs[1]
	local def = iargs.def
	local suff_type = iargs.suff_type
	local postype = nil
	if suff_type then
		postype = poscat .. '-' .. suff_type
	else
		postype = poscat
	end

	local data = {lang = lang, categories = {}, heads = {}, genders = {}, inflections = {}}
	local infl_classes = {}
	local appendix = {}
	local postscript = {}

	if poscat == "suffixes" then
		table.insert(data.categories, "チェコ語 " .. suff_type .. "-forming suffixes")
	end

	if pos_functions[postype] then
		local new_poscat = pos_functions[postype](def, args, data, infl_classes, appendix, postscript)
		if new_poscat then
			poscat = new_poscat
		end
	end

	data.pos_category = (NAMESPACE == "Reconstruction" and "reconstructed " or "") .. poscat
	
	postscript = table.concat(postscript, ", ")
	
	return
		require("モジュール:headword").full_headword(data)
		.. format(infl_classes, "/")
		.. format(appendix, ", ")
		.. (postscript ~= "" and " (" .. postscript .. ")" or "")
end

pos_functions["名詞"] = function(def, args, data, infl_classes, appendix)
	local params = {
		["head"] = {list = true},
		[1] = {alias_of = "g"},
		["g"] = {list = true},
		["m"] = {list = true},
		["f"] = {list = true},
		["sort"] = {},
		["indecl"] = {type = boolean},
		["id"] = {},
	}

	local args = require("モジュール:parameters").process(args, params)
	data.heads = args.head
	data.sort = args.sort
	data.id = args.id

	for _, g in ipairs(args.g) do
		local base_gender = valid_genders_to_base_gender[g]
		if not base_gender then
			error("Unrecognized gender: '" .. g .. "'")
		end
		table.insert(data.categories, "チェコ語 " .. base_gender .. "名詞")
	end
	data.genders = args.g
	if args.indecl then
		table.insert(data.inflections, { label = "格変化なし"})
	end
	local masc = args.m
	if #masc > 0 then
		masc.label = "男性"
		table.insert(data.inflections, masc)
	end
	local fem = args.f
	if #fem > 0 then
		fem.label = "女性"
		table.insert(data.inflections, fem)
	end
end

pos_functions["suffixes-noun"] = pos_functions["nouns"]

return export