% Semantics Principle

% Clause a

% Part I
% (head-adjunct structures and head-marker structures)

(phrase,
 daughters:(head_adj_struc;head_mark_struc,
	    hdtr:((word;phrase),
		  qstore:(e_list;ne_list),
		  retr:(e_list;ne_list)))) *>
(qstore:Qstore,
 retr:Retr,
 daughters:Const_struc)
goal (collect_dtrs_qstores(Const_struc,CollectedQstore),
      qstore_retrieval(Retr,Qstore,CollectedQstore)).


% Part II
% (head-complement structures)

(phrase,
 daughters:(head_comp_struc,
	    hdtr:((word;phrase),
		  qstore:(e_list;ne_list),
		  retr:(e_list;ne_list)),
	    c_dtrs:([];
	            hd:((word;phrase),
		       qstore:(e_list;(hd:quant)),
		       retr:(e_list;(hd:quant)))))) *>
(qstore:Qstore,
 retr:Retr,
 daughters:(Const_struc,
	    c_dtrs:Cdtrs))
goal (collect_dtrs_qstores(Const_struc,CollectedQstore),
      qstore_retrieval(Retr,Qstore,CollectedQstore)).


qstore_retrieval([],[],[]) if true.
qstore_retrieval([],(List,ne_list),List) if true.
qstore_retrieval((R,ne_list),Q,(List,ne_list)) if
                                length_limit(List), % set to max. 3 quantifiers
                                select_any_number_order(List,R,Q).

length_limit(X) if  X=([_];[_,_];[_,_,_]).
% can be increased if more than 3 quantifiers are allowed to co-occur

select_any_number_order(Input,[],Input) if true.
select_any_number_order(Input,[Ele|SInput],Restlist) if
                              select_one(Ele,Input,Rest),
		              select_any_number_order(Rest,SInput,Restlist).


select_one(Ele,[Ele|Rest],Rest) if true.
select_one(Ele,[Hd|Tail],[Hd|Rest]) if select_one(Ele,Tail,Rest).
