Module:gender and number: difference between revisions

From Wiktionary, the free dictionary
Jump to navigation Jump to search
Content deleted Content added
No edit summary
added non-personal as antonym of personal
Line 25: Line 25:
codes["in"] = '<abbr title="inanimate">inan</abbr>'
codes["in"] = '<abbr title="inanimate">inan</abbr>'
codes["pr"] = '<abbr title="personal">pers</abbr>'
codes["pr"] = '<abbr title="personal">pers</abbr>'
codes["np"] = '<abbr title="non-personal">npers</abbr>'


-- Numbers
-- Numbers

Revision as of 16:51, 23 June 2015

This module shows gender/number annotations, such as m (masculine), n pl (neuter plural) or f anim du (feminine animate dual). "Gender" is something of a misnomer, as the available annotation categories include other similar lexical characteristics such as animacy and verb aspect (though the former is sometimes also considered a part of word gender). These annotations are attached to nouns, pronouns and other parts of speech that have such lexical categories, depending on the particular language. The annotations occur as parameters e.g. to headword templates such as {{head}}, {{es-noun}} (for Spanish nouns), {{fr-proper noun}} (for French proper nouns) and {{ru-verb}} (for Russian verbs); to translation templates such as {{t}}, {{t+}} and {{t-check}}; to definition templates such as {{demonym-noun}}; and to dedicated gender/number templates such as {{g}}.

Gender/number specifications

A given annotation is described using a gender/number specification. Each such specification is a hyphen-separated list of gender/number codes, where a given code describes a single value of a particular category (e.g. m for "masculine", an for "animate", p for "plural"). Often, templates accept a list of gender/number specifications rather than just a single one, since some terms belong to multiple possible gender/number categories. Depending on the template in question, these specifications will be given using separate parameters or a single comma-separated parameter.

When displaying a specification, each code in the specification is converted into the appropriate display form. The different codes within the specification are then added together, separated by spaces.

Some examples:

List Result
{"m"} m
{"m-p"} m pl
{"m-an-p"} m anim pl
{"mfbysense-p"} Lua error at line 104: The gender specification "mfbysense-p" is not valid.
{"?-p"} ? pl
{"?!-an-s"} Lua error at line 104: The gender specification "?!-an-s" is not valid.
{"f-d", "m-p"} f du, m pl
{"m-p", "f-p"} m pl, f pl
{"m", "f", "p"} m, f, pl

The source of truth for the current set of recognized codes is Module:gender and number/data.

The following table gives:

  1. the currently recognized codes;
  2. the type category they belong to (in a given spec, only one code in a given type category can be present);
  3. how the codes display (hover over the display form to see an explanation of what the code means);
  4. which category (if any) that the term will be assigned to if the code in question is in the term's headword gender/number spec (where POS is replaced by the pluralized part of speech of the term).
Code Type Display form Category
m gender m masculine POS
n gender n neuter POS
f gender f feminine POS
gneut gender gender-neutral gender-neutral POS
g! gender gender unattested
c gender c common-gender POS
s number sg
d number du dualia tantum
num! number number unattested
p number pl pluralia tantum
an animacy anim animate POS
in animacy inan inanimate POS
an! animacy animacy unattested
pr animacy pers personal POS
anml animacy animal animal POS
np animacy npers nonpersonal POS
vr virility vir virile POS
nv virility nvir nonvirile POS
pf aspect pf perfective POS
impf aspect impf imperfective POS
asp! aspect aspect unattested
? other ?
?! other gender unattested

Certain gender/number codes are combination codes that are more or less equivalent to individually specifying two or more codes of a given type category in separate gender/number specs. Some combination codes categorize and display additionally. The following table gives these combination codes:

Combination Individual codes Additional display text Category
biasp impf, pf
mf m, f
mfbysense m, f by sense masculine and feminine POS by sense
mfequiv m, f same meaning

In certain type categories, if more than one code of that category is given (necessarily in different gender/number specifications), the term is added to a special category. The following table gives these multi-code categories:

Type Category when multiple codes of that type are present
gender POS with multiple genders
animacy POS with multiple animacies
aspect biaspectual POS

Noun classes

Specifications that begin with "c" (but not "c" itself) are treated specially. They are considered noun classes, and the part immediately after the "c" is simply treated as some kind of name for a noun class; usually this will be a number. Noun classes do not have sub-parts, so they will not contain hyphens. When more than one specification is given, they must all be noun classes, and they are displayed separated with a forward slash instead, and preceded by class.

Examples:

List Result
{"c1"} class 1
{"c1", "c2"} class 1/2
{"c1a", "c2a"} class 1a/2a

Usage

The module can be used from another module by importing it and calling the exported format_list function. It requires one parameter, which must be a table of zero or more strings. It will then return a string containing the result. For example:

local gen = require("Module:gender and number")
local example1 = gen.format_list({"m"})
local example2 = gen.format_list({"m", "f"})
local example3 = gen.format_list({"m-p"})

WARNING: The list passed in will be overwritten.

It can also be invoked from a template. The function show_list is used for this. It works the same way as the format_list function, but the specifications are passed as parameters to the module invocation, like so:

