/* Filename: trans.pro Programmer: Br. David Carlson Date of creation: April 4, 1991 Revised: December 15, 1999 to run under yap. Based on ideas in Neil Rowe's Artificial Intelligence Through Prolog, pp 89 - 90. Description: This program will read sentences from the keyboard, translate them to a more readable form, and write the results to the screen. Start the program with the goal: go. */ go :- write('Enter your sentence 1 word per line, with a . after each word.'), nl, write('Use all lower case. Use CTRL d to end data entry.'), nl, readWords(WordList), nl, print_list(WordList), nl, process(WordList). readWords([Head | Tail]) :- read(Head), Head \== end_of_file, !, readWords(Tail). readWords([]). process(L) :- translate(L, S), print_list(S). translate([], []) :- !. translate(List, NewList) :- substitute(Item, NewItem), append(Item, Rest, List), translate(Rest, NewRest), append(NewItem, NewRest, NewList). translate([Head | Tail], [Head | NewTail]) :- translate(Tail, NewTail). append([], L, L) :- !. append([X | L1], L2, [X | L3]) :- append(L1, L2, L3). substitute([adversely, impact], [hurt]). substitute([negatively, impact], [hurt]). substitute([impact], [affect]). substitute([will, transition], [will, change]). substitute([must, transition], [must, change]). substitute([to, transition], [to, change]). substitute([consider, options], [study]). substitute([evaluate, options], [study]). substitute([under, advisement], [being, studied]). substitute([under, consideration], [being, studied]). substitute([expedite], [move, along]). substitute([expeditiously], [quickly]). substitute([prioritize], [rank]). substitute([key, to], [important, to]). substitute([director, of, janitorial, services], [head, janitor]). print_list([]). /* do nothing to print the empty list */ print_list([Head | Tail]) :- write(Head), write(' '), print_list(Tail).