/** 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],A). A = [[a, b], [a, c], [a, e], [b, d]] ; %%insert_in_memory([[a,b],[a,c],[b,d]],[a,e]). insert_in_memory(List1,[A,B],List2) :- find_start_of_sublist(List1,A,List3), find_end_of_sublist(List3,A,List4), append(List5,List4,List1), append(List5,[[A,B]],List6), append(List6,List4,List2),!. 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).**/ l(List1,[A,B],List2) :- append(List3,[[A,B1]|Rest],List1), append(List4,[[A1,B2]|Rest2],Rest), not(A=A1), append(List3,[[A,B1]],List5), append(List5,List4,List6), append(List6,[[A,B]],List7), append(List7,[[A1,B2]],List8), append(List8,Rest2,List2).