1

I need some help to understand AIML templates using an example below, your help is appreciated to get this template working.

These are some of the sample inputs I am trying to handle and output I want to generate from AIML parsing.

Input : sale abc
Output : SALES ABC

Input : sales abc
Output : SALES ABC

Input : sale of product abc
Output : SALES ABC

Input : sale product abc
Output : SALES ABC

Input : What is the sale of product abc
Output : SALES ABC

Input : What is the average sale of product abc
Output : AVG SALES ABC

Input : What is the avg sale of product abc Output : AVG SALES ABC

Input : What is the last 30 day average sale of product abc Output : AVG SALES ABC 30

Input : What is the last 30 day avg sale of product abc Output : AVG SALES ABC 30

I have been trying to start with something like this to begin with but this does not seem to progress well due to lack of clarity on this tool to me.

 <category><pattern>
    # <set>numbers</set>  <set>days</set>  <set>average</set> sales <set>prepositions</set> *</pattern>
  <template>SALES <star index="1"/>,<star index="2"/>,<star index="3"/>,<star index="4"/>,<star index="5"/>,<star index="6"/> </template>
  </category>

Where numbers set define > 1,2,3,4,5..... 100

Days set define > day, days

Average set define > average, avg , averages

Prepositions set define > of

Thanks!

Mark1234
  • 589
  • 2
  • 8
  • 24

1 Answers1

2

You should do this with wildcards rather than sets. The only sets you need are for your products and possibly a set for the number of days.

This category is the response to your first 4 queries:

<category>
    <pattern>SALE <set>products</set></pattern>
    <template>
        SALES <star/>
    </template>
</category>

We can now use wildcards to <srai> to call the master category:

<category>
    <pattern>SALES ^ <set>products</set> ^</pattern>
    <template>
        <srai>SALE <star index="2"/></srai>
    </template>
</category>

<category>
    <pattern>SALE ^ <set>products</set> ^</pattern>
    <template>
        <srai>SALE <star index="2"/></srai>
    </template>
</category>

<category>
    <pattern>WHAT IS THE SALE ^ <set>products</set> ^</pattern>
    <template>
        <srai>SALE <star index="2"/></srai>
    </template>
</category>

This category handles your next 2 queries:

<category>
    <pattern>WHAT IS ^ AVERAGE SALE ^ <set>products</set> ^</pattern>
    <template>
        AVG SALES <star index="3"/>
    </template>
</category>

We can use this to say that AVG means AVERAGE. You could also put this in your normal.substitutions file.

<category>
    <pattern>_ AVG *</pattern>
    <template>
        <srai><star/> average <star index="2"/></srai>
    </template>
</category>

Finally, this category handles your last 2 queries.

<category>
    <pattern>WHAT IS ^ LAST * DAY ^ AVERAGE SALE ^ <set>products</set> ^</pattern>
    <template>
        AVG SALES <star index="5"/> <star index="2"/>
    </template>
</category>
Steve Worswick
  • 880
  • 2
  • 5
  • 11
  • Thanks Steve, i am trying to work with your example. However i can not have a set of products as they are from the large universe, i would just like to pick that token, Also is there any built in support to identify date in user input? Thanks again for your help. – Mark1234 Aug 18 '20 at 16:57
  • 1
    In that case, you will need to put the word product in your pattern and pray that the users say "product." SALE OF PRODUCT * The second question about dates seems unrelated to this but if you post a new question, I'll take a look. – Steve Worswick Aug 18 '20 at 17:35