Mòdul:zgh-entrada

De Viccionari
Icona de documentació de mòdul Documentació del mòdul[mostra] [modifica] [refresca]

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]


Aquest mòdul presenta la capçalera d’una entrada en amazic marroquí. Actualment dóna suport a les plantilles: {{zgh-nom}}. Vegeu la documentació de les plantilles per a la seva utilització.

local p = {}

local lang = {code = "zgh", name = "amazic marroquí", sc = "Tfng"}
local pos_functions = {}

-----------------------
-- Utility functions --
-----------------------

-- If Not Empty
local function ine(arg)
	if arg == "" then
		return nil
	else
		return arg
	end
end

local function list_to_set(list)
	local set = {}
	for _, item in ipairs(list) do
		set[item] = true
	end
	return set
end

-- The main entry point.
function p.show(frame)
	local args = frame:getParent().args
	local pagename = args.pagename
	if not pagename or pagename == "" then
		pagename = mw.title.getCurrentTitle().subpageText
	end
	
	local poscat = frame.args[1] or error("Falta especificar la categoria lèxica com a primer paràmetre.")
	
	-- Gather parameters
	local data = {lang = lang, heads = {}, translits = {}, genders = {}, inflections = {enable_auto_translit = true}, categories = {}}
	local lema = ine(args.lema)
	table.insert(data.heads, lema)
	local translit = ine(args["tr"])
	local isLemma = frame.args['forma'] == nil and true or nil
	
	if pos_functions[poscat] then
		pos_functions[poscat].func(args, data, isLemma)
	else
		table.insert(data.categories, poscat .. " en " .. lang.name)
	end
	
	if args.bot then
		return require("Mòdul:lema").make_bot_list(data.inflections)
	else
		return require("Mòdul:lema").full_headword(data)
	end
end

-- Get a list of inflections. See handle_infl() for meaning of ARGS, ARGPREF
-- and DEFGENDER.
local function getargs(args, argpref, defgender)
	-- Gather parameters
	local forms = {}
	
	local form = ine(args[argpref])
	local translit = ine(args[argpref .. "tr"])
	local gender = ine(args[argpref .. "g"])
	local gender2 = ine(args[argpref .. "g2"])
	local i = 1
	
	while form do
		local genderlist = (gender or gender2) and {gender, gender2} or defgender and {defgender} or nil
		table.insert(forms, {term = form, translit = translit, gender = genderlist})

		i = i + 1
		form = ine(args[argpref .. i])
		translit = ine(args[argpref .. i .. "tr"])
		gender = ine(args[argpref .. i .. "g"])
		gender2 = ine(args[argpref .. i .. "g2"])
	end

	return forms
end

local function handle_infl(args, data, argpref, label, defgender)
	local newinfls = getargs(args, argpref, defgender)
	newinfls.label = label
	
	local accel_form = ''
	if argpref == 'a' then
		accel_form = 'annexió'
	elseif argpref == 'p' then
		accel_form = 'plural'
	elseif argpref == 'f' then
		accel_form = 'femenina'
	end
	if accel_form ~= '' then
		newinfls.accel = accel_form .. '-form-of'
	end
	
	if #newinfls > 0 then
		table.insert(data.inflections, newinfls)
	end
end

local function handle_all_infl(args, data, argpref, label, nobase)
	if not nobase and argpref ~= "" then
		handle_infl(args, data, argpref, label)
	end
	
	local labelsp = label == "" and "" or label .. " "
	handle_infl(args, data, argpref .. "a", labelsp .. "estat d'annexió")
	handle_infl(args, data, argpref .. "def", labelsp .. "definite state")
	handle_infl(args, data, argpref .. "obl", labelsp .. "oblique")
	handle_infl(args, data, argpref .. "inf", labelsp .. "informal")
end

-- Handle the case where pl=-, indicating an uncountable noun.
local function handle_noun_plural(args, data)
	if args["p"] == "-" then
		table.insert(data.inflections, {label = "normalment no comptable"})
	else
		handle_infl(args, data, "p", "plural")
	end
end

local valid_genders = list_to_set(
	{"m", "f", "m-p", "f-p", "p"})

local function is_masc_sg(g)
	return g == "m" 
end
local function is_fem_sg(g)
	return g == "f"
end

local function handle_gender(args, data, default, nonlemma)
	local g = ine(args["g"]) or default
	local g2 = ine(args["g2"])

	local function process_gender(g)
		if g then
			if valid_genders[g] then
				table.insert(data.genders, g)
			else
				error("Gènere no reconegut: " .. g)
			end
		end
	end

	process_gender(g)
	if g2 then
		process_gender(g2)
	end

	if nonlemma then
		return
	end
	
end

-- Part-of-speech functions

pos_functions["adjectives"] = {
	func = function(args, data)
		handle_all_infl(args, data, "", "")
		handle_all_infl(args, data, "f", "femení")
		handle_all_infl(args, data, "p", "masculí plural")
		handle_all_infl(args, data, "fp", "fememní plural")
	end
}

function handle_noun_infls(args, data, singonly)
	handle_all_infl(args, data, "", "") 

	if not singonly then
		handle_noun_plural(args, data)
		handle_all_infl(args, data, "p", "plural", "nobase")
	end
	
	handle_all_infl(args, data, "f", "femení")
	handle_all_infl(args, data, "m", "masculí")
end

pos_functions["Substantius"] = {
	func = function(args, data)
		handle_gender(args, data)
		handle_noun_infls(args, data)
		table.insert(data.categories, "Substantius en " .. lang.name)
	end
}

pos_functions["numerals"] = {
	func = function(args, data)
		table.insert(data.categories, "Numerals en " .. lang.name)
		handle_gender(args, data)
		handle_noun_infls(args, data)
	end
}

pos_functions["proper nouns"] = {
	func = function(args, data)
		handle_gender(args, data)
		handle_noun_infls(args, data, "singular only")
	end
}


pos_functions["pronouns"] = {
	params = {["g"] = {}},
	func = function(args, data)
		handle_gender(args, data)
		handle_all_infl(args, data, "f", "fememní")
		handle_all_infl(args, data, "p", "masculí plural")
		handle_all_infl(args, data, "fp", "fememní plural")
	end
}

return p