モジュール:nl-headword

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

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

local export = {}
local pos_functions = {}

local lang = require'モジュール:languages'.getByCode'nl'

-- 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
	PAGENAME = mw.title.getCurrentTitle().text
	
	local head = args["head"]; if head == "" then head = nil end
	
	-- The part of speech. This is also the name of the category that
	-- entries go in. However, the two are separate (the "cat" parameter)
	-- because you sometimes want something to behave as an adjective without
	-- putting it in the adjectives category.
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	local cat = args["cat"]; if cat == "" then cat = nil end
	
	local genders = {}
	local inflections = {}
	local categories = {"オランダ語 " .. (cat or poscat)}
	local tracking_categories = {}
	
	if pos_functions[poscat] then
		pos_functions[poscat](args, genders, inflections, categories, tracking_categories)
	end
	
	return require("モジュール:headword").full_headword{
		lang = lang,
		heads = {head},
		translit = {tr},
		genders = genders,
		inflections = inflections,
		categories = categories,
	} ..
		require("モジュール:utilities").format_categories(tracking_categories, lang, nil)
end

-- Display additional inflection information for an adjective
pos_functions["adjectives"] = function(args, genders, inflections, categories, tracking_categories)
	local shift = 0
	local mode = args[1]
	
	if mode == "inv" then
		table.insert(inflections, {label = "不変化"})
		shift = 1
	elseif mode == "pred" then
		table.insert(inflections, {label = "述詞のみ"})
		shift = 1
	end
	
	local comp_mode = args[1 + shift]
	
	if comp_mode == "-" then
		table.insert(inflections, {label = "比較形なし"})
	else
		-- Gather parameters
		local comparatives = {label = "比較級"}
		local p = args[1 + shift]; if p == "" then p = nil end
		local i = 1
		
		while p do
			table.insert(comparatives, p)
			i = i + 1
			p = args["comp" .. i]; if p == "" then p = nil end
		end
		
		local superlatives = {label = "最上級"}
		local p = args[2 + shift]; if p == "" then p = nil end
		local i = 1
		
		while p do
			table.insert(superlatives, p)
			i = i + 1
			p = args["sup" .. i]; if p == "" then p = nil end
		end
		
		-- Generate forms if none were given
		if #comparatives == 0 then
			if mode == "inv" or mode == "pred" then
				table.insert(comparatives, "peri")
			else
				table.insert(comparatives, require("モジュール:nl-adjective").make_comparative(PAGENAME))
			end
		end
		
		if #superlatives == 0 then
			if mode == "inv" or mode == "pred" then
				table.insert(superlatives, "peri")
			else
				-- Add preferred periphrastic superlative, if necessary
				if
					PAGENAME:find("[iï]de$") or PAGENAME:find("[^eio]e$") or
					PAGENAME:find("s$") or PAGENAME:find("sch$") or PAGENAME:find("x$") or
					PAGENAME:find("sd$") or PAGENAME:find("st$") or PAGENAME:find("sk$") then
					table.insert(superlatives, "peri")
				end
				
				table.insert(superlatives, require("モジュール:nl-adjective").make_superlative(PAGENAME))
			end
		end
		
		-- Replace "peri" with phrase
		for key, val in ipairs(comparatives) do
			if val == "peri" then comparatives[key] = "[[meer]] " .. PAGENAME end
		end
		
		for key, val in ipairs(superlatives) do
			if val == "peri" then superlatives[key] = "[[meest]] " .. PAGENAME end
		end
		
		table.insert(inflections, comparatives)
		table.insert(inflections, superlatives)
	end
end

-- Display additional inflection information for an adverb
pos_functions["adverbs"] = function(args, genders, inflections, categories, tracking_categories)
	local comp = args[1]; if comp == "" then comp = nil end
	local sup = args[2]; if sup == "" then sup = nil end
	
	if comp then
		if not sup then
			sup = PAGENAME .. "st"
		end
		
		table.insert(inflections, {label = "比較級", comp})
		table.insert(inflections, {label = "最上級", sup})
	end
