モジュール:es-headword

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

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

local export = {}
local pos_functions = {}

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

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	PAGENAME = mw.title.getCurrentTitle().text
	
	local poscat = frame.args[1] or error("品詞が指定されていません。パラメータ1をモジュールの呼び出しに渡して下さい。")
	
	local params = {
		["head"] = {list = true, default = ""},
		["suff"] = {type = "boolean"},
	}
	
	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(frame:getParent().args, params)
	local data = {heads = args["head"], genders = {}, inflections = {}, categories = {}}
	
	if args["suff"] then
		table.insert(data.categories, lang:getCanonicalName() .. " suffixes")
		
		if poscat == "形容詞" then
			table.insert(data.categories, lang:getCanonicalName() .. " adjective-forming suffixes")
		elseif poscat == "副詞" then
			table.insert(data.categories, lang:getCanonicalName() .. " adverb-forming suffixes")
		elseif poscat == "名詞" then
			table.insert(data.categories, lang:getCanonicalName() .. " noun-forming suffixes")
		elseif poscat == "動詞" then
			table.insert(data.categories, lang:getCanonicalName() .. " verb-forming suffixes")
		else
			error("No category exists for suffixes forming " .. poscat .. ".")
		end
	else
		table.insert(data.categories, lang:getCanonicalName() .. " " .. poscat)
	end
	
	if pos_functions[poscat] then
		pos_functions[poscat].func(args, data)
	end
	
	return require("モジュール:headword").full_headword(lang, nil, data.heads, nil, data.genders, data.inflections, data.categories, nil)
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, data)
	local categories = {}
	
	local gender = args[1]
	
	if gender == "m-p" or gender == "f-p" then
		table.insert(data.categories, "スペイン語 絶対複数")
	end
	
	if gender == "mf" then
		table.insert(data.genders, "m")
		table.insert(data.genders, "f")
	else
		table.insert(data.genders, gender)
	end
 
	if #data.genders == 0 then
		table.insert(data.genders, "?")
	end
end

pos_functions["固有名詞"] = {
	params = {
		[1] = {},
		},
	func = function(args, data)
		noun_gender(args, genders, inflections, categories)
	end
}

-- Display additional inflection information for a noun
pos_functions["名詞"] = {
	params = {
		[1] = {},
		[2] = {},
		["pl2"] = {},
		["f"] = {},
		["fpl"] = {},
		["m"] = {},
		["m2"] = {},
		["mpl"] = {},
		},
	func = function(args, data)
		noun_gender(args, data)
		
		-- Plural
		if data.genders[1] == "m-p" or data.genders[1] == "f-p" then
			table.insert(data.inflections, {label = "[[絶対複数]]"})
		else
			local plural = args[2]
			
			if plural == "-" then
				table.insert(data.inflections, {label = "[[不可算名詞|不可算]]"})
				table.insert(data.categories, "スペイン語 不可算名詞")
			else
				local infl_parts = {label = "複数", accel = "plural-form-of"}
				local plural2 = args["pl2"]
				
				if not plural or plural == "s" then
					plural = PAGENAME .. "s"
				elseif plural == "es" then
					plural = PAGENAME .. "es"
				end
				
				table.insert(infl_parts, plural)
				
				if plural2 then
					table.insert(infl_parts, plural2)
				end
				
				if plural and not mw.title.new(plural).exists then
					table.insert(data.categories, "スペイン語 名詞 複数形未作成")
				end
				if plural2 and not mw.title.new(plural2).exists then
					table.insert(data.categories, "スペイン語 名詞 複数形未作成")
				end
	
				table.insert(data.inflections, infl_parts)
			end
		end
		
		-- Gendered forms
		local feminine = args["f"]
		local feminine_pl = args["fpl"]
		local masculine = args["m"]
		local masculine2 = args["m2"]
		local masculine_pl = args["mpl"]
	 
		if feminine then
			table.insert(data.inflections, {label = "女性", feminine})
			if not mw.title.new(feminine).exists then
				table.insert(data.categories, "スペイン語 名詞 定形未作成")
			end
		end
		
		if feminine_pl then
			table.insert(data.inflections, {label = "女性複数", feminine_pl})
			if not mw.title.new(feminine_pl).exists then
				table.insert(data.categories, "スペイン語 名詞 定形未作成")
			end
		end
	 	
		if masculine then
			table.insert(data.inflections, {label = "男性", masculine, masculine2})
			if not mw.title.new(masculine).exists then
				table.insert(data.categories, "スペイン語 名詞 定形未作成")
			end
		end
		
		if masculine_pl then
			table.insert(data.inflections, {label = "男性複数", masculine_pl})
			if not mw.title.new(masculine_pl).exists then
				table.insert(data.categories, "スペイン語 名詞 定形未作成")
			end
		end
	end
}

function make_plural(base, gender)
	return base .. "s"
end

return export