/** Memory - attaches a three three-proposition (where each proposition is composed of subject, verb and object) to a hierarchy of propositions, i.e. the position which for example when A->C is an element, the pair of items A->B and B->C is inserted below it. **/ %% insert_in_memory([[a,d],[[[a,c],[[a,b],[b,c]]],[c,d]]]). %% insert_in_memory([[a,d],[[[a,c],[[a,b],[b,c]]],[c,d]]]). %% insert_in_memory([[a,c]],[[a,b],[b,c]]). %%insert_in_memory(Items,Pair,List) :- %% insert_in_memory(Items,Pair,[],List). /** insert_in_memory([Item|[Items1,Items2]],[[A,B],[B,C]],[Item,[List,Items2]]) :- member([[A,C],Items2],Items1), insert_in_memory([[A,C],Items2],[[A,B],[B,C]],List). insert_in_memory([Item|[Items2,Items1]],[[A,B],[B,C]],[Item,[Items2,List]]) :- member([[A,C],Items2],Items1), insert_in_memory([[A,C],Items2],[[A,B],[B,C]],List). insert_in_memory([Item|[Items1]],[[A,B],[B,C]],[Item,[[[A,C],[[A,B],[B,C]]],Items2]]) :- delete(Items1,[A,C],[Items2]),insert_in_memory(. insert_in_memory([[A,C]],[[A,B],[B,C]],[[A,C],[[A,B],[B,C]]]). %%append([[A,C]],[[A,B],[B,C]],List). **/ %%insert_in_memory([[a,b],[a,c],[b,d]],[a,e]). insert_in_memory(List,[A,B],List5) :- find_start_of_sublist(List,A,List1), find_end_of_sublist(List1,A,List2), append(List3,List2,List), append(List3,[[A,B]],List4), append(List4,List2,List5),!. find_start_of_sublist([[A,_]|Rest],A,Rest). find_start_of_sublist([_|Rest],A,List1) :- find_start_of_sublist(Rest,A,List1). find_end_of_sublist([[A1,B]|Rest],A,[[A1,B]|Rest]) :- not(A1=A). find_end_of_sublist([[A,_]|Rest],A,List1) :- find_end_of_sublist(Rest,A,List1).