AIML - Tag <srai>
<srai>Tag é uma tag multiuso. Esta tag permite que o AIML defina os diferentes alvos para o mesmo modelo.
Sintaxe
<srai> pattern </srai>
A seguir estão os termos comumente usados associados a srai -
Redução Simbólica
Dividir e conquistar
Resolução de sinônimos
Detecção de palavras-chave
Redução Simbólica
A técnica de redução simbólica é usada para simplificar padrões. Ajuda a reduzir padrões gramaticais complexos com padrões simples.
Por exemplo, considere a seguinte conversa.
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.
Agora What if questões são levantadas como
Human: DO YOU KNOW WHO Albert Einstein IS?
Human: DO YOU KNOW WHO Isaac Newton IS?
Aqui, <srai> tag funciona. Ele pode usar o padrão do usuário como um modelo.
Etapa 1: criar categorias
<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>
Etapa 2: Crie uma categoria genérica usando a tag <srai>
<category>
<pattern>DO YOU KNOW WHO * IS?</pattern>
<template>
<srai>WHO IS <star/></srai>
</template>
</category>
Exemplo
Crie srai.aiml dentro C > ab > bots > test > aiml e srai.aiml.csv dentro C > ab > bots > test > aimlif diretórios.
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
Execute o programa
Abra o prompt de comando. Vamos paraC > ab > e digite o seguinte comando -
java -cp lib/Ab.jar Main bot = test action = chat trace = false
Verifique o resultado
Você verá a seguinte saída -
Human: Do you know who Albert Einstein is
Robot: Albert Einstein was a German physicist.
Dividir e conquistar
Divide and Conquer é usado para reutilizar sub frases ao fazer uma resposta completa. Ajuda a reduzir a definição de várias categorias.
Por exemplo, considere seguir uma conversa.
Human: Bye
Robot: GoodBye!
Human: Bye Alice!
Robot: GoodBye!
Agora, aqui o robô deve responder GoodBye! Sempre que um usuário diz Bye no início da frase.
Vamos colocar a tag <srai> para funcionar aqui.
Etapa 1: Criar categoria
<category>
<pattern>BYE</pattern>
<template>Good Bye!</template>
</category>
Etapa 2: Crie uma categoria genérica usando a tag <srai>
<category>
<pattern>BYE *</pattern>
<template>
<srai>BYE</srai>
</template>
</category>
Exemplo
Atualize srai.aiml dentro C > ab > bots > test > aiml e srai.aiml.csv dentro C > ab > bots > test > aimlif diretórios.
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
Execute o programa
Abra o prompt de comando. Vamos paraC > ab > e digite o seguinte comando -
java -cp lib/Ab.jar Main bot = test action = chat trace = false
Verifique o resultado
Você verá a seguinte saída -
Human: Bye
Robot: GoodBye!
Human: Bye Alice!
Robot: GoodBye!
Resolução de sinônimos
Sinônimos são palavras com significados semelhantes. Um bot deve responder da mesma maneira para palavras semelhantes.
Por exemplo, considere a seguinte conversa.
Human: Factory
Robot: Development Center!
Human: Industry
Robot: Development Center!
Agora, aqui o robô deve responder Development Center! sempre que um usuário diz Factory ou Industry.
Vamos colocar <srai> tag para trabalhar aqui.
Etapa 1: Criar categoria
<category>
<pattern>FACTORY</pattern>
<template>Development Center!</template>
</category>
Etapa 2: Crie uma categoria genérica usando a tag <srai>
<category>
<pattern>INDUSTRY</pattern>
<template>
<srai>FACTORY</srai>
</template>
</category>
Exemplo
Atualize srai.aiml dentro C > ab > bots > test > aiml e srai.aiml.csv dentro C > ab > bots > test > aimlif diretórios.
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
Execute o programa
Abra o prompt de comando. Vamos paraC > ab > e digite o seguinte comando -
java -cp lib/Ab.jar Main bot = test action = chat trace = false
Verifique o resultado
Você verá a seguinte saída -
Human: Factory
Robot: Development Center!
Human: Industry
Robot: Development Center!
Detecção de palavras-chave
Usando srai, podemos retornar uma resposta simples quando o usuário digita uma palavra-chave específica, por exemplo, Escola, não importa onde "escola" esteja presente na frase.
Por exemplo, considere a seguinte conversa.
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.
Aqui, o robô deve responder a uma mensagem padrão 'School is an important institution in a child's life.' sempre que um usuário tem school na frase.
Vamos colocar <srai>tag para trabalhar aqui. Usaremos curingas aqui.
Etapa 1: Criar categoria
<category>
<pattern>SCHOOL</pattern>
<template>School is an important institution in a child's life.</template>
</category>
Etapa 2: Crie categorias genéricas usando a tag <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>
Exemplo
Atualize srai.aiml dentro C > ab > bots > test > aiml e srai.aiml.csv dentro C > ab > bots > test > aimlif diretórios.
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
Execute o programa
Abra o prompt de comando. Vamos paraC > ab > e digite o seguinte comando -
java -cp lib/Ab.jar Main bot = test action = chat trace = false
Verifique o resultado
Você verá a seguinte saída -
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.