end

-- Display information for a noun's gender
-- This is separate so that it can also be used for proper nouns
function noun_gender(args, genders, inflections, categories, tracking_categories)
	-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
	local g = args[1]; if g == "" then g = nil end
	local i = 2
	
	while g do
		if g == "c" then
			table.insert(categories, "オランダ語 通性名詞")
		elseif g == "p" then
			table.insert(categories, "オランダ語 絶対複数")
		elseif g ~= "m" and g ~= "f" and g ~= "n" then
			g = nil
		end
		
		table.insert(genders, g)
		g = args["g" .. i]; if g == "" then g = nil end
		i = i + 1
	end
	
	if #genders == 0 then
		table.insert(genders, "?")
	end
	
	-- Most nouns that are listed as f+m should really have only f
	if genders[1] == "f" and genders[2] == "m" then
		table.insert(categories, "Dutch nouns with f+m gender")
	end
end

pos_functions["proper nouns"] = function(args, genders, inflections, categories, tracking_categories)
	noun_gender(args, genders, inflections, categories, tracking_categories)
end

-- Display additional inflection information for a noun
pos_functions["nouns"] = function(args, genders, inflections, categories, tracking_categories)
	noun_gender(args, genders, inflections, categories, tracking_categories)
	
	-- Gather all the plural parameters
	local plurals = {}
	local p = args[2]; if p == "" then p = nil end
	local i = 2
	
	while p do
		table.insert(plurals, p)
		
		p = args["pl" .. i]; if p == "" then p = nil end
		i = i + 1
	end
	
	-- Gather all the diminutive parameters
	local diminutives = {}
	local p = args[3]; if p == "" then p = nil end
	local i = 2
	
	while p do
		table.insert(diminutives, p)
		
		p = args["dim" .. i]; if p == "" then p = nil end
		i = i + 1
	end
	
	-- Gather all the feminine parameters
	local feminines = {}
	local p = args["f"]; if p == "" then p = nil end
	local i = 2
	
	while p do
		table.insert(feminines, p)
		
		p = args["f" .. i]; if p == "" then p = nil end
		i = i + 1
	end
	
	-- Gather all the masculine parameters
	local masculines = {}
	local p = args["m"]; if p == "" then p = nil end
	local i = 2
	
	while p do
		table.insert(masculines, p)
		
		p = args["m" .. i]; if p == "" then p = nil end
		i = i + 1
	end
	
	-- Plural
	if genders[1] == "p" then
		table.insert(inflections, {label = "絶対複数"})
	elseif #plurals == 0 then
		table.insert(inflections, "<small><sup>???</sup> 複数形を入力して下さい</small>")
		table.insert(categories, "オランダ語 名詞 曲用未入力")
	elseif plurals[1] == "-" then
		table.insert(inflections, {label = "不可算"})
		table.insert(categories, "オランダ語 不可算名詞")
	else
		local generated = generate_plurals(PAGENAME)
		
		-- Process the plural forms
		for i, p in ipairs(plurals) do
			-- Is this a shortcut form?
			if p:sub(1,1) == "-" then
				if not generated[p] then
					error("The shortcut plural " .. p .. " could not be generated.")
				end
				
				if p:sub(-2) == "es" then
					table.insert(categories, "Dutch nouns with plural in -es")
				elseif p:sub(-1) == "s" then
					table.insert(categories, "Dutch nouns with plural in -s")
				elseif p:sub(-4) == "eren" then
					table.insert(categories, "Dutch nouns with plural in -eren")
				else
					table.insert(categories, "Dutch nouns with plural in -en")
				end
				
				if p:sub(2,2) == ":" then
					table.insert(categories, "Dutch nouns with lengthened vowel in the plural")
				end
				
				p = generated[p]
			-- Not a shortcut form, but the plural form specified directly.
			else
				local matches = {}
				
				for pi, g in pairs(generated) do
					if g == p then
						table.insert(matches, pi)
					end
				end
				
				if #matches > 0 then
					table.insert(tracking_categories, "nl-noun plural matches generated form")
				elseif not PAGENAME:find("[ -]") then
					if p == PAGENAME then
						table.insert(categories, "オランダ語 不変化名詞")
					elseif
						p == PAGENAME .. "den" or p == PAGENAME:gsub("ee$", "eden") or
						p == PAGENAME .. "des" or p == PAGENAME:gsub("ee$", "edes") then
						table.insert(categories, "Dutch nouns with plural in -den")
					elseif p == PAGENAME:gsub("([ao])$", "%1%1ien") or p == PAGENAME:gsub("oe$", "oeien") then
						table.insert(categories, "Dutch nouns with glide vowel in plural")
					elseif p == PAGENAME:gsub("y$", "ies") then
						table.insert(categories, "Dutch nouns with English plurals")
					elseif
						p == PAGENAME:gsub("a$", "ae") or
						p == PAGENAME:gsub("[ei]x$", "ices") or
						p == PAGENAME:gsub("is$", "es") or
						p == PAGENAME:gsub("men$", "mina") or
						p == PAGENAME:gsub("ns$", "ntia") or
						p == PAGENAME:gsub("o$", "ones") or
						p == PAGENAME:gsub("o$", "onen") or
						p == PAGENAME:gsub("s$", "tes") or
						p == PAGENAME:gsub("us$", "era") or
						p == mw.ustring.gsub(PAGENAME, "[uü]s$", "i") or
						p == mw.ustring.gsub(PAGENAME, "[uü]m$", "a") or
						p == PAGENAME:gsub("x$", "ges") then
						table.insert(categories, "Dutch nouns with Latin plurals")
					elseif
						p == PAGENAME:gsub("os$", "oi") or
						p == PAGENAME:gsub("on$", "a") or
						p == PAGENAME:gsub("a$", "ata") then
						table.insert(categories, "Dutch nouns with Greek plurals")
					else
						table.insert(categories, "オランダ語 不規則名詞")
					end
				end
			end
			
			plurals[i] = p
		end
		
		-- Add the plural forms
		plurals.label = "plural"
		plurals.accel = "plural-form-of"
		table.insert(inflections, plurals)
	end
	
	-- Add the diminutive forms
	if diminutives[1] == "-" then
		-- do nothing
	elseif #diminutives == 0 then
		table.insert(inflections, "<small><sup>???</sup> [[指小辞]]を入力して下さい</small>")
		table.insert(categories, "オランダ語 名詞 活用形未入力")
	else
		-- Process the diminutive forms
		for i, p in ipairs(diminutives) do
			diminutives[i] = {term = p, genders = {"n"}}
		end
		
		diminutives.label = "[[指小辞]]"
		diminutives.accel = "diminutive-form-of"
		table.insert(inflections, diminutives)
	end
	
	-- Add the feminine forms
	if #feminines > 0 then
		feminines.label = "女性"
		table.insert(inflections, feminines)
	end
	
	-- Add the masculine forms
	if #masculines > 0 then
		masculines.label = "男性"
		table.insert(inflections, masculines)
	end
