Module:gender and number doc

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

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

--[=[
	This module contains functions to display user-readable tables of the contents of ].

	Author: Benwing2
]=]

local export = {}

local data = require("Module:gender and number/data")

local function make_code(text)
	return "<code>" .. text .. "</code>"
end

-- Sort codes first by type, using the order specified below in `type_order`, then by code.
local type_order = {"gender", "number", "animacy", "virility", "aspect", "other"}
local type_to_index = {}
for i, typ in ipairs(type_order) do
	type_to_index = i
end

local function get_type_index(typ)
	return type_to_index or 50
end

function export.gender_and_number_table(frame)
	local alldata = {}

	-- Convert table of codes to a list of information.
	for code, desc in pairs(data.codes) do
		local obj = {
			code = make_code(code),
			type = desc.type,
			display = desc.display,
			cat = desc.cat and make_code(desc.cat) or "—",
		}
		table.insert(alldata, obj)
	end

	table.sort(alldata, function(obj1, obj2)
		local typind1 = get_type_index(obj1.type)
		local typind2 = get_type_index(obj2.type)
		if typind1 == typeind2 then
			return obj1.code < obj2.code
		else
			return typind1 < typind2
		end
	end)

	-- Convert to wikitable.

	local parts = {}
	table.insert(parts, '{|class="wikitable"')
	table.insert(parts, "! Code !! Type !! Display form !! Category")
	local last_type = nil
	for _, obj in ipairs(alldata) do
		table.insert(parts, "|-" .. (obj.type ~= last_type and ' style="border-top: 3px solid blue;"' or ""))
		local sparts = {}
		table.insert(sparts, obj.code)
		table.insert(sparts, obj.type)
		table.insert(sparts, obj.display)
		table.insert(sparts, obj.cat)
		table.insert(parts, "| " .. table.concat(sparts, " || "))
		last_type = obj.type
	end
	table.insert(parts, "|}")
	return table.concat(parts, "\n")
end

function export.combinations_table(frame)
	local alldata = {}

	-- Convert table of combination codes to a list of information.
	for code, desc in pairs(data.combinations) do
		local codes = desc.codes
		for i, indiv_code in ipairs(codes) do
			codes = make_code(indiv_code)
		end

		local obj = {
			code = make_code(code),
			codes = table.concat(codes, ", "),
			addl_display = desc.display or "—",
			cat = desc.cat and make_code(desc.cat) or "—",
		}
		table.insert(alldata, obj)
	end

	-- Sort codes by code.
	table.sort(alldata, function(obj1, obj2) return obj1.code < obj2.code end)

	-- Convert to wikitable.

	local parts = {}
	table.insert(parts, '{|class="wikitable"')
	table.insert(parts, "! Combination !! Individual codes !! Additional display text !! Category")
	for _, obj in ipairs(alldata) do
		table.insert(parts, "|-")
		local sparts = {}
		table.insert(sparts, obj.code)
		table.insert(sparts, obj.codes)
		table.insert(sparts, obj.addl_display)
		table.insert(sparts, obj.cat)
		table.insert(parts, "| " .. table.concat(sparts, " || "))
	end
	table.insert(parts, "|}")
	return table.concat(parts, "\n")
end

function export.multicode_table(frame)
	local alldata = {}

	-- Convert table of multicode categories to a list of information.
	for type, cat in pairs(data.multicode_cats) do
		local obj = {
			type = make_code(type),
			cat = make_code(cat),
		}
		table.insert(alldata, obj)
	end

	-- Sort by type.
	table.sort(alldata, function(obj1, obj2) return get_type_index(obj1.type) < get_type_index(obj2.type) end)

	-- Convert to wikitable.

	local parts = {}
	table.insert(parts, '{|class="wikitable"')
	table.insert(parts, "! Type !! Category when multiple codes of that type are present")
	for _, obj in ipairs(alldata) do
		table.insert(parts, "|-")
		local sparts = {}
		table.insert(sparts, obj.type)
		table.insert(sparts, obj.cat)
		table.insert(parts, "| " .. table.concat(sparts, " || "))
	end
	table.insert(parts, "|}")
	return table.concat(parts, "\n")
end

return export