模組:Category tree/poscatboiler/data/rhymes

子頁面


local labels = {}
local raw_categories = {}
local raw_handlers = {}



-----------------------------------------------------------------------------
--                                                                         --
--                                  LABELS                                 --
--                                                                         --
-----------------------------------------------------------------------------


labels["韻部"] = {
	description = "本分類列出歸屬於各個韻部的{{{langname}}}單字。",
	umbrella_parents = "分类",
	parents = {{name = "{{{langcat}}}", raw = true}},
}

labels["refractory rhymes"] = {
	description = "Lists of {{{langname}}} words that don't rhyme with other words.",
	umbrella_parents = "韻部子分類",
	parents = {"韻部"},
}



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


raw_categories["韻部子分類"] = {
	description = "Umbrella categories covering topics related to rhymes.",
	additional = "{{{umbrella_meta_msg}}}",
	parents = {
		"綜合元分類",
		{name = "韻部", is_label = true, sort = " "},
	},
}


raw_categories["韻部"] = {
	description = "Umbrella categories covering rhymes by language.",
	additional = "{{{umbrella_meta_msg}}}",
	parents = {
		"綜合元分類",
		{name = "韻部", is_label = true, sort = " "},
	},
}


-----------------------------------------------------------------------------
--                                                                         --
--                               RAW HANDLERS                              --
--                                                                         --
-----------------------------------------------------------------------------


table.insert(raw_handlers, function(data)
	local function rhymeTopCategory(lang)
		return {
			lang = lang:getCode(),
			description = "Lists of " .. lang:makeCategoryLink() .. " words by their rhymes.",
			additional = "This is an umbrella category. It contains no dictionary entries, but rather possible rhymes as subcategories.",
			parents = {
				"{{{langcat}}}",
				{name = "韻部", sort = langname},
			},
			breadcrumb = "韻部",
		}
	end
	
	local function rhymeCategory(lang, rhyme)
		return {
			lang = lang:getCode(),
			description = '押<span class="IPA">-' .. rhyme .. '</span>韻的' .. lang:makeCategoryLink() .. '詞語。',
			parents = {
				{name = "Rhymes:" .. lang:getCanonicalName(), sort = rhyme},
			},
			breadcrumb = '<span class="IPA">-' .. rhyme .. '</span>',
		}
	end
	
	local function rhymeSyllableCountCategory(lang, rhyme, syllableCount)
		return {
			lang = lang:getCode(),
			description = '押<span class="IPA">-' .. rhyme .. '</span>韻的' .. lang:makeCategoryLink() ..syllableCount .. "音節詞語。",
			parents = {
				{name = "Rhymes:" .. lang:getCanonicalName() .. "/" .. rhyme, sort = syllableCount},
			},
			breadcrumb = tostring(syllableCount) .. "音節",
		}
	end
	
	local langname = data.category:match("^Rhymes:([^/]+)")
	if langname then
		local lang = require("Module:languages").getByCanonicalName(langname)
		if lang then
			local tokens = mw.text.split(data.category, "/")
			if #tokens > 1 then
				local rhyme = tokens[2]
				if #tokens == 3 then
					-- rhyme + syllable count category
					local syllables = nil
					local syllablesregex = tokens[3]:match("(%d+)音節")
					if syllablesregex then
						syllables = tonumber(syllablesregex)
					end
					if syllables then
						return rhymeSyllableCountCategory(lang, rhyme, syllables)
					end
				elseif #tokens == 2 then
					-- rhyme category
					return rhymeCategory(lang, rhyme)
				end
			else
				-- rhyme language top category
				return rhymeTopCategory(lang)
			end
		end
	end
end)




return {LABELS = labels, RAW_CATEGORIES = raw_categories, RAW_HANDLERS = raw_handlers}