モジュール:he-headword

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

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

local m_headword = require("モジュール:headword")
local com = require("モジュール:he-common")

local export = {}
local pos_functions = {}

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

local function get_params_list(args, argprefix)
	local export = {}
	i = 1
	term = argprefix

	while args[term] ~= nil and args[term] ~= "" do
		table.insert(export, term)

		i = i + 1
		term = argprefix .. i
	end
	return export
end

local function make_params_array(args, params)
	local export = {}
	for _, param in ipairs(params) do
		table.insert(export, args[param])
	end
	return export
end

local function maybe_get_inflection(args, name, params, list, accel, is_construct)
	if list then
		params = get_params_list(args, params)
	end
	
	local tbl = {}
	if type(params) ~= "table" then
		params = {params}
	end
	for _, param in ipairs(params) do
		local paramwv = param .. "wv"
		local paramdwv = param .. "dwv"
		if args[param] or args[paramwv] or args[paramdwv] then
			tbl.label = name
			tbl.accel = accel
			if is_construct == true then
				table.insert(tbl, com.gen_link_ending_with_makaf(args[param], args[paramwv], args[paramdwv]))
			else
				table.insert(tbl, com.gen_link(args[param], args[paramwv], args[paramdwv]))
			end
		end
		if args[param] == "" or args[paramwv] == "" or args[paramdwv] == "" then
			require('モジュール:debug').track("he-noun/empty-form-param")
		elseif args[param] ~= nil and args[paramwv] ~= nil then
			require('モジュール:debug').track("he-noun/param-and-paramwv")
		end
	end
	return next(tbl) and tbl
end

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local args = frame:getParent().args
	local poscat = frame.args[1] or error("品詞が指定されていません。パラメータ1をモジュールの呼び出しに渡して下さい。")

	if frame.args["auto"] and (args["auto"] == "" or not args["auto"]) then args["auto"] = frame.args["auto"] end

	local heads = make_params_array(args, get_params_list(args, "head"))
	local head = args["head"]; if head == "" then head = nil end; heads[1] = head
	local wv = args["wv"] or mw.title.getCurrentTitle().subpageText
	local dwv = args["dwv"]

	if not heads[1] then
		if dwv then
			heads[1] = wv .. " \\ " .. '<span class="inflection-table">' .. "[[" .. dwv .. "]]" .. "</span>" -- not really an inflection table but for the black links
		else
			heads[1] = wv
		end
	end

	if dwv and mw.ustring.match(dwv, "%[%[") then
		require('モジュール:debug').track("he-noun/link-in-dwv")
	end
	
	local tr = make_params_array(args, get_params_list(args, "tr"))
	local genders = {}
	local inflections = {}
	local categories = {"ヘブライ語 " .. poscat}

	local begedkefet = "בגדכפת"
	local vowels = "ְֱֲֳִֵֶַָֹֻ"
	local dagesh = "ּֿ"
	local begedkefet_regex = "[" .. begedkefet .. "]"
	local vowels_regex = "[" .. vowels .. "]"
	local dagesh_regex = "[" .. dagesh .. "]"

	if args["unchangeablebegedkefet"] == "1" or mw.ustring.match(com.fix_nikud(dwv or wv), "^" .. begedkefet_regex .. vowels_regex) then
		table.insert(categories, "Hebrew terms beginning with an unchangeable begedkefet letter")
	elseif mw.ustring.match(com.fix_nikud(dwv or wv), "^" .. begedkefet_regex .. dagesh_regex) then
		table.insert(categories, "Hebrew terms beginning with a begedkefet letter")
	end

	if args["pat"] and args["pat"] ~= "" and poscat ~= "verbs" then
		table.insert(categories, "Hebrew terms in the pattern " .. args["pat"])
	end

	if pos_functions[poscat] then
		pos_functions[poscat](args, genders, inflections, categories, wv)
	end

	table.insert(inflections, maybe_get_inflection(args, "Biblical Hebrew [[w:Pausa|pausal form]]", "pausal", false))

	local sort = args["sort"]
	sort = sort ~= "" and sort or nil
	if sort then
		sort = sort .. "a" .. mw.title.getCurrentTitle().subpageText
	end

	return (m_headword.full_headword{
		lang = lang,
		heads = heads,
		translits = tr,
		genders = genders,
		inflections = inflections,
		categories = categories,
		sort_key = sort,
	})
