- AIML 教程
- AIML - 首頁
- AIML - 簡介
- AIML - 環境設定
- AIML - 第一個應用
- AIML - 基本標籤
- AIML - <star> 標籤
- AIML - <srai> 標籤
- AIML - <random> 標籤
- AIML - <set>,<get> 標籤
- AIML - <that> 標籤
- AIML - <topic> 標籤
- AIML - <think> 標籤
- AIML - <condition> 標籤
- AIML 有用資源
- AIML - 快速指南
- AIML - 有用資源
- AIML - 討論
AIML - <srai> 標籤
<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>
示例
在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.
分治法
分治法用於在構建完整回覆時重用子句。它有助於減少定義多個類別的需要。
例如,考慮以下對話。
Human: Bye Robot: GoodBye! Human: Bye Alice! Robot: GoodBye!
現在,只要使用者在句首說再見,機器人就應該回復再見!。
讓我們在這裡使用<srai>標籤。
步驟 1:建立類別
<category> <pattern>BYE</pattern> <template>Good Bye!</template> </category>
步驟 2:使用<srai>標籤建立通用類別
<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
<?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
執行程式
開啟命令提示符。進入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!
現在,每當使用者說工廠或工業時,機器人應該回復開發中心!。
讓我們在這裡使用<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>標籤建立通用類別
<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.