(AIML)- 5. AIML 標記

(AIML)- 5. AIML <srai>標記

AIML <srai>標記

 

AIML<srai>標記是一個多功能標籤。此標記使AIML能夠為同一模板定義不同的目標。

 

語法

<srai> pattern </srai>
以下是與srai相關的常用術語-


5.1 符號定義

符號定義技術用於簡化模式,它有助於用簡單的模式減少複雜的語法模式。

 

例如,請考慮以下對話。

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>

 

Example :

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

 

5.2 分而治之

分而治之為重複使用子句來完成完整的回覆。它有助於減少定義多個類別。

 

例如,考慮以下對話。

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>

 

Example : 

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

 

5.3 名詞解析

機器人應該以相同的方式回覆類似的單詞。

 

例如,請考慮以下對話。

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!

5.4 檢測


使用<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時,機器人回覆標准信息:“學校是兒童生活中的重要機構。”。

在這裡使用<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.

 

 

免責聲明:

1.本影像檔案皆從網上搜集轉載,不承擔任何技術及版權問題。

2.如有下載連結僅供寬頻測試研究用途,請下載後在24小時內刪除,請勿用於商業。

3.若侵犯了您的合法權益,請來信通知我們,我們會及時刪除,給您帶來的不便,深表歉意。



發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *