AIML - Tag <condizione>
<condition>Il tag è simile alle istruzioni switch nel linguaggio di programmazione. Aiuta ALICE a rispondere all'input corrispondente.
Sintassi
<condition name = "variable-name" value = "variable-value"/>Ad esempio, considera la seguente conversazione.
Human: How are you feeling today
Robot: I am happy!Qui abbiamo archiviato happy come lo stato di ALICE ed è così che risponde come "Sono felice!".
Esempio
Crea condition.aiml all'interno C > ab > bots > test > aiml e condition.aiml.csv all'interno C > ab > bots > test > aimlif directory.
condition.aiml
<?xml version = "1.0" encoding = "UTF-8"?>
<aiml version = "1.0.1" encoding = "UTF-8"?>
   <category>
      <pattern> HOW ARE YOU FEELING TODAY </pattern>
      
      <template>
         <think><set name = "state"> happy</set></think>
         <condition name = "state" value = "happy">
            I am happy!
         </condition>
         
         <condition name = "state" value = "sad">
            I am sad!
         </condition>
      </template>
      
   </category>
</aiml>condition.aiml.csv
0,HOW ARE YOU FEELING TODAY,*,*,
   <think>
      <set name = "state"> happy</set>
   </think>
   
   <condition name = "state" value = "happy">I am happy!</condition>
   <condition name = "state" value = "sad">I am sad!</condition>,condition.aimlEsegui il programma
Apri il prompt dei comandi. Vai aC > ab > e digita il seguente comando:
java -cp lib/Ab.jar Main bot = test action = chat trace = falseVerifica il risultato
Vedrai il seguente output:
Human: How are you feeling today
Robot: I am happy!