Module:ber-headword

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

This module implements headword templates for all Berber languages.

The Wikicode of a template invoking this module should look similarly to the following (shown is the code for Tarifit nouns, i.e. {{rif-noun}}):

{{#invoke:ber-headword|show|nouns|lang=rif}}<!--

--><noinclude>{{documentation}}</noinclude>

-- Based on ] by Benwing2
-- Adapted by Fenakhay

local lang

local export = {}
local pos_functions = {}

local force_cat = false

local function otherscript(inflections, args)
	local title = mw.title.getCurrentTitle()
	local sc = lang:findBestScript(title.subpageText)

	local other_sc

	if sc:getCode() == "Latn" then
		other_sc = require("Module:scripts").getByCode("Tfng")
		local inflection = { label = other_sc:getCanonicalName() .. " spelling" }

		if not tr then
			tr = require("Module:Latn-Tfng-translit").tr(
				require("Module:links").remove_links(
					mw.title.getCurrentTitle().text), lang:getCode(), sc:getCode())
		end

		table.insert(inflection, { term = tr, sc = other_sc })

		table.insert(inflections, inflection)
	end
end

-- The main entry point.
function export.show(frame)
	local poscat = frame.args or
		error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")

	local parargs = frame:getParent().args

	local params = {
		 = { list = true, disallow_holes = true },
		 = { list = true, allow_holes = true },
		 = {},
		 = { type = "boolean" },
		 = { type = "boolean" },
		 = {}, -- for testing
	}

	if frame.args then
		lang = require("Module:languages").getByCode(frame.args)
	else
		error("Please specify a language code.")
	end

	if pos_functions then
		for key, val in pairs(pos_functions.params) do
			params = val
		end
	end

	local args = require("Module:parameters").process(parargs, params)

	local pagename = args.pagename or mw.loadData("Module:headword/data").pagename

	local enable_auto_translit = false

	if (lang:findBestScript(pagename):getCode() == "Tfng") then
		enable_auto_translit = true
	end

	local data = {
		lang = lang,
		pos_category = poscat,
		categories = {},
		heads = {},
		genders = {},
		inflections = { enable_auto_translit = enable_auto_translit },
		pagename = pagename,
		id = args.id,
		sort_key = args.sort,
		force_cat_output = force_cat,
	}

	local heads = args.head
	for i = 1, #heads do
		table.insert(data.heads, {
			term = heads,
			tr = args.tr,
		})
	end

	local auto_generate_tifinagh = {  = true,  = true }

	if auto_generate_tifinagh then
		otherscript(data.inflections, args)
	end

	if pos_functions then
		pos_functions.func(args, data)
	end

	if args.json then
		return require("Module:JSON").toJSON(data)
	end

	return require("Module:headword").full_headword(data)
end

local function getargs(args, argpref)
	local forms = {}
	for i, form in ipairs(args) do
		local translit = args
		local gender = args
		local gender2 = args
		local genderlist = (gender or gender2) and { gender, gender2 } or nil
		table.insert(forms, { term = form, translit = translit, genders = genderlist })
	end

	return forms
end

local function add_infl_params(params, argpref, defgender)
	params = { list = true, disallow_holes = true }
	params = { list = true, allow_holes = true }
	params = { list = true, default = defgender }
	params = { list = true }
end

local function handle_infl(args, data, argpref, label, generate_default)
	local newinfls = getargs(args, argpref)
	if #newinfls == 0 and generate_default then
		newinfls = { { term = "+" } }
	end
	if generate_default then
		local saw_plus = false
		for _, newinfl in ipairs(newinfls) do
			if newinfl.term == "+" then
				saw_plus = true
				break
			end
		end
		if saw_plus then
			local newnewinfls = {}
			for _, newinfl in ipairs(newinfls) do
				if newinfl.term == "+" then
					local definfls = generate_default(args, data)
					for _, definfl in ipairs(definfls) do
						table.insert(newnewinfls, definfl)
					end
				else
					table.insert(newnewinfls, newinfl)
				end
			end
			newinfls = newnewinfls
		end
	end
	if #newinfls > 0 then
		newinfls.label = label
		table.insert(data.inflections, newinfls)
	end
end


local function add_all_infl_params(params, argpref)
	if argpref ~= "" then
		add_infl_params(params, argpref)
	end

	add_infl_params(params, argpref .. "cons")
end

local function handle_all_infl(args, data, argpref, label, generate_default)
	if argpref ~= "" then
		handle_infl(args, data, argpref, label, generate_default)
	end

	local labelsp = label == "" and "" or label .. " "
	handle_infl(args, data, argpref .. "cons", labelsp .. "construct state")
end

local function handle_noun_plural(args, data)
	if args.pl == "-" then
		table.insert(data.inflections, { label = "usually ]" })
		table.insert(data.categories, lang:getCanonicalName() .. " uncountable nouns")
	else
		handle_all_infl(args, data, "pl", "plural")
	end
end

local valid_bare_genders = { false, "m", "f" }
local valid_bare_numbers = { false, "p" }

local valid_genders = {}
for _, gender in ipairs(valid_bare_genders) do
	for _, number in ipairs(valid_bare_numbers) do
		local parts = {}
		local function ins_part(part)
			if part then
				table.insert(parts, part)
			end
		end
		ins_part(gender)
		ins_part(number)
		local full_gender = table.concat(parts, "-")
		valid_genders = true
	end
end

local function add_gender_params(params, default)
	params = { list = "g", default = default or "?" }
end

local function handle_gender(args, data, nonlemma)
	for _, g in ipairs(args) do
		if valid_genders then
			table.insert(data.genders, g)
		else
			error("Unrecognized gender: " .. g)
		end
	end

	if nonlemma then
		return
	end
end

local adj_inflections = {
	{ pref = "",    label = "" },
	{ pref = "f",   label = "feminine" },
	{ pref = "pl",  label = "masculine plural" },
	{ pref = "fpl", label = "feminine plural" },
}

local function create_infl_list_params(infl_list)
	local params = {}
	for _, infl in ipairs(infl_list) do
		if infl.basic then
			add_infl_params(params, infl.pref)
		else
			add_all_infl_params(params, infl.pref)
		end
	end
	return params
end

local function handle_infl_list_args(args, data, infl_list)
	for _, infl in ipairs(infl_list) do
		if infl.handle then
			infl.handle(args, data)
		elseif infl.basic then
			handle_infl(args, data, infl.pref, infl.label, infl.generate_default)
		else
			handle_all_infl(args, data, infl.pref, infl.label, infl.generate_default)
		end
	end
end

pos_functions = {
	params = (function()
		local params = create_infl_list_params(adj_inflections)
		return params
	end)(),
	func = function(args, data)
		handle_infl_list_args(args, data, adj_inflections)
	end
}

local sing_coll_noun_inflections = {
	{ pref = "",   label = "" },
	{ pref = "pl", label = "plural", handle = handle_noun_plural },
}

local function handle_sing_coll_noun_infls(args, data, otherinfl, otherlabel)
	handle_gender(args, data)
	handle_infl(args, data, otherinfl, otherlabel)
	handle_infl_list_args(args, data, sing_coll_noun_inflections)
end

local function get_sing_coll_noun_params(defgender, otherinfl, othergender)
	local params = create_infl_list_params(sing_coll_noun_inflections)
	add_gender_params(params, defgender)
	add_infl_params(params, otherinfl, othergender)
	return params
end

pos_functions = {
	params = get_sing_coll_noun_params("m", "sing", "f"),
	func = function(args, data)
		data.pos_category = "nouns"
		table.insert(data.categories, lang:getCanonicalName() .. " collective nouns")
		table.insert(data.inflections, { label = "collective" })
		handle_sing_coll_noun_infls(args, data, "sing", "singulative")
	end
}

pos_functions = {
	params = get_sing_coll_noun_params("f", "coll", "m"),
	func = function(args, data)
		data.pos_category = "nouns"
		table.insert(data.categories, lang:getCanonicalName() .. " singulative nouns")
		table.insert(data.inflections, { label = "singulative" })
		handle_sing_coll_noun_infls(args, data, "coll", "collective")
	end
}

local noun_inflections = {
	{ pref = "",    label = "" },
	{ pref = "d",   label = "dual" },
	{ pref = "pl",  label = "plural",              handle = handle_noun_plural },
	{ pref = "dim", label = "diminutive" },
	{ pref = "f",   label = "feminine equivalent" },
	{ pref = "m",   label = "masculine equivalent" },
}

local function get_noun_params()
	local params = create_infl_list_params(noun_inflections)
	add_gender_params(params)
	return params
end

local function handle_noun_infls(args, data)
	handle_gender(args, data)
	handle_infl_list_args(args, data, noun_inflections)
end

pos_functions = {
	params = get_noun_params(),
	func = handle_noun_infls,
}

pos_functions = {
	params = get_noun_params(),
	func = function(args, data)
		table.insert(data.categories, lang:getCanonicalName() .. " cardinal numbers")
		handle_noun_infls(args, data)
	end
}

pos_functions = {
	params = get_noun_params(),
	func = handle_noun_infls,
}

local pronoun_inflections = {
	{ pref = "",   label = "" },
	{ pref = "pl", label = "plural",  handle = handle_noun_plural },
	{ pref = "f",  label = "feminine" },
}

local function get_pronoun_params()
	local params = create_infl_list_params(pronoun_inflections)
	add_gender_params(params)
	return params
end

pos_functions = {
	params = get_pronoun_params(),
	func = function(args, data)
		handle_gender(args, data)
		handle_infl_list_args(args, data, pronoun_inflections)
	end
}

local verb_inflections = {
	{ pref = "cont",    label = "intensive aorist" },
	{ pref = "aorist",  label = "aorist" },
	{ pref = "pret",    label = "preterite" },
	{ pref = "negpret", label = "negative preterite" },
	{ pref = "vn",      label = "verbal noun" },
}

local function get_verb_params()
	local params = create_infl_list_params(verb_inflections)
	return params
end

local function handle_verb_infls(args, data)
	handle_infl_list_args(args, data, verb_inflections)
end

pos_functions = {
	params = get_verb_params(),
	func = handle_verb_infls,
}

return export