%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  OPERADORES LOGICOS DIFUSOS
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Para AND
execute_fcond(Label, tree(and, T1, T2), element(Label,Attr,Sons)) <- {!} &prod
	                        execute_fcond(Label, T1, element(Label,Attr,Sons)) &prod
				execute_fcond(Label, T2, element(Label,Attr,Sons)).

% Para OR
execute_fcond(Label, tree(or, T1, T2), element(Label,Attr,Sons)) <- {!} &prod
				|prod(
	                        	execute_fcond(Label, T1, element(Label,Attr,Sons)),
					execute_fcond(Label, T2, element(Label,Attr,Sons))
				).

% Para AVG
execute_fcond(Label, tree(avg, T1, T2), element(Label,Attr,Sons)) <- {!} &prod
				@prod(
	                        	execute_fcond(Label, T1, element(Label,Attr,Sons)),
					execute_fcond(Label, T2, element(Label,Attr,Sons)),
					tv(1,_),
					tv(1,_)
				).

execute_fcond(Label, tree(avg(A,B), T1, T2), element(Label,Attr,Sons)) <- {!} &prod
				@prod(
		                        execute_fcond(Label, T1, element(Label,Attr,Sons)),
					execute_fcond(Label, T2, element(Label,Attr,Sons)),
					tv(A,_),
					tv(B,_)
				).


% Cuando solo existe un solo elemento.
execute_fcond(Label, tree(Exp,nil,nil), element(Label,Attr,Sons)) <- {!} &prod
	                        execute_feq(Label, Exp, element(Label,Attr,Sons)).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% OPERADORES RELACIONALES
%
% Las condiciones son basicamente iguales, solamente cambia el signo
% > < = la condicion... por lo que se recomienda buscar una manera de
% simplificar estos.
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% inicialmente consideramos que A es solo un tag, y no una Ruta..., verificar que pasa si es una ruta

execute_feq(Label, A<B, element(Label,Attr,_)) <- {!} &prod
	@less(
		tv(1,[B,[],[]]),
		fuzzyXPath([Label, A], [element(Label, Attr, _)], 1, 1), % devuelve listado con todos los valores encontrados
	).

execute_feq(Label, A>B, element(Label,Attr,_)) <- {!} &prod
	@greater(
		tv(1,[B,[],[]]),
		fuzzyXPath([Label, A], [element(Label, Attr, _)], 1, 1), % devuelve listado con todos los valores encontrados
	).

execute_feq(Label, A=B, element(Label,Attr,_)) <- {!} &prod
	@equal(
		tv(1,[B,[],[]]),
		fuzzyXPath([Label, A], [element(Label, Attr, _)], 1, 1), % devuelve listado con todos los valores encontrados
	).
