模組:Category tree/poscatboiler/data/characters


此數據子模塊定義了維基詞典分類結構的一部分。

關於poscatboiler系統的介紹以及如何添加或更改分類,請參見Module:category tree/poscatboiler/data/documentation


local raw_categories = {}
local handlers = {} 

local ulen = mw.ustring.len
local uupper = mw.ustring.upper
local ulower = mw.ustring.lower
local rfind = mw.ustring.find



-----------------------------------------------------------------------------
--                                                                         --
--                              RAW CATEGORIES                             --
--                                                                         --
-----------------------------------------------------------------------------


raw_categories["Terms by their individual characters subcategories by language"] = {
	description = "Umbrella categories covering terms categorized by unusual characters contained in them.",
	additional = "{{{umbrella_meta_msg}}}",
	parents = {
		"綜合元分類",
		{name = "按漢字分類的詞", is_label = true, sort = " "},
	},
}

raw_categories["字元子分類"] = {
	description = "Umbrella categories covering terms categorized by unusual characters contained in them.",
	additional = "{{{umbrella_meta_msg}}}",
	parents = {
		"綜合元分類",
		{name = "依字元分類的詞", is_label = true, sort = " "},
	},
}



-----------------------------------------------------------------------------
--                                                                         --
--                                 HANDLERS                                --
--                                                                         --
-----------------------------------------------------------------------------


-- 	If char is a combining character, returns a version with a dotted circle before it.
function add_dotted_circle(char, combining)
	return combining and "◌" .. char or char
end


table.insert(handlers, function(data)
	-- NOTE: The "character" in the title may actually be a description such as
	-- "gershayim". In that case, char= is specified as a parameter indicating the
	-- actual character.
	local titlechar = data.label:match("^帶「(.+)」的詞$")
	if not titlechar then
		return nil
	end
	local params = {
		["char"] = {},
		["sort"] = {},
		-- Not sure what used to be done with the following parameters.
		["context"] = {},
		["context2"] = {},
	}
	local args = require("Module:parameters").process(data.args, params)
	
	if titlechar == "數字" then
		local sortkey = args.sort or "#"
		return {
			description = "含有一個或多個數字的{{{langname}}}詞。",
			parents = {{name = "依字元分類的詞", sort = sortkey }},
			breadcrumb = "數字",
			umbrella = {
				breadcrumb = "數字",
				parents = {{name = "字元子分類", sort = " " .. sortkey }}
			},
		}, true
	end
	local char = args.char or titlechar
	local titlechar_is_desc = args.char and args.char ~= titlechar
	if titlechar_is_desc then
		require("Module:debug").track("poscatboiler-characters/titlechar_is_desc")
	end
	
	

	local lang = data.lang or require("Module:languages").getByCode("mul")
	local combining = ulen(char) == 1 and require("Module:Unicode_data").is_combining(mw.ustring.codepoint(char))
	
	local upper = uupper(char)
	if char ~= upper and ulen(char) == 1 then
		-- We want uppercase characters; but unless we're careful, we run into an issue with
		-- [[Category:English terms spelled with ı]] due to the weird behavior of this character,
		-- which has standard I as its uppercase equivalent.
		local standard_chars = lang:getStandardCharacters()
		if standard_chars and not rfind(upper, "[" .. standard_chars .. "]") then
			error("Category titles should use uppercase characters: '" .. data.label .. "'")
		end
	end
	
	-- Compute description.

	-- If the letter has a lowercase form, show it.
	local character = require("Module:links").full_link(
		{
			term = char,
			alt = combining and add_dotted_circle(char, true) or nil,
			lang = lang,
			tr = combining and "-" or nil,
		},
		"term"
	)
	if ulower(char) ~= char then
		character = "大寫" .. character .. "或小寫" ..
			require("Module:links").full_link(
				{
					term = ulower(char),
					lang = lang
				},
				"term"
			)
	end
	
	if titlechar_is_desc then
		character = character .. " (" .. titlechar .. ")"
	end
	
	local description = "帶「" .. character .. "」的{{{langname}}}詞。"

	-- Set tagged character for displaytitle and breadcrumb.
	local tagged_titlechar = not titlechar_is_desc and
		require("Module:script utilities").tag_text(titlechar, lang, nil, "term") or nil
	local tagged_char = titlechar_is_desc and titlechar or
		require("Module:script utilities").tag_text(add_dotted_circle(char, combining), lang, nil, "term")

	-- Compute sort key.

	local sortkey =
		args.sort or lang:makeSortKey(char)
	if sortkey == "" then
		sortkey = char
	end

	return {
		description = description,
		displaytitle = not titlechar_is_desc and "帶「" .. tagged_titlechar .. "」的{{{langname}}}詞" or nil,
		parents = {{name = "依字元分類的詞", sort = sortkey }},
		breadcrumb = tagged_char,
		umbrella = {
			displaytitle = not titlechar_is_desc and "帶「" .. tagged_titlechar .. "」的詞" or nil,
			breadcrumb = tagged_char,
			parents = {{name = "字元子分類", sort = " " .. sortkey }}
		} or false,
	}, true
end)


