AI Zone Admin Forum Add your forum

NEWS: Chatbots.org survey on 3000 US and UK consumers shows it is time for chatbot integration in customer service!read more..

Newbie question - How do I process multiple sentences in one user volley?
 
 

Can some kind person give me or point me to a fully-worked example of how to process multiple sentences in one user input?  I can’t find one in the manual or tutorial.  Is there a repository of worked examples somehwere?

I understand the ^query part on facts, but not the overall high-level processing structure for the multiple-sentence input.

So, say the user asks:  What is your name and address?
Or to be sure the questions are different topics,  “What is your name and who do you think will win the election?

So,  first we’d have to figure out that these input sentences are really two separate questions, I guess, and change the input to:  “What is your name? What is your address?” and substitute that for what the user said.

  I THINK that would involve something like:
          [figure stuff out]
          ^input ( What is your address ?)
          ^input ( What is your name ? )
          ^fail(SENTENCE)

( ? maybe ?)

At that point, or some similar point, we now have as replacement input two distinct questions on unrelated topics (suppose.) 

It’s not clear to me what they are input TO, either after the processing described above, or after the user simply types two questions and hits <enter>.

Are we still in the context of the topic? Or is this as if the user had simply typed these two questions and the engine still has to figure out what topic each one belongs to?  Or is this where something like ^fail(TOPIC) should happen to force a fresh look?

And,  further,  what patterns would my rules look for?  Should a pattern attempt to match
the FIRST incoming question only?  Should there be a wildcard at the end to absorb the second question? 

Do I somehow use %more ?
And if I use %more and realize there’s more sentences, how do I complete output, if I feel like it at this point, and then shift my focus to the next sentence?

Thank you.

