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

ChatScript collections
 
 

Hi,
I can’t seem to find any implementation of collections in CS.

I would like to be able to replace something like this:

u: (cond1)  $$var1 =1
u: (cond2)  $$var2 =0
u: ():
if $$var1==1 and $$var2==1)
  respond something

with this:

u: (cond1)  $$col1.add(1)
u: (cond2)  $$col1.add(0)
u: ():
  for $$col1….
 

Basically, any collection would do, but off course variations like lists and hash would be nice.

If I’m missing something, please point me in the right direction.

Thanks

 

 
  [ # 1 ]

Depends on what you are REALLY trying to do.  JSON arrays exist that you can add to and iterate thru

 

 
  [ # 2 ]

Hi Bruce,
As a starting point the idea is to use the fact that if no output generated than the condition matching continues.
That provides some interesting possibilities. Basically think about two (in my case it can be much more) independent conditions that are matched without generating any output, only adding to a collection. Later on, I would be able to use a macro to decide based on the collection what kind of output to return.
As a side advantage, this could allow for creating simpler conditions and combining them, instead of some complex ones. It will also allow me to deal with responses in a single place instead of replicating them numerous times.


The actual case is relatively simple. I’m trying to generate some rules from code, instead of creating them manually. The reason for that is that the data is constantly changing on the back end, so it would not be easy to update the rules manually all the time. That means that I mostly use << >> matching. Meaning that the first match will be used, while there is a high possibility there are more. Instead, I would prefer to hit all matches and when done respond based on the collection of those matches.
Hope this gives you a better idea. Any suggestions will be really appreciated.


Thanks for JSON arrays suggestion, I’m looking into it, looks very promising.

 

 
  [ # 3 ]

That’s fine.  JSON arrays whose values are text strings and are either labels or internal rule tags.  Then you could execute them via ^reuse when you choose one.

 

 
  [ # 4 ]

if I understand correctly ^jsonarrayinsert doesn’t return any value.
Is there any way to get the index of inserted value?
Wouldn’t it be reasonable for this function just to return the index (and in case of unique to return the index of existing item)?

 

 
  [ # 5 ]

you can always call ^length immediately afterwards

 

 
  [ # 6 ]

making it return a value will likely break existing scripts, because people are not expecting the return value so it will go to user output

 

 
  [ # 7 ]
Bruce Wilcox - Jun 28, 2017:

you can always call ^length immediately afterwards

Yes, but that would not give me the index in case a unique value was not inserted.

Anyhow, I’m just trying to understand this topic, and looking for a best way to do what I have in mind, and there are almost no real life examples I could find.

Thanks

 

 
  [ # 8 ]

insertion in middle does not happen. If you try to add a value already there, it is not added. You can do length before and after

 

 
  [ # 9 ]
Bruce Wilcox - Jun 29, 2017:

insertion in middle does not happen. If you try to add a value already there, it is not added. You can do length before and after

Yes, exactly, nothing is added, but there is no way to get the index of the item that is identical to the one I was trying to add. length would not help in that case.

[‘one’, ‘two’, ‘three’,‘four’]

if I try to add ‘two’ using unique tag, it will not be added, but it would be nice to be able to get the index (1) without looping over the whole list.

This is really not a critical thing.

Thanks a lot for your replies and help!!!

 

 
  [ # 10 ]

you CAN get the index.  Just use ^query(direct_so $arrayref ? $value 1)

 

 
  [ # 11 ]

That works, thanks!

 

 
  login or register to react