/*qa*/ /*Question Answering system based on Eliza Alan Bundy 16.11.79 use with readin, eliza and infer*/ /*top level*/ qa :- read_in(Input), qa(Input). qa([bye,.]) :- !. qa(Input) :- translate(Input,Desc,Type), answer(Type,Desc), qa. /*translation*/ translate(Input,Desc,Type) :- sm_triple(S,D,Type), match(Input,S,off,Subst), replace1(Subst,D,Desc). /*replace variables by phrases in description*/ replace1(Subst,Word,Word) :- (atomic(Word); var(Word)), !. replace1(Subst,?Var,Phrase) :- !, member(Phrase/Var,Subst). replace1(Subst,D,Desc) :- D =.. [Sym|Args], not(Args = []), !, maplist(replace1(Subst),Args,NewArgs), Desc =.. [Sym|NewArgs]. /*answer writer on basis of type and description*/ answer(assertion,Desc) :- assert_fact(Desc), writef('ok\n',[]). answer(rule-assertion,(Ant->Consq)) :- assert(backward_rule(Ant,Consq)), writef('asserting rule %t implies %t \n',[Ant,Consq]), writef('ok\n',[]). answer(yes/no-question,Desc) :- (infer(Desc) -> writef('yes\n',[]); writef('dont know\n',[]) ). answer(wh-question,Desc) :- variables(Desc,Vars), (infer(Desc) -> checklist(print_list,Vars); writef('dont know\n',[]) ). /*stimulus meaning table*/ sm_triple([all,?p,are,?q,.],([?p,X] -> [?q,X]),rule-assertion). sm_triple([is,?t,?p,?],[?p,?t],yes/no-question). sm_triple([who,is,a,?p,?q,?],[?p,X] & [?q,X],wh-question). sm_triple([?t,is,?p,.],[?p,?t],assertion).