Wade

       

 

 
  [ # 1 ]

There are really two parts to this discussion. How do I process two independent sentences, and how do I take a single combined sentence and process it as two.  And is it even necessary to process it as two independent sentences.

First, a philosophical point. If the user asks what is your name and address, you can imagine replying to both as a single output. If the user asks “do you like cheese and what is your mother’s name”, this is kind of bizarre and NOTHING requres you answer both parts of it. You could answer just one part and ignore the other, letting the user ask again the other part if they really want to know.

Next, an understanding of flow of control.  Flow is always
1. run a preprocess topic before processing the user’s input
2. process each sentence of user input
3. run a postprocess topic after processing all user input

It is perfectly legitimate to split the user’s input as you described.  At the time you are doing that, you are processing the only sentence of the user input. When you say ^input(...)  you ask the system to insert ANOTHER sentence after the current user sentence. In your example, you do that twice.  So user input looks like
“what is your name and address” - current input being processed
“what is your address?” - pending user input
“what is your name?” - pending user input
(note flip of order based on using Input twice).

You then FAIL the current sentence, cancelling the composite actual user input. The system now moves to #2 on what is your address. After that sentence is done, it would move on to #2 on what is your name.
The actual SIMPLE control logic given would only output a single answer, as its code depends on %response == 0. 
One must at the start of the control logic memorize the current response count $$tmpresponse = %response and change all tests on %response == 0 thereafter to %response == $$tmpresponse, so the system can tell when an output has been generated for the current input sentence, not has been generated to any input sentence.

Things would be similar if the user had ACTUALLY done two sentences as input, you’d need to change simple control to accept multiple outputs, one for each sentence of input.

%more and %morequestion come into play in more elaborate control structures. If the user’s 1st sentence is a statement and his next is a question, for example, you might choose to IGNORE the first sentence and just answer the question.
u: (%morequestion) ^FAIL(SENTENCE)

There is no right answer on control, it’s just how you think the system should manage multiple inputs from the user. I have some fairly elaborate rules, myself. If the bot asked the user a question and the user’s 1st input is a short statement, I can often presume it’s a response to the question, and if the user has followed with more sentences, just ignore reacting to the 1st input.  Or if there are not more sentences, treat his input as an “OK” and move along to the next gambit in a topic.  Etc.

 

 
  [ # 2 ]

Then there is the possibility of merely accumulating an output and dumping it as the last minute….

You write patterns like (using particularly lazy and overly specific patterns)
u: (what is * your * name)  create $$tmp as the intended output
u: (what is * your * address)  if ($$tmp exists) add “and” and the next answer to it

then at the end of main processing (or even at the beginning of postprocessing) you could output $$tmp.
If at the end of main processing, it would be u: (!%more) $$tmp
Whereas if at the beginning of postprocessing it would be t: ^postprocessprint( $$tmp) as one choice.

It’s simpler and clearer to process multiple sentences instead of accumulating.

 

 
  [ # 3 ]

Thank you Bruce!

Since I’m still in “mostly overwhelmed” mode, I had considered SimpleControl.top to be inviolate and “The Engine” and tried to avoid looking at it.  Now I finally understand that SimpleControl.top is just one special sort of TOPIC for the actual Engine, and I should get to know it and will probably need to alter it someday.

Thanks for the unexpected excellent advice too, of not feeling obliged in conversation to answer everything the user asks.

Anyway,  I used your comments to solve the problem ( in skeleton form ) using the existing SimpleControl.top.

Here’s the transcript of a run:

#HARRY:_ Welcome to ChatScript.
#wade:_> what is your name?
#HARRY:_ My name is Angela.
#wade:_> what is your address?
#HARRY:_ I live at 123 River Drive.
#wade:_> what is your name and address?
#HARRY:_ My name is Angela, and I live at 123 River Drive.
#wade:_> what is your name? what is your address?
#HARRY:_ My name is Angela, and I live at 123 River Drive.

The SimpleTopic.top I used is attached.  Basically, I just added “repeat noerase” to the INTRODUCTIONS topic,  added “name address”
to the keywords for the top (for this example),  and put in these three rules that only took me about an hour (sigh) to get tweaked right, so I’m sharing them.

#! What is your name and address?
u: (“what is your name and address”)
  ^input( What is your name? What is your address? )
  ^NextInput()
  ^retry(TOPIC)

#! what is your name
#! what is your name ? what is your address ?
u: (what is your name)
          #^print( in question what is your name \n )
          if (!%more) { My name is Angela . }
          else {$$tmp = My_name_is_Angela,_and_
NextInput()
^retry(TOPIC) }
          # but output nothing so %response is still == 0
          # so simplecontrol.top will move on to the next sentence.

#! what is your address ?
u: (what is your address)
          #^print (in question what is your address \n )
          if (^notnull( $$tmp )) { $$tmp = ^join( $$tmp
I_live_at_123_River_Drive._ ) }
          else { $$tmp = I_live_at_123_River_Drive._ }
          ^eval($$tmp)

Wade

File Attachments
simpletopic.zip  (File Size: 1KB - Downloads: 71)
 

 
  [ # 4 ]

Being overwhelmed is a natural state of existence. And ChatScript has LOTS to overwhelm you, it’s not for someone who wants to build a trivial bot—AIML already exists for that. ChatScript is intended for “industrial strength” potentially complex systems, although one can build simple bots in it.

u: (“what is your name and address”)
Technically there is no reason to put this in quotes.  Quoted expressions (phrases) are nominally limited to 5 words in a row, so I’m somewhat surprised this works for you.

Using 2 sentences in ^input was cute, as was immediately switching to the first with NextInput and then telling the system to retry the topic. However, I would not normally do that, because I segregate kinds of processing into lots of different topics, so there is no reason for me to assume that the current topic would be the appropriate place to start processing the new sentence. Hence my normal idiom of ^fail(SENTENCE).

Then, I’d normally use the canonical “be” in
u: (what be your name)
because that would match “what was your name” “what is your name” “what am your name” etc. Expecting good english out of the user is wishing for a lot.

I don’t see the need for ^eval($$tmp).  Isn’t   $$tmp sufficient? Also, in the interests of generality, I’d put that on its own rule at the end. Then you can have any number of other rules building up the answer.

u: ($$tmp !%more) $$tmp

There are other optimizations I could suggest, but as you said, you’re in overwhelm… so you don’t need more from me

 

 

 
  [ # 5 ]

By the way, congratulations on truly understanding that the simplecontrol topic is just another topic, in a sense like any other, and there is nothing inviolate about it. One of the unique features of chatscript is that you can almost completely control its processing, peek into what it did, and control what it does based on that information. Which makes it possible to write really ugly messy control scripts that do bizarrely strange things.  Hence I separate all sorts of different kinds of control processing into separate topics. But simplecontrol is just that, a sort of minimal control topic to get one started.

 

 
  [ # 6 ]

I responded to your comment in a new topic - “What are Chatscripts’ theoretical limits?”

 

 
  [ # 7 ]

Thank you Wade for posting this question regarding how to process multiple sentences.  I also have had the same question but I keep rereading the manuals and each time I find something new because my understanding keeps improving with each reading.  I was also avoiding looking at the simplecontrol.top file after my initial peek under the hood.

Thanks Bruce! for taking the time to respond to the posts on this forum.  Your clarifications are very valuable and I appreciate the detail and your patience with those of us just starting with Chatscript.

I would like to offer my experience following Bruce’s instructions above.

I was able copy the simplecontrol.top file in the RAWDATA folder to another file I called multiplesentencecontrol.top.  I modified the files1.txt file and changed the line RAWDATA/simplecontrol.top to RAWDATA/multiplesentencecontrol.top.  In the file multiplesentencecontrol.top I added ”  $$tempresponse = %response” in the main sentence processing section as follows:

u: ($code=main) # main per-sentence processing

          $$tempresponse = %response

I changed all instances of “%response ==  0” to “%response ==  $$tempresponse”.  I also changed instances of “(%response !=  0)”  to “(%response !=  $$tempresponse) “.

This is all that was needed to allow chatscript to respond to each sentence.  Whether this is desirable or not is another question and Bruce has already discussed ways to ignore or fail sentences and to “look ahead” to consider multiple sentences together.

 

 
  [ # 8 ]

Modifying Chatscripts control files to process multiple statements has allowed for input and output such as the following:

alaric:_> Are robins birds? Can a bird fly?
HARRY:_ I don’t know if robins are birds. I am not sure if a bird can fly.
alaric:_> Robins are birds.  Birds can fly.  So can a robin fly?
HARRY:_ Ok. Robins are birds. Ok. Birds can fly. Yes,  a robin can fly.
alaric:_> A mouse is a mammal.  A mammal is a creature.  Creatures need air.  Do
es a mouse need air?
HARRY:_ Ok. A mouse is a mammal. Ok. A mammal is a creature. Ok. Creatures need
air. Yes,  a mouse needs air.
alaric:_>

I am working on a chatbot that I hope would be able to process different sorts of simple math word problems.  I have been experimenting with the creation and search of simple facts.  The great thing with Chatscript is that with a few output macros and a few patterns that simple output like the above can be created.  Having the ability to process and output multiple sentences is a great feature.  Again, thanks for this post.

 

 
  login or register to react