[go: up one dir, main page]
More Web Proxy on the site http://driver.im/Jump to content

Module:gd-art-len

From Wiktionary, the free dictionary


local export = {}

function export._getParameters(frame_args, arg_list)
	local new_args = {};
	local index = 1;
	local value;
	
	for _, arg in ipairs(arg_list) do
		value = frame_args[arg]
		if value == nil then
			value = frame_args[index];
			index = index + 1;
		end
		new_args[arg] = value;
	end
	
	return new_args;
end

local function has_value (tab, val)
    for index, value in ipairs(tab) do
        if value == val then
            return true
        end
    end

    return false
end

local function lenite_s(cluster)
	if string.len(cluster) == 1 then
		return cluster .. 'h'
	else
		return cluster:sub(1, 1) .. 'h' .. cluster:sub(2, string.len(cluster))
	end
end

function export.show(frame)
	local new_args = export._getParameters(frame.args, { 'g', 'n', 'case', 'init' });
	local gender = new_args['g'] or 'm';
	local init_letters = new_args['init'] or '';
	local case = new_args['case'] or 'nom';
	local number = new_args['n'] or 'sg';

	local vowels = {
		"a", "e", "i", "o", "u",
		"A", "E", "I", "O", "U",
		"à", "è", "ì", "ò", "ù",
		"À", "È", "Ì", "Ò", "Ù"
	};
	local velars = { "c", "g", "C", "G" };
	local dentals = { 
		"t", "d",
		"T", "D",
	};
	local labials = { "p", "b", "m", "P", "B", "M", "f", "F" };
	local s_clusters = {
		"sa", "se", "si", "so", "su",
		"Sa", "Se", "Si", "So", "Su",
		"sà", "sè", "sì", "sò", "sù",
		"Sà", "Sè", "Sì", "Sò", "Sù",
		"sl", "sn", "sr",
		"Sl", "Sn", "Sr", "s", "S"
	};

	if case == 'voc' then
		if has_value(velars, init_letters) or has_value(dentals, init_letters) 
		or has_value(labials, init_letters) then
			return init_letters .. 'h'
		elseif has_value(s_clusters, init_letters) then
			return lenite_s(init_letters)
		else return init_letters 
		end
	end

	if gender == 'm' then
		if number == 'sg' then
			if case == 'nom' then
				if has_value(vowels, init_letters) or init_letters == '' then
					return 't-' .. init_letters
				end
				return init_letters
			elseif case == 'gen' or case == 'dat' then
				if has_value(velars, init_letters) or has_value(labials, init_letters) then
				   	return init_letters .. 'h'
				elseif has_value(s_clusters, init_letters) then
					return 't-' .. init_letters
				end
				return init_letters
			end
		elseif number == 'pl' then
			if case == 'nom' or case == 'dat' then
				if has_value(vowels, init_letters) or init_letters == '' then
					return 'h-' .. init_letters
				end
				return init_letters
			end
			return init_letters
		end
	elseif gender == 'f' then
		if number == 'sg' then
			if case == 'nom' or case == 'dat' then
				if has_value(velars, init_letters) or has_value(labials, init_letters) then
				   	return init_letters .. 'h'
				elseif has_value(s_clusters, init_letters) then
					return 't-' .. init_letters
				end
				return init_letters
			elseif case == 'gen' then
				if has_value(vowels, init_letters) or init_letters == '' then
					return 'h-' .. init_letters
				end
				return init_letters				
			end
		elseif number == 'pl' then
			if case == 'nom' or case == 'dat' then
				if has_value(vowels, init_letters) or init_letters == '' then
					return 'h-' .. init_letters
				end
				return init_letters
			end
			return init_letters
		end
	end

	return init_letters
end

return export