% Adam Farquhar % 4/17/95 % % Convert prolog terms representing first order sentences to KIF. % % mixed case % quoting of strings % % Known problems: % we don't properly escape kif symbols from the corresponding prolog % atoms. E.g. an atom 'ab c : d' should be |ab c : d| or should it be % |AB C : D|? Perhaps the decision to use mixed case in producing the % prolog atoms was not a good one. % :- op(400,fy,-), % negation op(500,xfy,&), % conjunction op(600,xfy,v), % disjunction op(650,xfy,=>), % implication op(700,xfy,<=>). % equivalence pl_to_kif_file(Pl_File,Kif_File) :- open(Pl_File,read,In), open(Kif_File,write,Out), pl_to_kif_stream(In,Out). pl_to_kif_stream(In,Out) :- read(In,First), pl_to_kif_stream(First,In,Out). pl_to_kif_stream(end_of_file,In,Out) :- close(In), close(Out). pl_to_kif_stream(Formula,In,Out) :- pl_to_kif(Formula,Out), nl(Out), read(In,Next), pl_to_kif_stream(Next,In,Out). pl_to_kif(X) :- pl_to_kif(X,user_output). pl_to_kif(X,S) :- var(X), !, write(S, '?'), write(S,X). pl_to_kif(-X, S) :- !, pl_to_kif(not(X),S). pl_to_kif(&(X,Y),S) :- !, pl_to_kif(and(X,Y), S). pl_to_kif(v(X,Y),S) :- !, pl_to_kif(or(X,Y), S). pl_to_kif([H|T],S) :- write(S,'('), pl_to_kif(H,S), pl_to_kif_list_body(T,S), write(S,')'). pl_to_kif(X,S) :- atomic(X) -> write(S,X) ; (X =.. List, pl_to_kif(List,S)). pl_to_kif_list_body([],_). pl_to_kif_list_body([H|T],S) :- write(S, ' '), pl_to_kif(H,S), pl_to_kif_list_body(T,S). kif_string(X) :- atom(X), name(X,[34|_]).