end

pos_functions["adjectives"] = function(args, genders, inflections, categories)
	table.insert(genders, "m")
	if args["auto"] == nil or args["auto"] == "" then
		-- Use only provided inflections
		table.insert(inflections, maybe_get_inflection(args, "女性", {"f", "f2"}, false))
		table.insert(inflections, maybe_get_inflection(args, "男性複数", {"mp", "mp2"}, false))
		table.insert(inflections, maybe_get_inflection(args, "女性複数", "fp", true))
	else
		-- Automatically generate inflections
		local stem, stemwv, stemdwv = com.process_wv_triad(args["stem"], args["stemwv"], args["stemdwv"])
		if not stem then
			stemwv = args["wv"] or args["dwv"]
			stemdwv = args["wv"] and args["dwv"]
			stem = com.remove_nikud(stemwv) or mw.title.getCurrentTitle().subpageText
		end
		local f, fwv, fdwv = com.process_wv_triad(args["f"], args["fwv"], args["fdwv"])
		local f2, f2wv, f2dwv = com.process_wv_triad(args["f2"], args["f2wv"], args["f2dwv"])
		local mp, mpwv, mpdwv = com.process_wv_triad(args["mp"], args["mpwv"], args["mpdwv"])
		local mp2, mp2wv, mp2dwv = com.process_wv_triad(args["mp2"], args["mp2wv"], args["mp2dwv"])
		local fp, fpwv, fpdwv = com.process_wv_triad(args["fp"], args["fpwv"], args["fpdwv"])
		if f ~= "-" then
			if not (f or fwv or fdwv) then
				f = stem and (stem .. "ה")
				fwv = stemwv and (stemwv .. "ָה")
				fdwv = stemdwv and (stemdwv .. "ָה")
			end
			tbl = {label = "女性", com.gen_link(f, fwv, fdwv)}
			if f2 or f2wv or f2dwv then
				table.insert(tbl, com.gen_link(f2, f2wv, f2dwv))
			end
			table.insert(inflections, tbl)
		end
		if mp ~= "-" then
			if not (mp or mpwv or mpdwv) then
				mp = stem and (stem .. "ים")
				mpwv = stemwv and (stemwv .. "ִים")
				mpdwv = stemdwv and (stemdwv .. "ִים")
			end
			tbl = {label = "男性複数", com.gen_link(mp, mpwv, mpdwv)}
			if mp2 or mp2wv or mp2dwv then
				table.insert(tbl, com.gen_link(mp2, mp2wv, mp2dwv))
			end
			table.insert(inflections, tbl)
		end
		if fp ~= "-" then
			if not (fp or fpwv or fpdwv) then
				fp = stem and (stem .. "ות")
				fpwv = stemwv and (stemwv .. "וֹת")
				fpdwv = stemdwv and (stemdwv .. "וֹת")
			end
			tbl = {label = "女性複数", com.gen_link(fp, fpwv, fpdwv)}
			table.insert(inflections, tbl)
		end
	end
end

pos_functions["determiners"] = function(args, genders, inflections, categories, wv)
	if args["g"] == "m" or args["g"] == "m-p" then
		table.insert(genders, args["g"])
		table.insert(inflections, maybe_get_inflection(args, "feminine counterpart", "f", true))
	elseif args["g"] == "f" or args["g"] == "f-p" then
		table.insert(genders, args["g"])
		table.insert(inflections, maybe_get_inflection(args, "masculine counterpart", "m", false))
	elseif args["g"] == "m-f" or args["g"] == "m-f-p" then
		table.insert(genders, args["g"])
	end
end