table.insert(handlers, function(data)
	-- NOTE: The "character" in the title may actually be a description such as
	-- "gershayim". In that case, char= is specified as a parameter indicating the
	-- actual character.
	
	local titlechar = data.label:match("^寫作「(.+)」的詞$")
	if not titlechar then
		return nil
	end
	if string.find(titlechar, "讀作") ~= nil then ----------TEMP WORKAROUND
        return nil
    end
	local ja_ryu = data.lang and (data.lang:getCode() == "ja" or data.lang:getCode() == "ryu")
	-- If Japanese or Okinawan, only fire on a single kanji character.
	if ja_ryu and (titlechar:find("[A-Za-z]") or ulen(titlechar) > 1) then
		return nil
	end
	local params = {
		["char"] = {},
		["sort"] = {},
		-- Not sure what used to be done with the following parameters.
		["context"] = {},
		["context2"] = {},
	}
	local args = require("Module:parameters").process(data.args, params)
	local char = args.char or titlechar
	local titlechar_is_desc = args.char and args.char ~= titlechar
	if titlechar_is_desc then
		require("Module:debug").track("poscatboiler-characters/titlechar_is_desc")
	end

	local lang = data.lang or require("Module:languages").getByCode("mul")
	local combining = ulen(char) == 1 and require("Module:Unicode_data").is_combining(mw.ustring.codepoint(char))
	
	local upper = uupper(char)
	if char ~= upper and ulen(char) == 1 then
		-- We want uppercase characters; but unless we're careful, we run into an issue with
		-- [[Category:English terms spelled with ı]] due to the weird behavior of this character,
		-- which has standard I as its uppercase equivalent.
		local standard_chars = lang:getStandardCharacters()
		if standard_chars and not rfind(upper, "[" .. standard_chars .. "]") then
			error("Category titles should use uppercase characters: '" .. data.label .. "'")
		end
	end
	
	-- Compute description.

	-- If the letter has a lowercase form, show it.
	local character = require("Module:links").full_link(
		{
			term = char,
			alt = combining and add_dotted_circle(char, true) or nil,
			lang = lang,
			tr = combining and "-" or nil,
		},
		"term"
	)
	if ulower(char) ~= char then
		character = "upper case " .. character .. " or lower case " ..
			require("Module:links").full_link(
				{
					term = ulower(char),
					lang = lang
				},
				"term"
			)
	end
	
	if titlechar_is_desc then
		character = character .. " (" .. titlechar .. ")"
	end
	
	local description = "含有漢字「" .. character .. "」的{{{langname}}}詞彙。"

	-- Set tagged character for displaytitle and breadcrumb.
	local tagged_titlechar = not titlechar_is_desc and
		require("Module:script utilities").tag_text(titlechar, lang, nil, "term") or nil
	local tagged_char = titlechar_is_desc and titlechar or
		require("Module:script utilities").tag_text(add_dotted_circle(char, combining), lang, nil, "term")

	-- Compute sort key.

	local sortkey =
		args.sort or
		ja_ryu and ulen(char) == 1 and require("Module:zh-sortkey").makeSortKey(char, lang:getCode()) or
		lang:makeSortKey(char)
	if sortkey == "" then
		sortkey = char
	end

	return {
		description = description,
		displaytitle = not titlechar_is_desc and "寫作「" .. mw.text.encode(tagged_titlechar, titlechar) .. "」的{{{langname}}}詞" or nil,
		parents = {{name = "按漢字分類的詞", sort = sortkey }},
		breadcrumb = "-{" .. tagged_char .. "}-",
		umbrella = not ja_ryu and {
			displaytitle = not titlechar_is_desc and "Terms spelled with " .. tagged_titlechar .. " by language" or nil,
			breadcrumb = tagged_char,
			parents = {{name = "Terms by their individual characters subcategories by language", sort = " " .. sortkey }}
		} or false,
	}, true
end)


return {RAW_CATEGORIES = raw_categories, HANDLERS = handlers}