![]() |
|||||||
ProWeb: ElizaEliza was one of the first demonstrations of Prolog-based natural language processing. You play the part of the "patient" talking to Eliza, your psychiatrist. Programs such as Eliza were used in "The Turing Test" where volunteers had to work out whether they were having a conversation with a real person or an intelligent machine.
The Underlying Prolog ProgramThe essence of how Eliza works is to deconstruct the text of a natural language query, work out its semantic content, plan how to find the answer to the question and finally find and present that answer. Exactly the way Eliza does this is well documented in standard Prolog texts. Do not, however, expect too much of Eliza. In the current document, we only describe in any detail Eliza's ProWeb-based front end.
Developing the ProWeb Front-EndThis demonstration only uses three pages. The "initial" page welcomes the "patient" with the words, "Hello. I am ELIZA. How can I help you?", inviting them to enter an initial query. The "continue" page then displays Eliza's response to the query and invites the "patient" to give further information. Finally when the "patient" enters "quit", the "goodbye" page is displayed, with the words, "Goodbye. My secretary will send you a bill.".Each of these pages is created from the following Prolog code and template HTML files:
proweb_page( _, include('eliza/html/page.htm') ).
proweb_form( initial_form, include('eliza/html/initial.htm') ) :-
proweb_post_reply( eliza_reply, `Hello. I am ELIZA. How can I help you?` ).
proweb_form( continue_form(ClientSays-ElizaSays), include('eliza/html/continue.htm') ) :-
proweb_post_reply( client_last_query, ClientSays ),
proweb_post_reply( eliza_reply, ElizaSays ).
proweb_form( goodbye_form(ClientSays-ElizaSays), include('eliza/html/goodbye.htm') ) :-
proweb_post_reply( client_last_query, ClientSays ),
proweb_post_reply( eliza_reply, ElizaSays ).
Each of the three pages uses the one proweb_page/2 clause. This clause states that the structure of the HTML page to be generated by ProWeb is to come from the HTML template file, PAGE.HTM, the contents of which is as follows:
<HTML>
<HEAD>
</HEAD>
<BODY BACKGROUND="/lpa_back.jpg" BGCOLOR="#FFFFFF" TEXT="#000000"
LINK="#0000FF" VLINK="#FF0000" ALINK="#00FF00">
<TABLE>
<TD>
</TD>
<TD>
<FORM>
<PROWEB FORM>
</FORM>
<P><A HREF="/pws_dem.htm">Back to ProWeb Demos</A></P>
<P><A HREF="/index.htm" TARGET="_top">Visit the LPA Home Page!</A></P>
</TD>
</TABLE>
</BODY>
</HTML>
The form to be embedded into each of the three HTML pages generated by ProWeb is different so a template HTML file is provided for each - INITIAL.HTM, CONTINUE.HTM and GOODBYE.HTM. As they are included as part of a proweb_form/2 clause, ProWeb is only interested in the HTML code between the <FORM> tags; however such code has been wrapped up within additional HTML code so that the page can be viewed in a web browser independently of ProWeb.The HTML code for the Initial form (within the template INITIAL.HTM file) is as follows:
<HTML><HEAD></HEAD><BODY>
<FORM>
<H1>Welcome To The Eliza Example</H1>
<HR>
<TABLE>
<TR><TD ALIGN="right">Eliza:</TD><TD><B><I><PROWEB REPLY="eliza_reply"></I></B></TD></TR>
<TR><TD ALIGN="right">Client:</TD><TD><INPUT TYPE="text" NAME="client_reply" SIZE="50">
<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE="Submit">
</TD></TR>
</TABLE>
</FORM>
</BODY></HTML>
The HTML code for the Continue form (within the template CONTINUE.HTM file) is as follows:
<HTML><HEAD></HEAD><BODY>
<FORM>
<H1>The Eliza Example</H1>
<HR>
<TABLE>
<TR><TD ALIGN="right">Client:</TD><TD><B><PROWEB REPLY="client_last_query"></B></TD></TR>
<TR><TD ALIGN="right">Eliza:</TD><TD><B><I><PROWEB REPLY="eliza_reply"></I></B></TD></TR>
<TR><TD ALIGN="right">Client:</TD><TD><INPUT TYPE="text" NAME="client_reply" SIZE="50">
<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE="Submit">
</TD></TR>
</TABLE>
</FORM>
</BODY></HTML>
You will note that the form is defined simply in HTML with no special <PROWEB> tags.The HTML code for the Goodbye form (within the template GOODBYE.HTM file) is as follows:
<HTML><HEAD></HEAD><BODY> <FORM> <H1>Goodbye From The Eliza Example</H1> <HR> <TABLE> <TR><TD ALIGN="right">Client:</TD><TD><B><PROWEB REPLY="client_last_query"></B></TD></TR> <TR><TD ALIGN="right">Eliza:</TD><TD><B><I><PROWEB REPLY="eliza_reply"></I></B></TD></TR> </TABLE> </FORM> </BODY></HTML>The Initial and the Continue page each invite the "patient" to give more information.
The main goal for this example is eliza_pw/0, as shown below:
eliza_pw :-
retractall( mem(_) ),
proweb_send_form( initial_form ),
proweb_returned_input( client_reply, AtomClientSays ),
atom_string( AtomClientSays, ClientSays ),
ClientSays \= ``,
eliza_main( ClientSays, ElizaSays ),
(
ElizaSays = `Goodbye. My secretary will send you a bill.`
-> proweb_send_form( goodbye_form(ClientSays-ElizaSays) )
; proweb_resend_form( continue_form(ClientSays-ElizaSays) )
).
eliza_pw :-
proweb_resend_form( continue_form(``-`You're very quiet.`) ).
Any entered natural language question is passed to the underlying Eliza program (not documented here) via eliza_main/0, a modified version of eliza/0 especially written for ProWeb; after a short while, a response to the question is received:
% A ProWeb-aware version of eliza/0 in eliza.pl. eliza_main( ClientSays, ElizaSays ) :- read_atomics(Input) <~ ClientSays, process_input(Input,[],Input2), simplify(Input2,Input3), findkeywords(Input3,KeyWords), sortkeywords(KeyWords,KeyWords2), makecomment(KeyWords2,Input3,Comment), flatten(Comment,Comment2), writecomment(Comment2) ~> ElizaSays. |