モジュール:sl-headword

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

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

local m_common = require("モジュール:sl-common")

local export = {}

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

local pos_functions = {}

-- 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 poscat = frame.args[1] or error("品詞が指定されていません。パラメータ1をモジュールの呼び出しに与えて下さい。")
	
	local genders = {}
	local inflections = {}
	local categories = {"スロヴェニア語 " .. poscat}
	
	-- Gather headwords
	local head = args[1]
	local heads = {head or ""}
	local i = 2
	head = args["head" .. i]
	
	while head do
		if head ~= "" then
			table.insert(heads, head)
		end
		
		i = i + 1
		head = args["head" .. i]
	end
	
	-- Process headwords for accents
	local check_accents = true
	
	-- If the first headword given is "-", then skip the check.
	if heads[1] == "-" then
		heads[1] = ""
		check_accents = false
	else
		for i, head in ipairs(heads) do
			if head == "" or not m_common.has_accents(head) then
				table.insert(categories, "スロヴェニア語 アクセント未記載")
			end
		end
	end
	
	-- Call POS-specific function
	if pos_functions[poscat] then
		pos_functions[poscat](args, heads, genders, inflections, categories, check_accents)
	end
	
	return require("モジュール:headword").full_headword{
		lang = lang,
		heads = heads,
		genders = genders,
		inflections = inflections,
		categories = categories,
	}
end

-- Display additional inflection information for an adjective
pos_functions["adjectives"] = function(args, heads, genders, inflections, categories, check_accents)
	-- Get all the parameters
	local comparatives = {}
	
	local i = 2
	
	while true do
		local comp = args[i]; if comp == "" then comp = nil end
		
		if not comp then
			break
		end
		
		table.insert(comparatives, comp)
		i = i + 1
	end
	
	-- Decide what to do next...
	local mode = comparatives[1]
	
	if mode == "-" then
		table.insert(inflections, {label = "比較形なし"})
	else
		do_comparatives(heads, inflections, categories, comparatives, check_accents)
	end
end

-- Display additional inflection information for an adverb
pos_functions["adverbs"] = function(args, heads, genders, inflections, categories, check_accents)
	-- Get all the parameters
	local comparatives = {}
	
	local i = 2
	
	while true do
		local comp = args[i]; if comp == "" then comp = nil end
		
		if not comp then
			break
		end
		
		table.insert(comparatives, comp)
		i = i + 1
	end
	
	-- Decide what to do next...
	local mode = comparatives[1]
	
	if mode and mode ~= "-" then
		do_comparatives(heads, inflections, categories, comparatives, check_accents)
	end
end

function do_comparatives(heads, inflections, categories, comparatives, check_accents)
	local encoded_head = ""
	
	if heads[1] ~= "" then
		-- This is decoded again by [[WT:ACCEL]].
		encoded_head = " origin-" .. heads[1]:gsub("%%", "."):gsub(" ", "_")
	end
	
	local comp_parts = {label = "[[比較級]]", accel = "comparative-form-of" .. encoded_head, request = true}
	local sup_parts = {label = "[[最上級]]", accel = "superlative-form-of" .. encoded_head}
	
	for i, comp in ipairs(comparatives) do
		if comp == "bolj" then
			table.insert(comp_parts, "[[bòlj]] " .. (heads[1] ~= "" and heads[1] or PAGENAME))
			table.insert(sup_parts, "[[nàjbolj]] " .. (heads[1] ~= "" and heads[1] or PAGENAME))
		else
			table.insert(comp_parts, comp)
			table.insert(sup_parts, "nàj" .. comp)
			
			if check_accents and not m_common.has_accents(comp) then
				table.insert(categories, "スロヴェニア語 アクセント未記載")
			end
		end
	end
	
	table.insert(inflections, comp_parts)
	table.insert(inflections, sup_parts)
end

