Module:category tree/ws topic cat

Hello, you have come here looking for the meaning of the word Module:category tree/ws topic cat. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:category tree/ws topic cat, but we will also tell you about its etymology, its characteristics and you will know how to say Module:category tree/ws topic cat in singular and plural. Everything you need to know about the word Module:category tree/ws topic cat you have here. The definition of the word Module:category tree/ws topic cat will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:category tree/ws topic cat, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local export = {}

local topic_cat = require("Module:category tree/topic cat")
local poscatboiler = require("Module:category tree/poscatboiler")

-- Short-circuit some unnecessarily long category trees by
-- replacing certain parent categories, when encountered, with other ones
local parent_substitutions = {}
parent_substitutions = 'all topics'
parent_substitutions = 'all topics'
parent_substitutions = 'nature'
parent_substitutions = 'food and drink'  -- for Restaurants
parent_substitutions = 'occult'
parent_substitutions = 'food and drink'
parent_substitutions = 'all topics'  -- for Geography
parent_substitutions = 'food and drink'
parent_substitutions = 'economics'
parent_substitutions = 'sciences'
parent_substitutions = 'mathematics'
parent_substitutions = 'human behaviour'
parent_substitutions = 'society'
parent_substitutions = 'communication'
parent_substitutions = 'health'
parent_substitutions = 'society'
parent_substitutions = 'perception'
parent_substitutions = 'all topics'

-- Makes a "ws topic cat" object out of a "topic cat" object.
local function convert_topic_cat_to_ws_topic_cat(result)
	-- substituted category names are not allowed
	if parent_substitutions ~= nil then
		error(('This category is not allowed as a Thesaurus category. "%s" (see the list of parent substitutions at ])'):format(result:getCategoryName()))
	end

	-- keep a copy of the topic cat object's metatable so
	-- we can call its functions from our overrides
	local metatable = getmetatable(result)

	-- override certain functions on the topic cat object with
	-- {{ws topic cat}}-specific functions

	function result:getCategoryName()
		return 'Thesaurus:' .. metatable.getCategoryName(result)
	end

	function result:getDescription(isChild)
		local desc = metatable.getDescription(result)
		desc = mw.ustring.gsub(desc, ' terms()', ' thesaurus entries%1')
		desc = mw.ustring.gsub(desc, 'Category:', 'Category:Thesaurus:')
		desc = mw.ustring.gsub(desc, "'''NOTE.+$", '')
		return desc
	end

	function result:getParents()
		local parents = metatable.getParents(result)

		for key, parent in pairs(parents) do
			-- Process parent categories as follows:
			-- 1. skip non-topic cats and meta-categories that start with "List of"
			-- 2. map "en:All topics" to "English thesaurus entries" (and same for other languages), but map "All topics" itself to the root "Thesaurus" category
			-- 3. check if this parent is to be substituted, if so, substitute it
			-- 4. prepend "Thesaurus:" to all other category names
			if parent.name._info == nil or parent.name._info.raw ~= nil or string.sub(parent.name._info.label, 1, 8) == 'list of ' then
				table.remove(parents, key)
			elseif parent.name._info.label == 'all topics' or parent_substitutions == 'all topics' then
				if parent.name._lang == nil then
					parent.name = 'Category:Thesaurus'   -- TODO this cat needs to be Lua-ised
					parent.sort = string.lower(result._info.label)
				else
					parent.name = poscatboiler.new({ code = parent.name._info.code, label = 'thesaurus entries' })
				end
			elseif parent_substitutions ~= nil then
				parent.name = convert_topic_cat_to_ws_topic_cat(topic_cat.new({
					code = parent.name._info.code,
					label = parent_substitutions
				}))
			else
				parent.name = convert_topic_cat_to_ws_topic_cat(parent.name)
			end
		end

		-- add the non-thesaurus version of this category as a parent, unless it is a thesaurus-only category
		if result._data.thesaurusonly == nil then
			table.insert(parents, { name = topic_cat.new(result._info), sort = ' ' })
		end
		return parents
	end

	function result:getUmbrella()
		if not result._lang then
			return nil
		end

		local uinfo = mw.clone(result._info)
		uinfo.code = nil
		return export.new(uinfo)
	end

	return result
end

function export.new(info)
	return convert_topic_cat_to_ws_topic_cat(topic_cat.new(info))
end
export.main = export.new

return export