AIML <srai>
標記是一個多功能標籤。 此標記使AIML能夠為同一模板定義不同的目標。
語法
<srai> pattern </srai>
以下是與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步:建立類別
<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>
第2步: 使用<srai>
標籤建立通用類別
<category>
<pattern>DO YOU KNOW WHO * IS?</pattern>
<template>
<srai>WHO IS <star/></srai>
</template>
</category>
範例
在D:/software/ab/bots/test/aiml
目錄中建立檔案:srai.aiml,並在D:/software/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
執行程式
開啟命令提示字元,轉到目錄:D:/software/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.
分而治之用於重複使用子句來做出完整的回復。 它有助於減少定義多個類別。
例如,考慮以下對話。
Human: Bye
Robot: GoodBye!
Human: Bye Alice!
Robot: GoodBye!
每當使用者在句子開頭說Bye
時,機器人回復GoodBye!
。
在這裡將使用<srai>
標籤。參考以下實現步驟 -
第1步: 建立類別
<category>
<pattern>BYE</pattern>
<template>Good Bye!</template>
</category>
第2步: 使用<srai>
標籤建立通用類別
<category>
<pattern>BYE *</pattern>
<template>
<srai>BYE</srai>
</template>
</category>
範例
在D:/software/ab/bots/test/aiml
目錄中建立檔案:srai.aiml,並在D:/software/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>
</aiml>
檔案:srai.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
執行程式
開啟命令提示字元。 進入到目錄:D:/software/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!
每當使用者說Factory
或Industry
時,這裡機器人回復:Development Center!
在這裡使用<srai>
標籤表示來實現。
第1步: 建立類別
<category>
<pattern>FACTORY</pattern>
<template>Development Center!</template>
</category>
第2步: 使用<srai>
標籤建立通用類別
<category>
<pattern>INDUSTRY</pattern>
<template>
<srai>FACTORY</srai>
</template>
</category>
在D:/software/ab/bots/test/aiml
目錄中建立:srai.aiml 檔案,以及在D:/software/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>
檔案:srai.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
執行程式
開啟命令提示字元。 進入到目錄:D:/software/ab/
並鍵入以下命令 -
java -cp lib/Ab.jar Main bot = test action = chat trace = false
執行上面命令,得到以下結果 -
Human: Factory
Robot: Development Center!
Human: Industry
Robot: Development Center!
使用<srai>
標籤,當使用者鍵入特定關鍵詞時,可以返回一個簡單的響應,例如,無論句子中school
還是School
都一樣,它不分大小寫字母。
例如,請考慮以下對話。
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.
在這裡,每當使用者在句子中包含:School
時,機器人回復標準資訊:「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>
標籤建立通用類別 -
<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>
在D:/software/ab/bots/test/aiml
目錄中建立:srai.aiml 檔案,以及在D:/software/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>
檔案:srai.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
執行程式
開啟命令提示字元。 進入到目錄:D:/software/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.