AIML Elements Detailed description

Source: Internet
Author: User
Tags knowledge base
Preface:

Intelligent Customer Service Consulting function of the implementation of the main rely on is the Python AIML library, here first introduced under AIML.
Detailed use of the tutorial can be referred to: Https://github.com/andelf/PyAIML
At present, most AIML only support the Py2.7 version and do not support Chinese, even if there is support Py3 and support Chinese version, aiml some of the functions are also some defects, but Huang Tian, after the blogger constantly search, finally found a relatively stable Py3 version of the AIML.
Address: HTTPS://GITHUB.COM/SHUANG0420/AIML
Later bloggers will release their own projects, then we can also be interested in the reference. 1. Introduction

AIML is the abbreviation for artificial Intelligence Markup language, which describes a class of objects called AIML, and partly describes the performance of computer programs in processing these objects. AIML is the derivation of the XML language (Extensible Markup Language).

The Aiml object is made up of topic and category units, and the formatted or unformatted data is available. The formatted data is composed of characters, some of which constitute symbolic data, and some form AIML elements. The AIML element encapsulates the answer data in the document. The character data containing these elements may be formatted by the AIML interpreter, or it may be processed in subsequent responses.

elements in AIML are case insensitive 2, detailed description

1. The element of the

Type such as: <think><set name= "topic" >Me</set></think>

Placed in the template element, indicating that once the user's input to match the category, and then reply to the response, and assign a variable value, here is the me in mind, then you can use the <get name= "topic"/> to take out the previously remembered content.

2, <star/> said *
For example, there is a matching pattern is <pattern>* Hello *<pattern>; here pattern elements in the matching mode is to use the * number to indicate any match, but in other elements can not use the *, but the element of <star/> to express.

3, <srai> elements
Indicates that the words in <srai> will be treated as user input, find the matching pattern again until you find a reply that is not <srai> defined. For example:
<srai> I am <star/></srai>, then the robot will take "I am *" as a user input to find a new matching pattern. (Ps:srai not very good match Chinese)

4, <condition> Element (the condition element is the element that is used for the selection operation, similar to the If-else statement.) )
In the template element, there can be multiple condition elements, but not nested (not currently supported), in 3 different ways:

<condition name= "name" value= "value" > Hello </condition>
<condition name= "name" contains= "Value" > Hello </condition>
<condition name= "name" exists= "value" > Hello </condition>

Name is a predefined variable, the first of which indicates that the value of the name variable is equal to value, and the reply includes "Hello"; the second represents the value of the name variable if the string contains value, the reply includes "Hello" The third represents the value of the name variable if there is value, the reply includes "Hello" (what does that mean?)
For example, use a sample:

<category> 
<pattern> Hello </pattern> 
<template> 
hello.
<condition name= "user name" value= "John" > 
you're here again.: 
</condition> 
</template>
</ Category>

A. Situation one: If you have set the variable "user name" in advance, and is equal to "John", then the user receives the reply content is: Hello AH. You're here again.
B. Situation two: If there is no definition or variable "user name" value is not equal to "John", then the user received the reply content is: Hello AH.
There are several ways to do this:

<category> <pattern> My hair color is blue *</pattern> <template> Wow, you're <condition name= "user Sex" Valu E= "Girl" > Beautiful. </condition> <condition name= "user sex" value= "male" > Handsome. </condition> </template> </category> <category> <pattern> The color of my hair is blue *</pattern > <template> Wow, you're very <condition> <li name= "user sex" value= "girl" > Beautiful. </li> <li name= "user sex" value= "male" > Handsome. </li> </condition> </template> </category> <category> <pattern> The color of my hair is blue *</pattern> <template> Wow, you are <condition name= "user Sex" > <li value= "Girl" > Beautiful. </li> <li value= "man" > Handsome. </li> </condition> </template> </category> <category> <pattern> The color of my hair is blue *</pattern> <template> Wow, you're very <condition> <li name= "user sex" value= "Girl" > Pretty. </li> <li> good-looking. </li> </condition> </templatE> </category> 

The last Li element here represents the default condition, that is, when the condition match is not found, the default is used.

6, <gender> elements
Replace gender and pronoun, for example:

<gender>she told him to take a hike.</gender>

will be replaced by: he told her to take a hike, the gender-related words will be replaced, Chinese how to deal with is not very clear.

7, <get name= "" Name/>
That gets the value of name.

8, <gossip> elements
Used to save the contents of the modified elements into the Gossip.log file.

9, <if> elements
The element of judgment has the following form:

<if name= "topic" value= "Cars" ></if> 
<if name= "topic" contains= "Cars" ></if> 
<if Name= "topic" exists= "true" ></if>
example:
<template> 
<if name= "user name" exists= "true" > 
your name is <get name= "user name"/>. 
<else/> 
What's your name. 
</if> 
</template>

10. <input> indicates user input

