AIML <star>標記


<star>標籤用於匹配<pattern>標籤中的萬用字元*字元。

語法

<star index = "n"/>

n表示<pattern>標籤中使用者輸入中*的位置。

參考以下範例 -

<category>
   <pattern> A * is a *. </pattern>

   <template>
      When a <star index = "1"/> is not a <star index = "2"/>?
   </template>

</category>

如果使用者輸入"A mango is a fruit."。 那麼機器人會回答:"When a mango is not a fruit?"

範例

D:/software/ab/bots/test/aiml目錄中建立一個檔案:star.aiml,並在D:/software/ab/bots/test/aimlif目錄中建立一個檔案:star.aiml.csv

檔案:star.aiml -

<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>

   <category>
      <pattern>I LIKE *</pattern>
      <template>
         I too like <star/>.
      </template>
   </category>

   <category>
      <pattern>A * IS A *</pattern>
      <template>
         How <star index = "1"/> can not be a <star index = "2"/>?
      </template>
   </category>

</aiml>

檔案:star.aiml.csv -

0,I LIKE *,*,*,I too like <star/>.,star.aiml
0,A * IS A *,*,*,How <star index = "1"/> can not be a <star index = "2"/>?,star.aiml

執行程式

開啟命令提示字元。 轉到D:/software/ab目錄並鍵入以下命令 -

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

將看到以下輸出 -

Human: I like mango
Robot: I too like mango.
Human: A mango is a fruit
Robot: How mango can not be a fruit?