end

function generate_plurals(PAGENAME)
	local m_common = require("モジュール:nl-common")
	local generated = {}
	
	generated["-s"] = PAGENAME .. "s"
	generated["-'s"] = PAGENAME .. "'s"
	
	local stem_FF = m_common.add_e(PAGENAME, false, false)
	local stem_TF = m_common.add_e(PAGENAME, true, false)
	local stem_FT = m_common.add_e(PAGENAME, false, true)
	
	generated["-es"] = stem_FF .. "s"
	generated["-@es"] = stem_TF .. "s"
	generated["-:es"] = stem_FT .. "s"
	
	generated["-en"] = stem_FF .. "n"
	generated["-@en"] = stem_TF .. "n"
	generated["-:en"] = stem_FT .. "n"
	
	generated["-eren"] = m_common.add_e(PAGENAME .. (PAGENAME:find("n$") and "d" or ""), false, false) .. "ren"
	generated["-:eren"] = stem_FT .. "ren"
	
	if PAGENAME:find("f$") then
		local stem = PAGENAME:gsub("f$", "v")
		local stem_FF = m_common.add_e(stem, false, false)
		local stem_TF = m_common.add_e(stem, true, false)
		local stem_FT = m_common.add_e(stem, false, true)
		
		generated["-ves"] = stem_FF .. "s"
		generated["-@ves"] = stem_TF .. "s"
		generated["-:ves"] = stem_FT .. "s"
		
		generated["-ven"] = stem_FF .. "n"
		generated["-@ven"] = stem_TF .. "n"
		generated["-:ven"] = stem_FT .. "n"
		
		generated["-veren"] = stem_FF .. "ren"
		generated["-:veren"] = stem_FT .. "ren"
	elseif PAGENAME:find("s$") then
		local stem = PAGENAME:gsub("s$", "z")
		local stem_FF = m_common.add_e(stem, false, false)
		local stem_TF = m_common.add_e(stem, true, false)
		local stem_FT = m_common.add_e(stem, false, true)
		
		generated["-zes"] = stem_FF .. "s"
		generated["-@zes"] = stem_TF .. "s"
		generated["-:zes"] = stem_FT .. "s"
		
		generated["-zen"] = stem_FF .. "n"
		generated["-@zen"] = stem_TF .. "n"
		generated["-:zen"] = stem_FT .. "n"
		
		generated["-zeren"] = stem_FF .. "ren"
		generated["-:zeren"] = stem_FT .. "ren"
	elseif PAGENAME:find("heid$") then
		generated["-heden"] = PAGENAME:gsub("heid$", "heden")
	end
	
	return generated
