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

Using the same pattern multiple times on the same input
 
 

Hello to all the forum members,

This is my first question here, and I’m somewhat new to ChatScript. (which to my experience is great platform and many thanks to the author for open sourcing it)

I’ve gathered a lot of facts about specific topic and I want to be able to write big and generic pattern that will catch wide variety of input and extract information into user facts set.

Input examples:

[ol][li]computer with HD screen, speakers, mouse and keyboard [/li][li]red car with great speaker system[/li][li]big room with air conditioner and wide window[/li][/ol]
etc…

As you can tell the input consist of one subject and one or more objects as properties.

So far I have rule like this (the syntax is not exactly what I have I don’t have the code right now in front of me):

s: EXTRACT_PROPERTIES (_~subject *~1 {with} {a} {and} *~1 _~object)
^query(direct_svo _~subject has_a _~object)

If the query is not failed then I save the data in facts set specific to the user.
The goal is to catch in the first time the subject and the first property and in the second time the subject and the second property and so on…

My question is mainly about good code design:
How to use the same rule and repeat it again and again until it failed?

I can try to use ^refine \ ^reuse but before I’ll try it later today I’d love to hear from who ever had experience with this kind of patterns \ rules.

Secondly, I’d love to check out scripts similar to this to get some ideas on how to design reusable / modular / generic rules and code. so if there is something online (or in the folders of the project) please let me know.

Thanks in advance

Sam

 

 
  [ # 1 ]

the general function you want is ^retry(RULE), however chatscript can only shift the first match, which is your subject. So what you are looking for is this:
s: (__subject) $subject = ‘_0 refine()
  a: (_~object ^query(direct_svo _~subject has_a _~object)) ... ^retry(RULE)
although you might want the query outside the pattern since stopping when you dont find something in the query is not a guarantee that the next object also wont be in the query.

 

 
  [ # 2 ]

Thanks Bruce Wilcox, it works perfectly!

 

 
  login or register to react