-- Display additional inflection information for a noun
pos_functions["nouns"] = function(args, heads, genders, inflections, categories, check_accents)
	pos_functions["proper nouns"](args, heads, genders, inflections, categories, check_accents)
	
	-- If the noun is a duale/plurale tantum, then ignore the 4th parameter altogether
	local num = genders[1]:sub(3,3)
	
	if num == "d" then
		table.insert(inflections, {label = "[[絶対双数]]"})
	elseif num == "p" then
		table.insert(inflections, {label = "[[絶対複数]]"})
	else
		-- Get the plural parameters
		-- First get the 4th parameter. The remainder is named pl2=, pl3= etc.
		local form = args[4]; if form == "" then form = nil end
		local plurals = {form}
		local i = 2
		
		while true do
			form = args["pl" .. i]; if form == "" then form = nil end
			
			if not form then
				break
			end
			
			table.insert(plurals, form)
			i = i + 1
		end
		
		-- Decide what to do next...
		local mode = plurals[1]
		
		if mode == "-" then
			table.insert(inflections, {label = "不可算"})
			table.insert(categories, "スロヴェニア語 不可算名詞")
		else
			plurals.label = "複数主格"
			plurals.request = true
			
			for i, form in ipairs(plurals) do
				if check_accents and not m_common.has_accents(form) then
					table.insert(categories, "スロヴェニア語 名詞 アクセント未記載")
				end
			end
			
			table.insert(inflections, plurals)
		end
	end
	
	-- Get the feminine parameters
	-- First get the f= parameter. The remainder is named f2=, f3= etc.
	local form = args["f"]; if form == "" then form = nil end
	local feminines = {form}
	local i = 2
	
	while true do
		form = args["f" .. i]; if form == "" then form = nil end
		
		if not form then
			break
		end
		
		table.insert(feminines, form)
		i = i + 1
	end
	
	if #feminines > 0 then
		local f_parts = {label = "女性"}
		
		for i, form in ipairs(feminines) do
			table.insert(f_parts, form)
			
			if check_accents and not m_common.has_accents(form) then
				table.insert(categories, "スロヴェニア語 名詞 アクセント未記載")
			end
		end
		
		table.insert(inflections, f_parts)
	end

	-- Get the masculine parameters
	-- First get the m= parameter. The remainder is named m2=, m3= etc.
	local form = args["m"]; if form == "" then form = nil end
	local masculines = {form}
	local i = 2
	
	while true do
		form = args["m" .. i]; if form == "" then form = nil end
		
		if not form then
			break
		end
		
		table.insert(masculines, form)
		i = i + 1
	end
	
	if #masculines > 0 then
		local m_parts = {label = "男性"}
		
		for i, form in ipairs(masculines) do
			table.insert(m_parts, form)
			
			if check_accents and not m_common.has_accents(form) then
				table.insert(categories, "スロヴェニア語 名詞 アクセント未記載")
			end
		end
		
		table.insert(inflections, m_parts)
	end
end

