モジュール:la-adj

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

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

local export = {}

local lang = require("モジュール:languages").getByCode("la")
local m_links = require("モジュール:links")
local m_utilities = require("モジュール:utilities")

NAMESPACE = NAMESPACE or mw.title.getCurrentTitle().nsText
PAGENAME = PAGENAME or mw.title.getCurrentTitle().text

local decl = require("モジュール:la-adj/data")
local m_table = require("モジュール:la-adj/table")

local case_order = {
	"nom_sg_m",
	"gen_sg_m",
	"dat_sg_m",
	"acc_sg_m",
	"abl_sg_m",
	"voc_sg_m",
	"nom_sg_f",
	"gen_sg_f",
	"dat_sg_f",
	"acc_sg_f",
	"abl_sg_f",
	"voc_sg_f",
	"nom_sg_n",
	"gen_sg_n",
	"dat_sg_n",
	"acc_sg_n",
	"abl_sg_n",
	"voc_sg_n",
	"nom_pl_m",
	"gen_pl_m",
	"dat_pl_m",
	"acc_pl_m",
	"abl_pl_m",
	"voc_pl_m",
	"nom_pl_f",
	"gen_pl_f",
	"dat_pl_f",
	"acc_pl_f",
	"abl_pl_f",
	"voc_pl_f",
	"nom_pl_n",
	"gen_pl_n",
	"dat_pl_n",
	"acc_pl_n",
	"abl_pl_n",
	"voc_pl_n",
}

local function process(data, args)
	local noteindex = 1
	local notes = {}
	local redlink = false
	if data.num == "pl" then
		table.insert(data.categories, "ラテン語 形容詞 複数形のみ")
	end
	for _, key in ipairs(case_order) do
		if args[key] or data.forms[key] then
			local user_specified = false
			if args[key] then
				val = args[key]
				user_specified = true
			else
				val = data.forms[key]
			end
			if type(val) == "string" then
				val = mw.text.split(val,"/")
			end
			if data.num == "pl" and key:find("sg") then
				data.forms[key] = ""
			elseif val[1] == "" or val == "" or val == {""} or val[1] == "-" or val[1] == "—" or val == "-" or val == "—" then
				data.forms[key] = "—"
			else
				for i,form in ipairs(val) do
					local word = data.prefix .. form .. data.suffix
					if data.notes[key .. i] and not user_specified then
						val[i] = m_links.full_link({lang = lang, term = word}) .. '<sup style="color: red">' .. noteindex .. '</sup>'
						table.insert(notes, '<sup style="color: red">' .. noteindex .. '</sup>' .. data.notes[key .. i])
						noteindex = noteindex+1
					else
						val[i] = m_links.full_link({lang = lang, term = word})
					end
					if not redlink and NAMESPACE == '' then
						local title = lang:makeEntryName(word)
						local t = mw.title.new(title)
						if t and not t.exists then
							table.insert(data.categories,'ラテン語 活用表に赤リンクを含む形容詞')
							redlink = true
						end
					end
				end
				data.forms[key] = table.concat(val, ", ")
			end
		end
	end
	data.footnote = table.concat(notes, "<br />") .. data.footnote
end

function export.show(frame)
	local data = {
		title = "",
		footnote = "",
		num = "",
		voc = true,
		forms = {},
		categories = {},
		notes = {},
	}

	local args = frame:getParent().args
	local iargs = frame.args
	
	data.subtype = iargs["type"] or args["type"] or ""
	data.num = iargs["num"] or args["num"] or ""
	data.prefix = args["prefix"] or ""
	data.suffix = args["suffix"] or ""
	
	decl[iargs[1]](data, args)
	
	process(data, args)
	
	if data.prefix .. data.suffix ~= "" then
		table.insert(data.categories, "Kenny's testing category 6")
	end
	
	return m_table.make_table(data) .. m_utilities.format_categories(data.categories, lang)
end

return export