AIML - < srai>标签

< srai> 标签是一种多用途标签.此标记使AIML能够为同一模板定义不同的目标.

语法

 <srai&gt pattern </srai&gt


以下是与 srai相关的常用术语 :

  • 符号缩减

  • 分而治之

  • 同义词解析

  • 关键字检测

符号缩减

符号缩减技术用于简化模式.它有助于用简单的模式减少复杂的语法模式.

例如,考虑以下对话.

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.


现在如果提出问题

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


此处,< srai> 标签有效.它可以将用户的模式作为模板.

步骤1:创建类别

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


第2步:使用< srai&gt标签创建通用类别

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


示例

C > ab > bots > test > aiml内创建srai.aiml 和C > ab > bots > test > aimlif 目录场景srai.aiml.csv .

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

执行程序

打开命令提示符.转到 C> ab> 并输入以下命令 :

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


验证结果

您将看到以下输出 :

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


分而治之

Divide and Conquer用于在完成回复时重复使用子句.它有助于减少定义多个类别.

例如,考虑以下对话.

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


现在,机器人应该回复 GoodBye!每当用户在开头的时候说再见句子.

让我们把< srai>标签放到这里工作.

第1步:创建类别

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


第2步:使用< srai&gt标签创建通用类别

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


示例

更新C > ab > bots > test > aiml 内的srai.aiml 和C > ab > bots > test > aimlif目录的srai.aiml.csv .

srai.aiml

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


执行程序

打开命令提示符.转到 C> ab> 并输入以下命令 :

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


验证结果

您将看到以下输出 :

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


同义词解析

同义词是具有相似含义的词.机器人应该以相同的方式回复类似的单词.

例如,考虑以下对话.

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


现在,只要用户说出工厂或<b,机器人就会回复开发中心!>行业.

让我们在这里使用< srai> 标签.

第1步:创建类别

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


第2步:使用< srai>创建通用类别标签

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

示例

更新C > ab > bots > test > aiml 内的srai.aiml 和C > ab > bots > test > aimlif目录的srai.aiml.csv .

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


执行程序

打开命令提示符.转到 C> ab> 并输入以下命令 :

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


验证结果

您将看到以下输出 :

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


关键字检测

使用 srai ,我们可以在用户返回简单响应键入一个特定的关键词,比如学校,无论句子中出现"学校".

例如,考虑以下对话.

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.


在这里,机器人应该回复标准信息'学校是儿童生活中的重要机构.'每当用户在句子中学校.

让我们在这里使用< srai> 标签.我们将在这里使用通配符.

第1步:创建类别

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


第2步:使用< srai&gt标签创建通用类别

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

示例

更新C > ab > bots > test > aiml 内的srai.aiml 和C > ab > bots > test > aimlif目录的srai.aiml.csv .

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


执行程序

打开命令提示符.转到 C> ab> 并输入以下命令 :

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


验证结果

您将看到以下输出 :

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.