Module:sga-nouns

Hello, you have come here looking for the meaning of the word Module:sga-nouns. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:sga-nouns, but we will also tell you about its etymology, its characteristics and you will know how to say Module:sga-nouns in singular and plural. Everything you need to know about the word Module:sga-nouns you have here. The definition of the word Module:sga-nouns will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:sga-nouns, 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.

local m_utilities = require("Module:utilities")
local m_links = require("Module:links")

local export = {}

local lang = require("Module:languages").getByCode("sga")


local function postprocess(args, data)
	if args then
		if args == "p" then
			table.insert(data.categories, lang:getCanonicalName() .. " pluralia tantum")
		elseif args == "d" then
			table.insert(data.categories, lang:getCanonicalName() .. " dualia tantum")
		elseif args == "s" then
			table.insert(data.categories, lang:getCanonicalName() .. " uncountable nouns")
		end
		
		for key, form in pairs(data.forms) do
			-- Do not show singular or plural forms for nominals that don't have them
			if (not args:find("s") and key:find("_sg$"))
					or (not args:find("d") and key:find("_du$"))
					or (not args:find("p") and key:find("_pl$")) then
				form = "-"
			end
		
			data.forms = form
		end
	end
end


-- Inflection functions

local gender_names = {
	 = "masculine",
	 = "feminine",
	 = "neuter",
	 = "unknown gender",
}

export = function(frame)
	local wikicode = mw.getCurrentFrame():expandTemplate{title = "sga-decl-noun-table", args = {}}
	
	local params = {
		 = {},
		 = {list = true},
		}
	
	local form_params = {}
	
	for match in mw.ustring.gmatch(wikicode, "{{{(+)}}}") do
		if match ~= "info" then
			params = {
				list = true,
				default = mw.title.getCurrentTitle().nsText == "Template"
					and "{{{" .. match .. "}}}"
					or nil
			}
			table.insert(form_params, match)
		end
	end
	
	local data = {forms = {}, info = {}, categories = {}}
	
	local parent_args = frame:getParent().args
	
	-- Track empty tables: add category if the only parameter is |class=.
	local empty = true
	for k in pairs(parent_args) do
		if k ~= "class" then
			empty = false
			break
		end
	end
	if empty then
		table.insert(data.categories, "Old Irish nouns with empty inflection tables")
	end
	
	local args = require("Module:parameters").process(parent_args, params)
	
	for _, class in ipairs(args) do
		local stem, gender = mw.ustring.match(class, "^(.-)%-()$")
		
		if not stem or not gender then
			error("Unrecognised inflection class \"" .. class .. "\".")
		end
		
		local class_name
		if stem == "irreg" then
			class_name = "irregular"
		elseif stem == "indecl" then
			class_name = "indeclinable"
		else
			class_name = stem .. "-stem"
		end
		
		table.insert(data.info, gender_names .. " " .. class_name)
		
		if stem == "io" or stem == "o" or stem == "u" then
			table.insert(data.categories, lang:getCanonicalName() .. " "
				.. gender_names .. " " .. class_name .. " nouns")
		elseif stem == "i" or stem == "n" or stem == "nt" then
			if gender == "f" or gender == "m" then
				table.insert(data.categories, lang:getCanonicalName()
					.. " masculine or feminine " .. class_name .. " nouns")
			else
				table.insert(data.categories, lang:getCanonicalName() .. " "
					.. gender_names .. " " .. class_name .. " nouns")
			end
		else
			table.insert(data.categories, lang:getCanonicalName() .. " "
				.. class_name .. " nouns")
		end
	end
	
	data.info = table.concat(data.info, ", ")
	
	local any = false
	
	for _, p in ipairs(form_params) do
		data.forms = args
		any = true
	end
	
	postprocess(args, data)
	
	return make_table(data, wikicode)
end


-- Make the table
function make_table(data, wikicode)
	local function repl(param)
		if param == "info" then
			return mw.getContentLanguage():ucfirst(data.info or "")
		end
		
		local form = data.forms
		
		if form == "-" then
			return "—"
		elseif not form or #form == 0 then
			return ""
		end
		
		local ret = {}
		
		for key, subform in ipairs(form) do
			local note = mw.ustring.match(subform, "%+()$")
			subform = mw.ustring.gsub(subform, "%+()$", "")
			subform = m_links.full_link {lang = lang, term = subform}
			
			if note then
				subform = subform .. "<sup>" .. note .. "</sup>"
			end
			
			table.insert(ret, subform)
		end
		
		return table.concat(ret, ", ")
	end
	
	local wikicode = wikicode or mw.getCurrentFrame():expandTemplate {
		title = "sga-decl-noun-table",
		args = {},
	}
	
	return wikicode:gsub("{{{(+)}}}", repl)
		.. m_utilities.format_categories(data.categories, lang)
end

return export