pos_functions["nouns"] = function(args, genders, inflections, categories, wv)
	local origin = " origin-" .. wv:gsub("%%", "."):gsub(" ", "_")

	if args["g"] == "m" or args["g"] == "f" or args["g"] == "m-f" then
		table.insert(genders, args["g"])
		if args["sg"] ~= nil then
			require('モジュール:debug').track("he-noun/sg-for-head")
		end
	elseif args["g"] == "m-d" or args["g"] == "f-d" or args["g"] == "m-f-d" then
		table.insert(genders, args["g"])
		table.insert(categories, "ヘブライ語 絶対双数")
		table.insert(inflections, maybe_get_inflection(args, "非限定単数", "sg", false))
	elseif args["g"] == "m-p" or args["g"] == "f-p" or args["g"] == "m-f-p" then
		table.insert(genders, args["g"])
		table.insert(categories, "ヘブライ語 絶対複数")
		table.insert(inflections, maybe_get_inflection(args, "非限定単数", "sg", false))
	elseif args["g"] == "" or args["g"] == nil then
		table.insert(genders, "?")
		table.insert(categories, "Hebrew terms with incomplete gender")
	end

	-- Dual forms rare enough that there's no need for without/missing categoristion
	table.insert(inflections, maybe_get_inflection(args, "dual indefinite", "dual", true))

	if args["pl"] == "-" then
		table.insert(inflections, {label = "複数形なし"})
		table.insert(categories, "ヘブライ語 名詞 複数形無し")
	elseif args["pl"] == "" or args["pl"] == nil then
		table.insert(categories, "ヘブライ語 名詞 複数形未入力")
	else
		table.insert(inflections, maybe_get_inflection(args, "非限定複数", "pl", true, "plural-form-of" .. origin))
		if args["g"] == "m" and mw.ustring.sub(com.remove_nikud(args["pl"]), -2, -1) == "ות" then
			table.insert(categories, "Hebrew masculine nouns with plurals ending in ־ות")
		elseif args["g"] == "f" and mw.ustring.sub(com.remove_nikud(args["pl"]), -2, -1) == "ים" then
			table.insert(categories, "Hebrew feminine nouns with plurals ending in ־ים")
		elseif mw.ustring.sub(com.remove_nikud(args["pl"]), -3, -1) == "יים" then
			table.insert(categories, "Hebrew nouns with plurals ending in ־יים")
		end
	end

	if args["cons"] == "-" then
		table.insert(inflections, {label = "no construct forms"})
		table.insert(categories, "Hebrew nouns without construct forms")
	else
		if args["cons"] == "" or args["cons"] == nil then
			table.insert(categories, "Hebrew noun entries missing singular construct forms")
		else
			table.insert(inflections, maybe_get_inflection(args, "singular construct", "cons", true, "construct-form-of" .. origin, true))
		end
		if (args["plcons"] == "" or args["plcons"] == nil) and args["pl"] ~= "-" then
			table.insert(categories, "Hebrew noun entries missing plural construct forms")
		else
			table.insert(inflections, maybe_get_inflection(args, "plural construct", "plcons", true, "plural-construct-form-of" .. origin, true))
		end
		table.insert(inflections, maybe_get_inflection(args, "dual construct", "dualcons", true , nil, true))
	end

	table.insert(inflections, maybe_get_inflection(args, "masculine counterpart", "m", true))
	table.insert(inflections, maybe_get_inflection(args, "feminine counterpart", "f", true))

	if args["g"] == "m" and mw.ustring.sub((com.remove_nikud(args["wv"] or args["dwv"] or mw.title.getCurrentTitle().subpageText)), -1) == "ת" then
		table.insert(categories, "Hebrew masculine nouns ending in ־ת")
	elseif args["g"] == "m" and mw.ustring.sub((com.remove_nikud(args["wv"] or args["dwv"] or mw.title.getCurrentTitle().subpageText)), -1) == "ה" then
		table.insert(categories, "Hebrew masculine nouns ending in ־ה")
	end
end

pos_functions["numerals"] = function(args, genders, inflections, categories)
	table.insert(inflections, maybe_get_inflection(args, "masculine counterpart", "m", true))
	table.insert(inflections, maybe_get_inflection(args, "feminine counterpart", "f", true))
