AI Zone Admin Forum Add your forum

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

Store name of called pattern macro in variable

Is it somehow possible to save the name of a pattern macro, that was used during patternmatching, in a variable to put it in an oob-message for example for debugging?

Right now i have a lot of different pattern macros, that analyse the intent behind a user question, for example “places_together”, “activity_together” or “personal_opinion”.

The pattern macros may repeat themselves from one topic to the other, so that i can ask for ^activity_together with person1 and ^activity_together with person2.

My go to solution was to have a $$intent variable after each call of a specific patternmacro and type out the name of the pattern macro myself.

Like this:

topic: ~brother_t ()

#specific questions/answers depending on general context
u: () ^keep() ^refine()
# name
a: (^names()) $$intent=names Leon 
# age
a: (^age()) $$intent=age Der ist 12. 

Is there a more elegant way to do this? It would be already helpful if could somehow memorise the pattern macro name and do something like $$intent=_0. Would save a lot of typing smile

Or maybe i can’t see the forest for the trees and there is a completely different solution.


  [ # 1 ]

First off, in the most recent release of CS you can do assignment onto matchvariables so your pattern could end with something like _10:=names

Second off, you can put labels on your rules, and then grab the rule label locally, though if you have generated output from that rule, then you can just write a single call to get the rule that fired in a postcontrol topic


  [ # 2 ]

Thanks for the quick reply!

For your first suggestion, i have to get my finger on an windows machine to try that out, as im working on a mac (i assume its still some version behind the most recent release)

As for the second suggestion: my problem is, that some intent rules are sending the input further down to other responses to generate output (via ^respond()), that have already a rule label on it. I assume that i could only get the label of the last fired rule in a postcontrol topic right?


  [ # 3 ]

Hermann, check out ^callstack() to see if that helps you out.
We use that function in some places to determine where a code block is called from.


  [ # 4 ]

a post topic can access the rule and the refine that got you the output. But no, if you are calling respond from some rule and wanted to know that THAT was the rule that caused output to be generated much deeper down, you have to have that rule set a flag to tell you that. Eg
  $_response = %response
  if ($_response != %response) {$caller = RULEICAREABOUT} 

Is this what you want?

Alternatively if your rule labels you care about have a std pattern, for every rule that ACTUALLY makes output, you could use the ^callstack to find out how you got there and hunt for a rule name following your std pattern


  [ # 5 ]

Thanks Bruce & Andy for the ^callstack advice. Could you maybe give me an example of one of your use cases? Unfortunately i won’t get any wiser via the manual on how and where to implement it into my code.

I think the corresponding passage in the manual is this one:

ˆcallstack ( @n )
Generates a list of transient facts into the named factset. The facts represent the callstack and have as subject the critical value (the verb is callstack and the object is the rule tag responsible for this entry). Items include function calls
(ˆxxxx) and topic calls (~xxxx) and internal calls (no prefix).

So here i was 1. not sure what to use as @n and 2. where to place it best, as i don’t know, where this list is being put out.

2.  $_response = %response
3.  ^respond(~generateoutput)
4.  if ($_response != %response) {$caller = RULEICAREABOUT}

Im not sure if i get this here and how it differs logically from my initial approach. Here you would compare the response of the last volley (step 2) with the current one (step 4) and if they differ, than the RULEICAREBOUT becomes the caller variable correct?



  login or register to react