*{{#invoke:gender and number|show_list|m}}
*{{#invoke:gender and number|show_list|m|f}}
*{{#invoke:gender and number|show_list|m-p}}
  • m
  • m, f
  • m pl

There is no limit to the number of parameters that can be given this way. The module will process all of its parameters until it finds one that is empty. This means that the following will display only "m" and not "m, n":

{{#invoke:gender and number|show_list|m||n}}

Exported functions

export.show_list

function export.show_list(frame)

This function lacks documentation. Please add a description of its usages, inputs and outputs, or its difference from similar functions, or make it local to remove it from the function list.

export.format_list

function export.format_list(list, lang)

This function lacks documentation. Please add a description of its usages, inputs and outputs, or its difference from similar functions, or make it local to remove it from the function list.

export.format_specification

function export.format_specification(spec, lang)

This function lacks documentation. Please add a description of its usages, inputs and outputs, or its difference from similar functions, or make it local to remove it from the function list.


--[=[
	This module creates standardised displays for gender and number.
	It converts a gender specification into Wiki/HTML format.
	
	A gender specification is a list of one of the elements listed below,
	separated by hyphens. Examples are: "c", "n", "f-p", "m-an-p"
]=]--

local export = {}

local codes = {}

-- A list of all possible "parts" that a specification can be made out of.

codes["?"] = '<abbr title="gender incomplete">?</abbr>'

-- Genders
codes["m"] = '<abbr title="masculine gender">m</abbr>'
codes["f"] = '<abbr title="feminine gender">f</abbr>'
codes["n"] = '<abbr title="neuter gender">n</abbr>'
codes["c"] = '<abbr title="common gender">c</abbr>'

-- Additional qualifiers
codes["an"] = '<abbr title="animate">anim</abbr>'
codes["in"] = '<abbr title="inanimate">inan</abbr>'
codes["pr"] = '<abbr title="personal">pers</abbr>'
codes["np"] = '<abbr title="non-personal">npers</abbr>'

-- Numbers
codes["s"] = '<abbr title="singular number">sg</abbr>'
codes["d"] = '<abbr title="dual number">du</abbr>'
codes["p"] = '<abbr title="plural number">pl</abbr>'

-- Verb qualifiers
codes["impf"] = '<abbr title="imperfective aspect">impf</abbr>'
codes["pf"] = '<abbr title="perfective aspect">pf</abbr>'

-- Version of format_list that can be invoked from a template.
function export.show_list(frame)
	local args = frame.args
	local lang = args["lang"]; if lang == "" then lang = nil end
	local list = {}
	local i = 1
	
	while args[i] and args[i] ~= "" do
		table.insert(list, args[i])
		i = i + 1
	end
	
	return export.format_list(list, lang)
end

-- Format one or more gender specifications, in the form of a table of specifications.
function export.format_list(list, lang)
	local is_nounclass = nil
	
	-- Iterate over each specification and format it
	for key, spec in ipairs(list) do
		local nc
		list[key], nc = export.format_specification(spec, lang)
		
		-- Ensure that the specifications are either all noun classes, or none are.
		if is_nounclass == nil then
			is_nounclass = nc
		elseif is_nounclass ~= nc then
			error("Noun classes and genders cannot be mixed. Please use either one or the other.")
		end
	end
	
	if is_nounclass then
		-- Add the processed codes together with slashes
		return "<span class=\"gender\">class " .. table.concat(list, "/") .. "</span>"
	else
		-- Add the processed codes together with commas
		return "<span class=\"gender\">" .. table.concat(list, ", ") .. "</span>"
	end
end

-- Format the sub-parts of a single gender specification.
function export.format_specification(spec, lang)
	local categories = ""
	local ret = ""
	local is_nounclass = false
	
	-- If the specification starts with cX, then it is a noun class specification.
	if spec:find("^[1-9]") or spec:find("^c[^-]") then
		is_nounclass = true
		code = spec:gsub("^c", "")
		
		if code == "?" then
			ret = "<abbr class=\"noun-class\" title=\"noun class missing\">?</abbr>"
		else
			ret = "<abbr class=\"noun-class\" title=\"noun class " .. code .. "\">" .. code .. "</abbr>"
		end
	else
		-- Split the parts and iterate over each part, converting it into its display form
		local parts = mw.text.split(spec, "-")
		
		for key, code in ipairs(parts) do
			-- Is this code valid?
			if codes[code] then
				parts[key] = codes[code]
			else
				error("The gender specification \"" .. spec .. "\" is not valid.")
			end
		end
		
		-- Add the processed codes together with non-breaking spaces
		ret = table.concat(parts, "&nbsp;")
	end
	
	-- Do some additional checks if a language was given
	if lang then
		-- Is this an incomplete gender?
		if spec:find("?") then
			local m_utilities = require("Module:utilities")
			categories = m_utilities.format_categories({lang:getCanonicalName() .. " terms with incomplete gender"}, nil)
		end
		
		-- Check if the specification is valid
		--elseif langinfo.genders then
		--	local valid_genders = {}
		--	for _, g in ipairs(langinfo.genders) do valid_genders[g] = true end
		--	
		--	if not valid_genders[spec] then
		--		local valid_string = {}
		--		for i, g in ipairs(langinfo.genders) do valid_string[i] = g end
		--		error("The gender specification \"" .. spec .. "\" is not valid for " .. langinfo.names[1] .. ". Valid are: " .. table.concat(valid_string, ", "))
		--	end
		--end
	end
	
	return ret .. categories, is_nounclass
end

return export