end

pos_functions["past participles"] = function(args, genders, inflections, categories, tracking_categories)
	if args[1] == "-" then
		table.insert(inflections, {label = "not used adjectivally"})
		table.insert(categories, "Dutch non-adjectival past participles")
	end
end

pos_functions["verbs"] = function(args, genders, inflections, categories, tracking_categories)
	local past_sg = args[1]; if past_sg == "" then past_sg = nil end
	local past_ptc = args[2]; if past_ptc == "" then past_ptc = nil end
	local is_plural = args["pl"]; if is_plural == "" then is_plural = nil end  -- Used for reciprocal verbs (with "elkaar"), which can only be conjugated in plural
	
	-- Past singular
	if past_sg == "-" then
		table.insert(inflections, {label = "not inflected"})
		table.insert(categories, "Dutch uninflected verbs")
	elseif not past_sg then
		table.insert(inflections, "<small><sup>???</sup> 過去" .. (is_plural and "複数形" or "単数形") .. "を入力して下さい</small>")
		table.insert(categories, "オランダ語 動詞 活用形未入力")
	else
		local infl_parts = {label = "過去" .. (is_plural and "複数形" or "単数形")}
		local past_sg2 = args["past_sg2"]; if past_sg2 == "" then past_sg2 = nil end
		
		table.insert(infl_parts, past_sg)
		
		if past_sg2 then
			table.insert(infl_parts, past_sg2)
		end
		
		table.insert(inflections, infl_parts)
	end
	
	-- Past participle
	if past_ptc == "-" then
		table.insert(inflections, {label = "過去分詞なし"})
	elseif not past_ptc then
		table.insert(inflections, "<small><sup>???</sup> 過去分詞を入力して下さい</small>")
		table.insert(categories, "オランダ語 動詞 活用形未入力")
	else
		local infl_parts = {label = "過去分詞"}
		local past_ptc2 = args["past_ptc2"]; if past_ptc2 == "" then past_ptc2 = nil end
		
		table.insert(infl_parts, past_ptc)
		
		if past_ptc2 then
			table.insert(infl_parts, past_ptc2)
		end
		
		table.insert(inflections, infl_parts)
	end
end

return export