Search code examples
aiml

How to find multiple patterns in single category using AIML


I have been using AIML to make chatbot. I am unable to find multiple patterns in same category. How can we use OR clause in the pattern?


Solution

  • In AIML version 2, you can do this using sets or maps. Basically you define the set which is a list of one or more members, then you can refer to it in the pattern. Imagine you had a set with the names of the countries of the world, you could code this:

    <category>
      <pattern>IS <set>countries</set> A COUNTRY</pattern>
      <template>
        Yes, <star/> is a country.
      </template>
    </category>
    
    <category>
      <pattern>IS * A COUNTRY</pattern>
      <template>
        I never heard of a country called <star/>.
      </template>
    </category>
    

    This works because the set is higher priority than the star in AIML version 2. So if you typed IS GERMANY A COUNTRY it would reply "Yes, Germany is a country". But if you typed IS EREWHON A COUNTRY it would reply "I never heard of a country called Erewhon".