AIML - Balise <srai>

<srai>La balise est une balise polyvalente. Cette balise permet à AIML de définir les différentes cibles pour le même modèle.

Syntaxe

<srai> pattern </srai>

Voici les termes couramment utilisés associés à srai -

  • Réduction symbolique

  • Diviser et conquérir

  • Résolution des synonymes

  • Détection de mots-clés

Réduction symbolique

La technique de réduction symbolique est utilisée pour simplifier les motifs. Il aide à réduire les modèles grammaticaux complexes avec des modèles simples.

Par exemple, considérez la conversation suivante.

Human: Who was Albert Einstein?
Robot: Albert Einstein was a German physicist.
Human: Who was Isaac Newton?
Robot: Isaac Newton was a English physicist and mathematician.

Maintenant What if les questions sont soulevées comme

Human: DO YOU KNOW WHO Albert Einstein IS?
Human: DO YOU KNOW WHO Isaac Newton IS?

Ici, <srai> la balise fonctionne. Il peut prendre le modèle de l'utilisateur comme modèle.

Étape 1: créer des catégories

<category>
   <pattern>WHO IS ALBERT EINSTEIN?</pattern>
   <template>Albert Einstein was a German physicist.</template>
</category>

<category>
   <pattern> WHO IS Isaac NEWTON? </pattern>
   <template>Isaac Newton was a English physicist and mathematician.</template>
</category>

Étape 2: Créer une catégorie générique à l'aide de la balise <srai>

<category>
   <pattern>DO YOU KNOW WHO * IS?</pattern>
   
   <template>
      <srai>WHO IS <star/></srai>
   </template>
   
</category>

Exemple

Créez srai.aiml à l'intérieur C > ab > bots > test > aiml et srai.aiml.csv à l'intérieur C > ab > bots > test > aimlif répertoires.

srai.aiml

<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
   <category>
      <pattern> WHO IS ALBERT EINSTEIN </pattern>
      <template>Albert Einstein was a German physicist.</template>
   </category>
   
   <category>
      <pattern> WHO IS Isaac NEWTON </pattern>
      <template>Isaac Newton was a English physicist and mathematician.</template>
   </category>
   
   <category>
      <pattern>DO YOU KNOW WHO * IS</pattern>
      <template>
         <srai>WHO IS <star/></srai>
      </template>
   </category>
</aiml>

star.aiml.csv

0,WHO IS ALBERT EINSTEIN,*,*,Albert Einstein was a German physicist.,srai.aiml
0,WHO IS Isaac NEWTON,*,*,Isaac Newton was a English physicist and mathematician.,srai.aiml
0,DO YOU KNOW WHO * IS,*,*,<srai>WHO IS <star/></srai>,srai.aiml

Exécuter le programme

Ouvrez l'invite de commande. Aller àC > ab > et tapez la commande suivante -

java -cp lib/Ab.jar Main bot = test action = chat trace = false

Vérifiez le résultat

Vous verrez la sortie suivante -

Human: Do you know who Albert Einstein is
Robot: Albert Einstein was a German physicist.

Diviser et conquérir

Divide and Conquer est utilisé pour réutiliser des sous-phrases pour faire une réponse complète. Cela aide à réduire la définition de plusieurs catégories.

Par exemple, envisagez de suivre la conversation.

Human: Bye
Robot: GoodBye!
Human: Bye Alice!
Robot: GoodBye!

Maintenant, ici, le robot devrait répondre GoodBye! Chaque fois qu'un utilisateur dit Bye au début de la phrase.

Mettons la balise <srai> pour fonctionner ici.

Étape 1: créer une catégorie

<category>
   <pattern>BYE</pattern>
   <template>Good Bye!</template>
</category>

Étape 2: Créer une catégorie générique à l'aide de la balise <srai>

<category>
   <pattern>BYE *</pattern>
   
   <template>
      <srai>BYE</srai>
   </template>
   
</category>

Exemple

Mettre à jour srai.aiml à l'intérieur C > ab > bots > test > aiml et srai.aiml.csv à l'intérieur C > ab > bots > test > aimlif répertoires.

srai.aiml