end

pos_functions["pronouns"] = function(args, genders, inflections, categories)
	if args["g"] == "m" or args["g"] == "f" or args["g"] == "m-f" or args["g"] == "m-p" or args["g"] == "f-p" or args["g"] == "m-f-p" then
		table.insert(genders, args["g"])
	elseif args["n"] then
		require('Module:debug').track("he-pron/param-n")
	end
end

pos_functions["proper nouns"] = function(args, genders, inflections, categories)
	if args["g"] == "m" or args["g"] == "f" or args["g"] == "m-f" then
		table.insert(genders, args["g"])
	elseif args["g"] == "m-d" or args["g"] == "f-d" or args["g"] == "m-f-d" then
		table.insert(genders, args["g"])
		table.insert(categories, "ヘブライ語 絶対双数")
	elseif args["g"] == "m-p" or args["g"] == "f-p" or args["g"] == "m-f-p" then
		table.insert(genders, args["g"])
		table.insert(categories, "ヘブライ語 絶対複数")
	elseif args["g"] == "" or args["g"] == nil then
		table.insert(categories, "Hebrew proper nouns with incomplete gender")
	elseif args["g"] == "-" then --surnames don't really have gender
		table.insert(categories, "ヘブライ語 固有名詞 性無し")
	else
		table.insert(genders, "?")
	end
end

local binyanim = {
	["pa"] = "パアル",
	["pi"] = "ピエル",
	["hif"] = "ヒフィル",
	["hit"] = "ヒトパエル",
	["huf"] = "フファル",
	["pu"] = "プアル",
	["nif"] = "ニファル",
	["hitpu'al"] = "hitpu'al", -- should this be included?
}

local weakroots = {
	["פ"] = {
		["א"] = true,
		["ה"] = true,
		["ח"] = true,
		["י"] = true,
		["ל"] = true,
		["נ"] = true,
		["ע"] = true,
	},
	["ע"] = {
		["א"] = true,
		["ה"] = true,
		["ו"] = true,
		["ח"] = true,
		["י"] = true,
		["ע"] = true,
		["ר"] = true,
	},
	["ל"] = {
		["א"] = true,
		["ה"] = true,
		["ח"] = true,
		["נ"] = true,
		["ע"] = true,
	},
}

local function maybe_get_weakcat(args, pos, binyan)
	if weakroots[pos][args[pos]] then
		if binyan then
			return "Hebrew " .. pos .. "״" .. args[pos] .. " " .. binyan .. " verbs"
		else
			return "Hebrew " .. pos .. "״" .. args[pos] .. " verbs"
		end
	else
		return nil -- perhaps track error if args[pos] ~= ""
	end
end

pos_functions["verbs"] = function(args, genders, inflections, categories)
	local binyan = binyanim[args[1]]
	if binyan then
		table.insert(inflections, { label="" .. binyan .. " constructionp" })
		table.insert(categories, "ヘブライ語 " .. binyanim[args[1]] .. " verbs")
	elseif args[1] ~= "-" then
		table.insert(categories, "Hebrew verbs lacking binyan")
	end
	table.insert(categories, maybe_get_weakcat(args, "פ", binyan))
	table.insert(categories, maybe_get_weakcat(args, "ע", binyan))
	table.insert(categories, maybe_get_weakcat(args, "ל", binyan))
	table.insert(inflections, maybe_get_inflection(args, "不定詞", "inf", true))
	table.insert(inflections, maybe_get_inflection(args, "現在", "pres", true))
	table.insert(inflections, maybe_get_inflection(args, "未来", "fut", true))
	table.insert(inflections, maybe_get_inflection(args, "命令", "imp", true))
	table.insert(inflections, maybe_get_inflection(args, "受動分詞", "passp", true))
	table.insert(inflections, maybe_get_inflection(args, "passive counterpart", "pass", true))
	table.insert(inflections, maybe_get_inflection(args, "active counterpart", "act", true))
end

return export