- 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 - <set>、<get> 標籤
<set> 和 <get> 標籤用於在 AIML 中使用變數。變數可以是預定義變數或程式設計師建立的變數。
語法規則
<set> 標籤用於在變數中設定值。
<set name = "variable-name"> variable-value </set>
<get> 標籤用於從變數中獲取值。
<get name = "variable-name"></get>
例如,思考一下以下對話。
Human: I am Mahesh Robot: Hello Mahesh! Human: Good Night Robot: Good Night Mahesh! Thanks for the conversation!
例子
在 C > ab > bots > test > aiml 中建立 setget.aiml,在 C > ab > bots > test > aimlif 中建立 setget.aiml.csv。
setget.aiml
<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
<category>
<pattern>I am *</pattern>
<template>
Hello <set name = "username"> <star/>! </set>
</template>
</category>
<category>
<pattern>Good Night</pattern>
<template>
Hi <get name = "username"/> Thanks for the conversation!
</template>
</category>
</aiml>
setget.aiml.csv
0,I am *,*,*, Hello <set name = "username"> <star/>! </set>,setget.aiml 0,Good Night,*,*, Hi <get name = "username"/> Thanks for the conversation!,setget.aiml
執行程式
開啟命令提示符。轉到 C > ab >,然後鍵入以下命令 −
java -cp lib/Ab.jar Main bot = test action = chat trace = false
驗證結果
你將看到以下輸出 −
Human: I am Mahesh Robot: Hello Mahesh! Human: Good Night Robot: Good Night Mahesh! Thanks for the conversation!
廣告