Module:gender and number

Hali sa Wiksyunaryo

An plantillang ini nagpapahiling kan mga anotasyon sa kasarian, arog kan m o f pl. "Kasarian" sarong salang pagtaong ngaran sa sarong bagay, an anotasyon igdi kaayon sa kategoriya an animacy asin berbong aspeto (dawa pa an enot pirmi nang naipaparte bilang bahagi kan tataramon na kasarian. Ini ginagamit bilang parte kan ibang modyul, o pwedeng paganahon gamit an plantilla. An modyul na ini pinapagana kan listahan kan saro o dakul na mga "gender specifications".

Gender specifications para sa mga Lua script writers[baguhon]

Kada espesifikasyon sarong listahan kan mga codes, itinatao bilang sarong string na kaibahan an mga code na nababanga kan mga hyphens. Bawat code pinapabisto sa laog kan modyul mismo, asin sa pagpahiling kan mga espesifikasyon, bawat code sa espesifikasyon naililipat sa kinararapatang pampahiling na porma. An mga iba-ibang codes sa laog kan espesifikasyon idinudugang sa kada saro, asin sinusuway kan mga espasyo. Kun an modyul tinatawan nin iba-ibang espesifikasyon nin sararoan (sa sarong listahan), an kada item sa listahan isinusuway gamit an kuwit.

Halimbawa:

Listahan Resulta
{"m"} m
{"m-p"} m pl
{"m-an-p"} m anim pl
{"f-d", "m-p"} f du or m pl
{"m-p", "f-p"} m pl or f pl
{"m", "f", "p"} m or f or pl

An mga espesifikasyon na nagpupuon sa "c" (pero bako mismo an "c") itinatrato nin espesyal. Sinda kinokonsiderar na mga klase kan pangngaran, asin an parte sunod mismo sa "c" ay itinatrato bilang ngaran kan mga klase kan pangngaran; kadalasan, ini sarong numero. An mga klase kan pangngaran mayong mga sub na parte, kaya sinda mayong mga hyphens. KUn lampas sarong espesifikasyon an itinao, dapat gabos sinda klase kan pangngaran, asin sinda ipapahiling na nasusuway gamit an "forward slash", asin pinapanginotan kan "klase".

Halimbawa:

Listahan Resulta
{"c1"} class 1
{"c1", "c2"} class 1/2
{"c1a", "c2a"} class 1a/2a

Paggamit[baguhon]

An modyul na ini pwedeng gamiton sa paagi kan pagpalaog kaini asin pag apod sa function na format_list. Nangangaipo ini nin sarong parametro, na dapat sarong table kan mga zero o mas dakul pang takod. Ibabalik kaini an takod na igwang resulta. Halimbawa:

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"})

PAGIRUMDOM: An mga listang inagihan, mariribayan nin mas bago. Pwede man inin paganahon hali sa sarong plantilla. An function na show_list an ginagamit igdi. Naggagana ini sa parehong paagi kan function na format_list, pero an mga espesifikasyon minaagi bilang mga parametro sa pagpagana kan modyul, arog kan:

*{{#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 or f
  • m pl

Mayong limitasyon sa numero kan parametro na itinatao sa arog kaining paagi. An modyul maproseso kan gabos na parametro hanggang sa makahanap ini nin mayong laog. Ibig sabihon, an minasunod mapahiling nin "m" bakong "m or n":

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


Categoriya:Pankagabsan na gamit kan modyul


--[=[
	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["?"] = {type = "other", display = '<abbr title="gender incomplete">?</abbr>'}

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

-- Animacy
codes["an"] = {type = "animacy", display = '<abbr title="animate">anim</abbr>'}
codes["in"] = {type = "animacy", display = '<abbr title="inanimate">inan</abbr>'}

-- Personal
codes["pr"] = {type = "personal", display = '<abbr title="personal">pers</abbr>'}
codes["np"] = {type = "personal", display = '<abbr title="non-personal">npers</abbr>'}

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

-- Verb qualifiers
codes["impf"] = {type = "perfectivity", display = '<abbr title="imperfective aspect">impf</abbr>'}
codes["pf"] = {type = "perfectivity", display = '<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, " or ") .. "</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
		local types = {}
		
		-- 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 not codes[code] then
				error("The gender specification \"" .. spec .. "\" is not valid.")
			end
			
			if codes[code].type ~= "other" and types[codes[code].type] then
				--require("Module:debug").track("gender and number/multiple")
				--require("Module:debug").track("gender and number/multiple/" .. spec)
				error("The gender specification \"" .. spec .. "\" contains multiple tags of type \"" .. codes[code].type .. "\".")
			end
				
			parts[key] = codes[code].display
			types[codes[code].type] = true
		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