For example:
<input index= "2"/> will output the 2nd user's penultimate input, look at the following dialog:
User: Good
robot: You are better, what is your name.
User: My name is Black Mountain
robot: hehe, hello Montenegro.
If there are fragments in the Aiml file:
<category>
<pattern> hehe </pattern>
<template>
< Gossip> you just said: "<input index=" 2 "/>". </gossip>
</template>
</category>
If the user input "Hey Hei" this time, then the robot will reply: You just said: "My name is Montenegro".
the number of the index attribute represents the penultimate sentence, 1: The penultimate sentence, 2: The penultimate sentence, and so on.

11, <learn filename= "XXX.AIML" > elements
That allows a robot to learn a AIML file.

12, <li></li> elements
It can be used in elements such as random elements or condition to represent a list;
13, <pattern> Show matching mode
The contents must be capitalized, you can have an asterisk * or an underscore _, an asterisk to match all, any situation; the underline is the same as an asterisk, except that it does not match the letters behind Z in the dictionary.

14, <person> and <person2>
The first person is converted to the 3rd person, and the 2nd is to turn the first person into the 2nd person. <person/> equals <person><star/></person>

15, <random> random elements
Commonly used in conjunction with <li>, indicating a random pick from the list.

16, <sentence> elements used to format sentences

For example:
<sentence>this is some kind of sentence test.</sentence>
can be formatted as: This is some kind of sentence of That is to capitalize the first letter of the sentence, but also to add punctuation. such as:
<category>
    <pattern> who are you </pattern>
    <template><sentence> Hello, I'm a chat robot, June. </sentence></template>
</category>

17, <star/> to indicate an asterisk
Deprecated, only for 0. 9 version, now generally to add the Index property to use,

For example: <star index= "1"/>, look at the following dialogue:
User: My name is Montenegro.
<pattern>* name is called *</pattern> 
<template> Oh, I know, your name is <star index= "2"/>.
</template>

18, <system><system> elements
Represents the call to a system function.

For example:
<system>date</system> means to take the system's current date
warning: Be careful with this element, because it is possible for the user to run your system commands.
19, <template> define the template for the reply.

20, <that> elements

Said the previous robot said, for example:
<category> 
<pattern> good </pattern> <that> together to talk about the 
movie, okay *</that > 
<template> What movie do you like that. </template> 
</category>
that is: if the robot previously asked the user to "talk about the movie together," and now the user answered "good", then the correct match, the reply content is: "Then you like what movie that." "
if you want to take the front robot, you can use: <that index=" Nx,ny ", for example: <that index=" 2,<?xml:namespace prefix = st1 ns = "urn: Schemas-microsoft-com:office:smarttags "/>1" >
 means to take the 2nd sentence of the robot, <that index= "2,1" > also equals < Justbeforethat/>

21, <thatstar index= "n" > elements
The previous nth robot said the asterisk part,

<thatstar/> equals <thatstar index= "1"/> see example:
<category> 
<pattern> Hello </pattern> 
<template>
What is the model of the computer
</template> 
</category> 

<category>
<  What is the model of pattern>*</pattern> <that>* </that>
<template><star/>
This model is <thatstar/> inside
<random>
<li> very good product </li> 
<li> very popular commodity </ Li> 
<li> very gorgeous products </li>
<random>. 
</template> 
</category>
dialog scene:
User: Hello
robot: What is the computer model
User: P4
Robot: P4 This model is a good product in the computer

22, <think>
Record user input and the contents are not returned to the user.

For example:
<category> 
<pattern>i AM female</pattern> 
<template>thanks for telling Me your gender. 
<think>
<set name=gender>female</set>
</think> 
</template> 
</category>
Here The value of female is saved to the gender variable, and the reply does not include female.

23, <topic name= "film" > Elements

Used to set themes, such as:
<aiml> 
<topic name= "Kung Fu" >
    <category> 
    <pattern> phrase </ pattern> 
    <that> phrase </that> 
    <template> phrase </template> 
    </category > 
</topic> 
</aiml>
only the current topic system variable is "Kung Fu" when it will match here.

24. The <topicstar index= "n" > elements are used to get the subject of the previous penultimate nth talk. Summary:

Personal feeling in the business consulting module, included in the entire Intelligent Customer Service project, this AIML knowledge base is the most important and time-consuming work of the knowledge base with these syntaxes, because if you design this knowledge base, you can save a lot of things later, but how to design this knowledge base well. This is a matter of experience, you need to have as much data as possible, but also to understand the consulting business of those issues are common, for some common problems you need to design the knowledge base to match and so on, Eventually you will also need to familiarize yourself with the entire AIML label and how to use these tags to optimize your business issues (after all, the real business consulting scenario will be a variety of issues, once the data volume is large, it is very likely that the entire knowledge base will conflict, such as entering a question, there are two matching answers, Then the system will collapse ... There will be a lot of questions coming up later. So it feels like this is not particularly relevant to technology, but more to do with business.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.