<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
   <category>
      <pattern> WHO IS ALBERT EINSTEIN </pattern>
      <template>Albert Einstein was a German physicist.</template>
   </category>
 
   <category>
      <pattern> WHO IS Isaac NEWTON </pattern>
      <template>Isaac Newton was a English physicist and mathematician.</template>
   </category>
   
   <category>
      <pattern>DO YOU KNOW WHO * IS</pattern>
      <template>
         <srai>WHO IS <star/></srai>
      </template>
   </category>
   
   <category>
      <pattern>BYE</pattern>
      <template>Good Bye!</template>
   </category>
   
   <category>
      <pattern>BYE *</pattern>
      <template>
         <srai>BYE</srai>
      </template>
   </category>
   
</aiml>

star.aiml.csv

0,WHO IS ALBERT EINSTEIN,*,*,Albert Einstein was a German physicist.,srai.aiml
0,WHO IS Isaac NEWTON,*,*,Isaac Newton was a English physicist and mathematician.,srai.aiml
0,DO YOU KNOW WHO * IS,*,*,<srai>WHO IS <star/></srai>,srai.aiml
0,BYE,*,*,Good Bye!,srai.aiml
0,BYE *,*,*,<srai>BYE</srai>,srai.aiml

Exécuter le programme

Ouvrez l'invite de commande. Aller àC > ab > et tapez la commande suivante -

java -cp lib/Ab.jar Main bot = test action = chat trace = false

Vérifiez le résultat

Vous verrez la sortie suivante -

Human: Bye
Robot: GoodBye!
Human: Bye Alice!
Robot: GoodBye!

Synonymes Résolution

Les synonymes sont des mots avec des significations similaires. Un bot doit répondre de la même manière pour des mots similaires.

Par exemple, considérez la conversation suivante.

Human: Factory
Robot: Development Center!
Human: Industry
Robot: Development Center!

Maintenant, ici, le robot devrait répondre Development Center! chaque fois qu'un utilisateur dit Factory ou Industry.

Mettons <srai> tag pour travailler ici.

Étape 1: créer une catégorie

<category>
   <pattern>FACTORY</pattern>
   <template>Development Center!</template>
</category>

Étape 2: Créer une catégorie générique à l'aide de la balise <srai>

<category>
   <pattern>INDUSTRY</pattern>
   
   <template>
      <srai>FACTORY</srai>
   </template>
   
</category>

Exemple

Mettre à jour srai.aiml à l'intérieur C > ab > bots > test > aiml et srai.aiml.csv à l'intérieur C > ab > bots > test > aimlif répertoires.

srai.aiml

<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
   <category>
      <pattern> WHO IS ALBERT EINSTEIN </pattern>
      <template>Albert Einstein was a German physicist.</template>
   </category>
   
   <category>
      <pattern> WHO IS Isaac NEWTON </pattern>
      <template>Isaac Newton was a English physicist and mathematician.</template>
   </category>
   
   <category>
      <pattern>DO YOU KNOW WHO * IS</pattern>
      <template>
         <srai>WHO IS <star/></srai>
      </template>
   </category>
   
   <category>
      <pattern>BYE</pattern>
      <template>Good Bye!</template>
   </category>
   
   <category>
      <pattern>BYE *</pattern>
      <template>
         <srai>BYE</srai>
      </template>
   </category>
   
   <category>
      <pattern>FACTORY</pattern>
      <template>Development Center!</template>
   </category>
   
   <category>
      <pattern>INDUSTRY</pattern>
      <template>
         <srai>FACTORY</srai>
      </template>
   </category>
   
</aiml>

star.aiml.csv

0,WHO IS ALBERT EINSTEIN,*,*,Albert Einstein was a German physicist.,srai.aiml
0,WHO IS Isaac NEWTON,*,*,Isaac Newton was a English physicist and mathematician.,srai.aiml
0,DO YOU KNOW WHO * IS,*,*,<srai>WHO IS <star/></srai>,srai.aiml
0,BYE,*,*,Good Bye!,srai.aiml
0,BYE *,*,*,<srai>BYE</srai>,srai.aiml
0,FACTORY,*,*,Development Center!,srai.aiml
0,INDUSTRY,*,*,<srai>FACTORY</srai>,srai.aiml

Exécuter le programme

Ouvrez l'invite de commande. Aller àC > ab > et tapez la commande suivante -

java -cp lib/Ab.jar Main bot = test action = chat trace = false

Vérifiez le résultat

Vous verrez la sortie suivante -

Human: Factory
Robot: Development Center!
Human: Industry
Robot: Development Center!

Détection de mots-clés

En utilisant srai, nous pouvons renvoyer une réponse simple lorsque l'utilisateur tape un mot-clé spécifique, par exemple, École, peu importe où «école» est présente dans la phrase.

Par exemple, considérez la conversation suivante.

