Overview of
the parse () Function
The parse() function declares the bit stream pattern as an
array of twenty characters, then it initialises the array to
null. It creates an array to hold the output of up to two hundred
and fifty characters. Parse() begins by breaking down the
incoming sentence into numerical values to give the bit stream
pattern. The function uses two counters to compare each string in
the sentence to the words in each lexical array in order to
identify them as either a verb, adjective, interrogative etc. On
discovering a match, the bit stream pattern is assigned the
numerical value of the lexical array i.e. verb is 4,
interrogative is 6. For example, the bit stream pattern that
would be assigned to "What does he like?" is 6434,
interrogative, verb, pronoun and verb.
At the end of the parse() function there is a list of patterns
that the program considers to be correct. At the moment, the list
consists of two patterns. The patterns considered to be legal to
the program are extensible. If the pattern is considered to be
legal, it is passed to response(). If this is not the case, an
error messages is selected at random and passed to display(). For
example, " I beg your pardon" or "I don�t
understand the question".
Overview of
the response () Function
Response() takes as its argument, a pointer to pattern. That
is, the address of pattern is passed to the function. The
function creates an array for the response of up to two hundred
and fifty six characters, and initialises it to null or empty. In
this function a flag �ok� is created as an integer
value. The flag is used as a switch. If it is set to 0, a line of
code is read. If it is set to 1, the same line of code is not
read. This was for simplicity. It is worth mentioning only
because it is the only use of a flag in the program.
At points in response(), the statement "If the pattern of
the question is a match for this pattern then do this"
appears. If the answer is true, the following code will be
executed. If not, the program will jump to the next occurrence of
the same statement, holding a different pattern. The code that
handles each pattern will generate a response using a different
grammatical structure.
For the example "what does he like?" the match is
pattern 643. The number �6� represents an
interrogative. The list of interrogatives is now given a question
identity. �What� now has an ident_question identity of
�What�. The question identity will be used to match the
response to a suitable collection of templates, from the template
file.
The rewrite rules then look at the input pronoun and select an
appropriate response for whichever one is used. The verb is then
examined in order to make a grammatically correct response. If
the sentence is longer than three words (which is the length of
the pattern in this case), the next word is examined. If the next
word is a verb listed in the lexicon, then it is included in the
response. If the first verb is �does�, then the second
verb may have to have �s� or �es� added to
it. The rewrite rules perform this. In our example, the response
generated should be "he likes�.". However,
"What do you like" should return "I
like�.". If the fourth word in the input sentence is a
prepositional, the remainder of the sentence is taken into the
response. For example, " Why is he here today in this
rain?" should return "he is here today in this
rain�". The examples show that it is possible to write
code that deals with the pattern of the input sentence and to
generate a response that is grammatically correct. If transitive
and intransitive verbs had been listed as separate classes, this
would be more apparent. If a transitive verb is found in the
sentence, the rest of the sentence could be included in the
response, as it is with the prepositional.
Once a response has been generated, it is inserted into a
template from the template file. This is one of the reasons for
having question identities. The last two commands in response()
are to pass the sentence and the question identity to
templ_database() and display(outp) which sends to display() the
output, returned from templ_database.
 
|