Module:yi-headword

Hello, you have come here looking for the meaning of the word Module:yi-headword. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:yi-headword, but we will also tell you about its etymology, its characteristics and you will know how to say Module:yi-headword in singular and plural. Everything you need to know about the word Module:yi-headword you have here. The definition of the word Module:yi-headword will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:yi-headword, 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 com = require("Module:yi-common")
local lang = require("Module:languages").getByCode("yi")
local Latn = require("Module:scripts").getByCode("Latn")
local u = mw.ustring

local export = {}
local pos_functions = {}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	SUBPAGENAME = mw.title.getCurrentTitle().subpageText

	local args = {}
	for key, val in pairs(frame:getParent().args) do
		if val ~= "" then
			args = val
		end
	end
	
	local poscat = frame.args or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	
	local data = {lang = lang, pos_category = poscat, categories = {}, heads = {args}, translits = {args}, genders = {}, inflections = {}, sort_key = args}
	
	-- Call POS-specific function
	if pos_functions then
		pos_functions(args, data)
	end
	
	return require("Module:headword").full_headword(data)
end

-- if func(form, formtr) is nil or returns nil, then the default get_form will be used
local function get_form_custom(func, args, argname, trname)
	local form = args
	if form then
		local formtr = args
		local ret = func and func(form, formtr)
		if ret == nil then
			ret = com.form(form, args)
		end
		return ret
	else
		return form
	end
end

local function get_form(args, argname, trname)
	return get_form_custom(func, args, argname, trname)
end

local function get_numbered_forms_custom(func, args, argname, startat, output)
	output = output or {}
	while true do
		local form = get_form_custom(func, args, argname .. startat)
		if form then
			table.insert(output, form)
		else
			break
		end
		startat = startat + 1
	end
	return output
end

local function get_numbered_forms(args, argname, startat, output)
	return get_numbered_forms_custom(nil, args, argname, startat, output)
end

local function add_inflections(inflections, ...)
	for _, inflection in ipairs({...}) do
		if inflection then
			for i, form in ipairs(inflection) do
				if form == "-" then
					inflection = {term = "—", translit = "-", nolink = true, sc = Latn}
				else
					inflection = {term = form.text, translit = form.tr}
				end
			end
			table.insert(inflections, inflection)
		end
	end
end

pos_functions = function(args, data)
	local comparatives = {get_form(args, 1, "ctr"), label = "comparative", enable_auto_translit = true}
	if comparatives then
		get_numbered_forms(args, "c", 2, comparatives)
	end

	local superlatives = {get_form(args, 2, "str"), label = "superlative", enable_auto_translit = true}
	if superlatives then
		get_numbered_forms(args, "s", 2, superlatives)
	end

	add_inflections(data.inflections, comparatives, superlatives)
end

pos_functions = function(args, data)
	local past_participles = {get_form(args, 1, 2), label = "past participle", enable_auto_translit = true, accel = {form = "past-participle"}}
	if past_participles then
		get_numbered_forms(args, "p", 2, past_participles)
	end

	add_inflections(data.inflections, past_participles)
end

local compound_genders = {
	 = {"m-p"},
	 = {"n-p"},
	 = {"f-p"},
	 = {"m", "n"},
	 = {"m", "f"},
	 = {"f", "n"},
	 = {"m-p", "n-p"},
	 = {"m-p", "f-p"},
	 = {"f-p", "n-p"},
	 = {"m", "f", "n"},
	 = {"m-p", "f-p", "n-p"},
}

local plural_suffixes = {
	 = "ן",
	 = "ען",
	 = "ס",
	 = "עס",
	 = "ער",
	 = "עך",
}

local plural_getter = {}
function plural_getter:__call(f, ftr)
	if f == "+" then
		return com.form(self.head, ftr)
	elseif plural_suffixes then
		return com.form(com.suffix(self.head, plural_suffixes), ftr)
	else
		return nil
	end
end

local dim_suffixes = {
	 = "ל",
	 = "כל",
	 = "עלע",
}

local dim_getter = {}
function dim_getter:__call(f, ftr)
	if dim_suffixes then
		return com.form(com.suffix(self.head, dim_suffixes), ftr)
	else
		return nil
	end
end

local gender_endings = {
		= "n",
	 = "n",
}

local gender_getter = {}
function gender_getter:__call()
	for k, v in pairs(gender_endings) do
		if u.match(self.head, k .. "$") then
			return v
		end
	end
	return nil
end

pos_functions = function(args, data)
	local gs = compound_genders]
	if gs then
		for _, g in ipairs(gs) do
			table.insert(data.genders, g)
		end
	elseif args then
		table.insert(data.genders, args)
		local i = 2
		while args do
			table.insert(data.genders, args)
			i = i + 1
		end
	else
		local get_gender = {head = com.form(args or SUBPAGENAME, args)}
		setmetatable(get_gender, gender_getter)
		data.genders = {get_gender()}
	end

	local get_plural = {head = com.form(args or SUBPAGENAME, args)}
	setmetatable(get_plural, plural_getter)
	local plurals = {get_form_custom(get_plural, args, "pl"), label = "plural", enable_auto_translit = true}
	if plurals then
		get_numbered_forms_custom(get_plural, args, "pl", 2, plurals)
	end

	add_inflections(data.inflections, plurals)

	local get_dim = {head = com.form(args or SUBPAGENAME, args)}
	setmetatable(get_dim, dim_getter)
	local dims = {get_form_custom(get_dim, args, "dim"), label = "diminutive", enable_auto_translit = true}
	if dims then
		get_numbered_forms_custom(get_dim, args, "dim", 2, dims)
	end

	add_inflections(data.inflections, dims)
end

pos_functions = function(args, data)
	local dem_forms = {get_form(args, "dem", "demtr"), label = "contracted ''dem''-form", enable_auto_translit = true}

	if dem_forms == "-" then
		dem_forms.label = "no " .. dem_forms.label
		dem_forms = nil
		table.insert(data.inflections, dem_forms)
	elseif dem_forms then
		get_numbered_forms(args, "dem", 2, dem_forms)
		add_inflections(data.inflections, dem_forms)
	end
end

return export