Skip to content

Tutorial Sets

Keith Sterling edited this page Sep 25, 2017 · 7 revisions

Sets

Sets are essentially a collection of similar words that you can use within a <pattern> tag to simplify the pattern matching capabilities. Instead of separate categories to capture every possible grammar allowing the user to state that they like a color, we can have a single grammar that makes use of a set of colours, as follows

<category>
    <pattern> I LIKE THE COLOR <set name="colors"></pattern>
    <template>
        That is great, I like that color too.
    </template>
</category>

The set above references a name attribute with a value 'colors'. This references a file stored in the directory that is referenced by the configuration option

brain:
  sets:
    files: $BOT_ROOT/sets
    extension: .txt
    directories: false

For more information on the settings, see the section Brain File Configuration

If you were to add this grammar to your bot and execute. You can then ask any question about like a color, as long as that colors name is contained within the set file colors.txt

Loading, please wait...
No bot root argument set, defaulting to [.]
Y-Bot version 0.0.1, initiated March 14, 2017
Hi, how can I help you today?
>>> I like the color red
That is great, I like that color too.
>>> I like the color green
That is great, I like that color too.

Creating your own Set

Lets create a new set for the types of cars.

  1. Create a file and give it the name of the set you want to use. Don't worry about case, set name lookup is case insensitive, so cars.txt, CARS.txt and Cars.txt will all be considered the same set

  2. Fill the set with names of all the cars you want in the set. Again don't worry about case, set contents lookup is case insensitive.

       Saab
       Ford
       Vauxhall
       Peugeot       
       Honda
       Nissan
       BMW
       Mercedes
  1. Next, create a grammar that can make use of the set in the AIML folder of your bot.
<category>
    <pattern> I DRIVE A <set name="cars"></pattern>
    <template>
        Hey, I have always wanted to drive one of them.
    </template>
</category>
  1. Reload the bot, and check the log file to make sure that the new grammar has been loaded without any issues.

  2. You can now interact with your bot using the new grammar and set

Loading, please wait...
No bot root argument set, defaulting to [.]
Y-Bot version 0.0.1, initiated March 14, 2017
Hi, how can I help you today?
>>> I drive a Ford
Hey, I have always wanted to drive one of them.
>>> I drive a Saab
Hey, I have always wanted to drive one of them.

Inbuilt Sets

  • Numeric

Dynamic Sets

Dynamic Sets

For more information about the template set tag, see the wiki page Sets

Clone this wiki locally