Human: I love going to school daily.
Robot: School is an important institution in a child's life.
Human: I like my school.
Robot: School is an important institution in a child's life.

Ici, le robot doit répondre à un message standard 'School is an important institution in a child's life.' chaque fois qu'un utilisateur a school dans la phrase.

Mettons <srai>tag pour travailler ici. Nous utiliserons des jokers ici.

Étape 1: créer une catégorie

<category>
   <pattern>SCHOOL</pattern>
   <template>School is an important institution in a child's life.</template>
</category>

Étape 2: Créez des catégories génériques à l'aide de la balise <srai>

<category>
   <pattern>_ SCHOOL</pattern>
   <template>
      <srai>SCHOOL</srai>
   </template>
</category>

<category>
   <pattern>_ SCHOOL</pattern>
   <template>
      <srai>SCHOOL</srai>
   </template>
</category>

<category>
   <pattern>SCHOOL *</pattern>
   <template>
      <srai>SCHOOL</srai>
   </template>
</category>

<category>
   <pattern>_ SCHOOL *</pattern>
   <template>
      <srai>SCHOOL</srai>
   </template>
</category>

Exemple

Mettre à jour srai.aiml à l'intérieur C > ab > bots > test > aiml et srai.aiml.csv à l'intérieur C > ab > bots > test > aimlif répertoires.

srai.aiml

<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
   <category>
      <pattern> WHO IS ALBERT EINSTEIN </pattern>
      <template>Albert Einstein was a German physicist.</template>
   </category>
   
   <category>
      <pattern> WHO IS Isaac NEWTON </pattern>
      <template>Isaac Newton was a English physicist and mathematician.</template>
   </category>
   
   <category>
      <pattern>DO YOU KNOW WHO * IS</pattern>
      <template>
         <srai>WHO IS <star/></srai>
      </template>
   </category>
   
   <category>
      <pattern>BYE</pattern>
      <template>Good Bye!</template>
   </category>
   
   <category>
      <pattern>BYE *</pattern>
      <template>
         <srai>BYE</srai>
      </template>
   </category>
   
   <category>
      <pattern>FACTORY</pattern>
      <template>Development Center!</template>
   </category>
   
   <category>
      <pattern>INDUSTRY</pattern>
      <template>
         <srai>FACTORY</srai>
      </template>
   </category>
   
   <category>
      <pattern>SCHOOL</pattern>
      <template>School is an important institution in a child's life.</template>
   </category>  
   
   <category>
      <pattern>_ SCHOOL</pattern>
      <template>
         <srai>SCHOOL</srai>
      </template>
   </category>
   
   <category>
      <pattern>_ SCHOOL</pattern>
      <template>
         <srai>SCHOOL</srai>
      </template>
   </category>
   
   <category>
      <pattern>SCHOOL *</pattern>
      <template>
         <srai>SCHOOL</srai>
      </template>
   </category>
   
   <category>
      <pattern>_ SCHOOL *</pattern>
      <template>
         <srai>SCHOOL</srai>
      </template>
   </category>
   
</aiml>

star.aiml.csv

0,WHO IS ALBERT EINSTEIN,*,*,Albert Einstein was a German physicist.,srai.aiml
0,WHO IS Isaac NEWTON,*,*,Isaac Newton was a English physicist and mathematician.,srai.aiml
0,DO YOU KNOW WHO * IS,*,*,<srai>WHO IS <star/></srai>,srai.aiml
0,BYE,*,*,Good Bye!,srai.aiml
0,BYE *,*,*,<srai>BYE</srai>,srai.aiml
0,FACTORY,*,*,Development Center!,srai.aiml
0,INDUSTRY,*,*,<srai>FACTORY</srai>,srai.aiml
0,SCHOOL,*,*,School is an important institution in a child's life.,srai.aiml
0,_ SCHOOL,*,*,<srai>SCHOOL</srai>,srai.aiml
0,SCHOOL *,*,*,<srai>SCHOOL</srai>,srai.aiml
0,_ SCHOOL *,*,*,<srai>SCHOOL</srai>,srai.aiml

Exécuter le programme

Ouvrez l'invite de commande. Aller àC > ab > et tapez la commande suivante -

java -cp lib/Ab.jar Main bot = test action = chat trace = false

Vérifiez le résultat

Vous verrez la sortie suivante -

Human: I love going to school daily.
Robot: School is an important institution in a child's life.
Human: I like my school.
Robot: School is an important institution in a child's life.