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..

Detect if output in rule
 
 

Is there a way to detect whether the current rule has generated output while still in the same rule?

Here is a fragment…

u: ()
 
# Loaded some data into a fact set ...

 # Generate the first part of a response
 
[There are $$numReps people reporting to you]
 [You have 
$$numReps reportees]
 [Your team contains 
$$numReps people]
 [
$$numReps <= 5 ]
 
 
^if ($$numReps <= 5)
 
{
  
^if (^response(1) != "")  # *** What really want is to know if any of the first 3 responses was output
  
{
   [
They are]
   [
,]
  }
  
^printNames(@20)
 

That is, if the 4th option was selected, then don’t go on to output any response with punctuation. Just output a list of names.

 

 

 
  [ # 1 ]

There are two kinds of user output, pending and committed. Pending output occurs when you just dump words as part of your data (like in your example). Should the rule fail, it will be scrubbed. Should the rule succeed, it will be committed (and subsequent failures of other rules or topics will not impact it). Also, if you try to leave the rule via gambit or respond or reuse or refine, that will commit your pending output (as will calling flushoutput). You can also directly create commited output by calling a function like print.

You can detect committed output.  at the start of your rule do $$tmp = %response.  Later you can see if $$tmp != %response (each commitment will increase the index value returned by %response.

 

 
  [ # 2 ]

OK, so I can only detect committed output, and I can force that with ^flushoutput().
I think I can live with that in my situation.

Thanks.

 

 
  [ # 3 ]

And sometimes I just need to think harder!

This works better for me, even if the output is split into two places, because there is not a space between the two text fragments.

outputmacro: ^reporteeCountMsg(^numReps)
 
[There are ^numReps people reporting to you]
 [You have 
^numReps reportees]
 [Your team contains 
^numReps people]
 [
^numReps <= 5 ]


u
: ()

 $
$repCountMsg = ^nofail(RULE ^reporteeCountMsg($$numReps))
 
 ^if ($
$numReps <= 5)
 
{
  
^if ($$repCountMsg)
  
{
   
$$repCountMsg
   
   [
They are]
   [
:]
  }
  
^printNames(@20)
 

 

 

 
  [ # 4 ]

Although in this context there is no way for your macro to fail, so you dont need to call it nofail.

 

 
  [ # 5 ]

Actually I found that I did need the ^nofail(). If the macro picked the 4th choice, which is an empty response, then it was marked as failed.

 

 
  [ # 6 ]

My mistake.

I misunderstood the syntax for tests at the start of a optional response. It is for the existence of a variable only and so [^numReps <= 5 ] was always true because ^numReps was always there. But that means that the “<= 5”  caused the failure bit to be set, and no text to be output.

Anyway I’ve fixed my macro and yes I don’t need the ^nofail() wrapper.

 

 
  login or register to react
‹‹ query from a set      Jsongather crash ››