モジュール:mn-headword

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

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

local export = {}

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

local params = {
	["head"] = {}, --with no diacritics I don't think we'll need more than one head
	["cat"] = {list = true},
	[1] = {list = true}
}

local function get_script(args) 
	return m_scripts.findBestScript(args["head"] or mw.title.getCurrentTitle().subpageText, lang)
end
	
local function otherscript(inflections, args, sc, categories)
	if #args[1] < 1 then
		if sc then
			if sc:getCode() == "Mong" then
				table.insert(categories, "モンゴル語 キリル文字表記未入力")
			elseif sc:getCode() == "Cyrl" then
				table.insert(categories, "モンゴル語 モンゴル文字表記未入力")
			end
		end
		return 
	end

	local other_sc
	
	local scripts = {
		m = "Mong",
		c = "Cyrl",
		Mong = true,
		Cyrl = true,
	}
	if scripts[args[1][1]] then
		other_sc =  m_scripts.getByCode(scripts[args[1][1]])
		table.remove(args[1], 1)
		require("モジュール:debug").track("mn-headword/script-param")
	else
		other_sc = m_scripts.findBestScript(args[1][1], lang)
	end
	
	if sc and sc:getCode() == other_sc:getCode() then
		error("The headword and the alternative spelling should be in different scripts.")
	end
	
	if not scripts[other_sc:getCode()] then
		error("Mongolian entries in " .. other_sc:getCanonicalName() .. " script are not currently allowed.")
	end
	
	local spelling = {label = other_sc:getCanonicalName(), sc = other_sc, enable_auto_translit=true}
	
	for i, arg in ipairs(args[1]) do
		table.insert(spelling, arg)
	end
	
	table.insert(inflections, spelling)
end

local function categorize(cats)
	if cats == nil then
		return nil
	end
	local categories = {}
	for i, arg in ipairs(cats) do
		table.insert(categories, lang:getCanonicalName() .. " " .. arg)
	end
	return categories
end

function export.basic(frame)
	
	local args = require("モジュール:parameters").process(frame:getParent().args, params)
	
	local inflections = {}
	local categories = categorize(args["cat"])
	
	local sc = get_script(args)
	
	otherscript(inflections, args, sc, categories)
	
	local data = {lang = lang, sc = sc, heads = {args["head"] or ""}, genders = nil, inflections = inflections, pos_category = frame.args[1], categories = categories, sort_key = nil}
	return require("モジュール:headword").full_headword(data)
end

function export.noun(frame)

	params["pl"] = {list = true}
	params["dec"] = {}
	
	local args = require("モジュール:parameters").process(frame:getParent().args, params)
	
	local sc = get_script(args)
	
	local inflections = {}
	
	local categories = categorize(args["cat"])
	
	local declension = ""
	
	otherscript(inflections, args, sc, categories)
	
	if #args["pl"] > 0 then
		local plurals = {label = "plural"}
		for i, pl in ipairs(args["pl"]) do
			table.insert(plurals, pl)
		end
		table.insert(inflections, plurals)
	end

		
	if args["dec"] then
		declension = "; <small><i>("
		if args["dec"] == "r" then
			declension = declension .. "regular declension [[Category:Mongolian regular declension nouns]]"
		elseif args["dec"] == "n" then
			declension = declension .. "hidden-n declension [[Category:Mongolian hidden-n nouns]]"
		elseif args["dec"] == "g" then
			declension = declension .. "hidden-g declension [[Category:Mongolian hidden-g nouns]]"
		elseif args["dec"] == "m" then
			declension = declension .. "mixed declension [[Category:Mongolian mixed declension nouns]]"
		else
			--error("non-existent declension")
		end
		declension = declension .. ")</i></small>"
	end
	
	local data = {lang = lang, sc = sc, heads = {args["head"] or ""}, genders = nil, inflections = inflections, pos_category = "nouns", categories = categories, sort_key = nil}
	return require("モジュール:headword").full_headword(data) .. declension
end


function export.verb(frame)
	params["caus"] = {list = true}
	params["pass"] = {list = true}
	
	local args = require("モジュール:parameters").process(frame:getParent().args, params)
	
	
	local inflections = {}
	local categories = categorize(args["cat"])
	
	local sc = get_script(args)
	
	otherscript(inflections, args, sc, categories)
	
	if #args["caus"] > 0 then
		causatives = {label = "causative"}
		for i, x in ipairs(args["caus"]) do
			table.insert(causatives, x)
		end
		table.insert(inflections, causatives)
	end
	
	if #args["pass"] > 0 then
		passives = {label = "passive"}
		for i, x in ipairs(args["pass"]) do
			table.insert(passives, x)
		end
		table.insert(inflections, passives)
	end

	local data = {lang = lang, sc = sc, heads = {args["head"] or ""}, genders = nil, inflections = inflections, pos_category = "verbs", categories = categories, sort_key = nil}
	return require("モジュール:headword").full_headword(data)
end


return export