-- Display additional inflection information for a proper noun
-- This is also used for nouns
pos_functions["proper nouns"] = function(args, heads, genders, inflections, categories, check_accents)
	local valid_genders = {
		["m-?"] = true,
		["m-an"] = true,
		["m-in"] = true,
		["f"] = true,
		["n"] = true,
		["m-d"] = true,
		["f-d"] = true,
		["n-d"] = true,
		["m-p"] = true,
		["f-p"] = true,
		["n-p"] = true }
	
	-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
	local g = args[2]; if g == "" then g = nil end
	local i = 2
	
	while g do
		if g == "m" then g = "m-?" end
		
		if not valid_genders[g] then
			g = "?"
		end
		
		table.insert(genders, g)
		
		-- Categorize by gender
		if g == "m-an" then
			table.insert(categories, "スロヴェニア語 男性名詞")
			table.insert(categories, "スロヴェニア語 男性名詞 活動体")
		elseif g == "m-in" then
			table.insert(categories, "スロヴェニア語 男性名詞")
			table.insert(categories, "スロヴェニア語 男性名詞 不活動体")
		elseif g:sub(1,1) == "m" then
			table.insert(categories, "スロヴェニア語 男性名詞")
		elseif g:sub(1,1) == "f" then
			table.insert(categories, "スロヴェニア語 女性名詞")
		elseif g:sub(1,1) == "n" then
			table.insert(categories, "スロヴェニア語 中性名詞")
		end
		
		-- Categorize by number
		if g:sub(3,3) == "d" then
			table.insert(categories, "スロヴェニア語 絶対双数")
		elseif g:sub(3,3) == "p" then
			table.insert(categories, "スロヴェニア語 絶対複数")
		end
		
		g = args["g" .. i]; if g == "" then g = nil end
		i = i + 1
	end
	
	if #genders == 0 then
		table.insert(genders, "?")
	elseif #genders > 1 then
		table.insert(categories, "スロヴェニア語 複数の性を持つ名詞")
	end
	
	-- Get the genitive parameters
	-- First get the 3rd parameter. The remainder is named gen2=, gen3= etc.
	local form = args[3]; if form == "" then form = nil end
	local genitives = {form}
	local i = 2
	
	while true do
		form = args["gen" .. i]; if form == "" then form = nil end
		
		if not form then
			break
		end
		
		table.insert(genitives, form)
		i = i + 1
	end
	
	-- Show the forms
	genitives.label = "属格"
	genitives.request = true
	
	for i, form in ipairs(genitives) do
		if check_accents and not m_common.has_accents(form) then
			table.insert(categories, "スロヴェニア語 名詞 アクセント未記載")
		end
	end

	table.insert(inflections, genitives)
end

-- Display additional inflection information for a verb
pos_functions["verbs"] = function(args, heads, genders, inflections, categories, check_accents)
	-- Aspect
	local aspect = args[2]; if aspect == "" then aspect = nil end
	
	if aspect == "impf" then
		table.insert(genders, "impf")
		table.insert(categories, "スロヴェニア語 動詞 不完了体")
	elseif aspect == "pf" then
		table.insert(genders, "pf")
		table.insert(categories, "スロヴェニア語 動詞 完了体")
	elseif aspect == "both" then
		table.insert(genders, "impf")
		table.insert(genders, "pf")
		table.insert(categories, "スロヴェニア語 動詞 不完了体")
		table.insert(categories, "スロヴェニア語 動詞 完了体")
	else
		table.insert(genders, "?")
		table.insert(categories, "スロヴェニア語 動詞 相未記")
	end
	
	-- Get all the parameters
	-- First get the 3rd and 4th parameters. The remainder is named pres2=, past2= etc.
	local pres = args[3]; if pres == "" then pres = nil end
	local past = args[4]; if past == "" then past = nil end
	local presents = {pres}
	local pasts = {past}
	local i = 2
	
	while true do
		pres = args["pres" .. i]; if pres == "" then pres = nil end
		past = args["past" .. i]; if past == "" then past = nil end
		
		if not pres and not past then
			break
		end
		
		if pres then table.insert(presents, pres) end
		if past then table.insert(pasts, past) end
		i = i + 1
	end
	
	-- Present tense (1st person singular)
	presents.label = "現在第一人称単数形"
	presents.request = true
	
	for i, form in ipairs(presents) do
		if check_accents and not m_common.has_accents(form) then
			table.insert(categories, "スロヴェニア語 動詞 アクセント未記載")
		end
	end
	
	table.insert(inflections, presents)
	
	-- Past tense (past active participle / l-participle)
	pasts.label = "能動過去分詞"
	
	for i, form in ipairs(pasts) do
		if check_accents and not m_common.has_accents(form) then
			table.insert(categories, "スロヴェニア語 動詞 アクセント未記載")
		end
	end
		
	table.insert(inflections, pasts)
end

return export