![]() |
|||||||
ProWeb: Chat-80Originally published nearly two decades ago by researchers at Edinburgh University, Chat-80 was one of the first major demonstrations of Prolog-based natural language processing. Now in the public domain, Chat-80 provides a fascinating sample application, comprising a natural language interface to a geographical database. Please note that this demonstration uses the original 1980 data: one or two countries have appeared, vanished, or been renamed since then!
The Underlying Prolog ProgramThe essence of how Chat-80 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 Chat-80 does this is well documented in standard Prolog texts. In the current document, we only describe in any detail its ProWeb-based front end.Please note that the geographical data originates from 1980 and has not been updated for this demonstration.
Developing the ProWeb Front-EndThis demonstration only uses three pages. The "initial" page welcomes the client to the Chat-80 example, asking them to enter an initial query. The "continue" page then displays Chat-80's answer to the query and invites the client to enter another query. Finally when the user enters "bye", or leaves the query field blank, a final "goodbye" page is displayed, thanking the client for using Chat-80.Each of these pages is created from the following Prolog code and template HTML files:
proweb_page( _, include('chat80\html\page.htm') ).
proweb_form( initial_form, include('chat80/html/initial.htm') ).
proweb_form( continue_form, include('chat80/html/continue.htm') ).
proweb_form( goodbye_form, include('chat80/html/goodbye.htm') ).
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><TITLE></TITLE></HEAD><BODY>
<FORM>
<H1>Welcome To The Chat-80 ProWeb Example</H1>
<HR>
<TABLE CELLSPACING=5 CELLPADDING=5>
<TR>
<TD WIDTH=80%>Please enter the text of your next query in
the edit box below...</TD>
<TD WIDTH=20><A HREF="/pws_data/pws/examples/chat80/chateg.htm">
Sample Queries</A></TD>
</TR>
<TR>
<TD><PROWEB QUESTION="chat_query"></TD>
<TD><INPUT TYPE=SUBMIT NAME=SUBMIT VALUE="Submit"></TD>
</TR>
<TR><TD><P><P><P></TD></TR>
</TABLE>
</FORM>
</BODY></HTML>
The HTML code for the Continue form (within the template CONTINUE.HTM file) is as follows:
<HTML><HEAD><TITLE></TITLE></HEAD><BODY>
<FORM>
<H1>The Chat-80 ProWeb Example</H1>
<HR>
<TABLE CELLSPACING=5 CELLPADDING=5>
<TR>
<TD WIDTH=20%>You asked...</TD>
<TD WIDTH=80%><H4><PROWEB
REPLY="chat_last_query"></H4></TD>
</TR>
<TR>
<TD>Chat-80 says...</TD>
<TD><H4><PROWEB REPLY="chat_answer"></H4></TD>
</TR>
<TR><TD><P><P><P></TD></TR>
<TR>
<TD WIDTH=80%>Please enter the text of your next query in
the edit box below...</TD>
<TD WIDTH=20><A HREF="/pws_data/pws/examples/chat80/chateg.htm">
Sample Queries</A></TD>
</TR>
<TR>
<TD><PROWEB QUESTION="chat_query"></TD>
<TD><INPUT TYPE=SUBMIT NAME=SUBMIT VALUE="Submit"></TD>
</TR>
</TABLE>
</FORM>
</BODY></HTML>
The HTML code for the Goodbye form (within the template GOODBYE.HTM file) is as follows:
<HTML><HEAD><TITLE></TITLE></HEAD><BODY> <FORM> <H1>Goodbye From The Chat-80 ProWeb Example</H1> <HR> <TABLE CELLSPACING=5 CELLPADDING=5> <TD>Thank you for using the Chat-80 example.</TD> </TABLE> </FORM> </BODY></HTML>The Initial and the Continue page each invite the client to enter a query. This is defined by the following Prolog code:
proweb_question( chat_query, [ method = input, type = string, cols = 72, prefill = Answer ] ) :- ( proweb_returned_answer( chat_query, Answer ) -> true ; Answer = `` ).The main goal for this example is top_chat/0, as shown below:
top_chat :-
ensure_loaded( 'examples\chat80\chat' ),
proweb_send_form( initial_form ),
proweb_returned_answer( chat_query, ChatQuery ),
( ChatQuery = ``
-> proweb_send_form( goodbye_form )
; process_query( ChatQuery, ChatAnswer ),
( ChatAnswer = `bye`
-> proweb_send_form( goodbye_form )
; proweb_post_reply( chat_last_query,
unencoded @ ChatQuery ),
proweb_post_reply( chat_answer,
unencoded @ ChatAnswer ),
proweb_resend_form( continue_form )
)
).
Any entered natural language question is passed to the underlying Chat-80 program (not documented here); after a short while, an answer to the question is received:
process_query(Query,Response) :-
catch( ReadError, read_in( Words ) <~ Query ),
!,
( ReadError = 0
-> catch( ControlError, control( Words ) ) ~> Response
; cat( [Query,`.`],DotQuery,_),
catch( DotReadError, read_in(DotWords) <~ DotQuery ),
!,
( DotReadError = 0
-> catch( DotControlError, control( DotWords ) )
~> Response
; error_message( ReadError, Message),
write( Message ) ~> Response
)
).
Should the client be totally confused as to how to formulate a query, a hyperlink to a page of sample queries is provided.
|