-
Notifications
You must be signed in to change notification settings - Fork 135
Tutorial Maps
A map is a way to map the value of something to a different value. It provides the ability to carry out a number of lookups or conversions
- Convert the tense of a word, e.g be -> been
- Generalise the gender of a word, e.g man -> male, bot -> male, girl -> female
- Lookup the capital city, e.g Afghanistan -> Kabul, UK -> London
- Convert number to and from numeric and number, e.g 1 -> one, three -> 3
Program-Y supports 3 different types of maps
- File-based. Each mapping is stored in a single file in the maps folder
- Inbuilt. The system ships with a number of inbuilt mappings, e.g. Singular, Plural, Successor, Predecessor
- Dynamic. User-defined maps that programmatically map the value given to a new value
The location of each map file is configured using the maps section of the file seciton of the brain configuration in your configuration file
brain:
files:
maps:
files: $BOT_ROOT/maps
extension: .txt
directories: false
Each map value consists of a number of name and value pairs seperated by a ':'. As an example, the follows shows a snippet from the nation2capitol.txt mapping value which takes the name of a country and returns its capital city
Uganda:Kampala
Ukraine:Kiev
United Arab Emirates:Abu Dhabi
United Kingdom:London
United States:Washington, D.C.
To use this in a grammar we use the <map>
tag
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="2.0">
<category>
<pattern>I AM FROM THE *</pattern>
<template>
Cool, have you been to the capital city <map name="nation2capitol" />?
</template>
<category>
</aiml>
Running the bot with this grammar, allows us to answer the question about living in any country has an entry in the file
Loading, please wait...
No bot root argument set, defaulting to [.]
Y-Bot version 0.0.1, initiated March 14, 2017
Hi, how can I help you today?
>>> I live in the United Kingdom
Cool, have you been to the capital city London?
>>>
AIML 2.0 defines a number of inbuilt maps which use code to map the value from one value to the next. Currently, AIML defines 4 such in-built maps
- Singular. Given a word attempts to create the singular version of the word by removing 's', 'es', or 'ies' from the word.Can also deal with words such as sheep -> sheep, and foot -> feet.
- Plural. Given a word attempts to create the plural by appending 's', 'es', or 'ies' to the word. Can also deal with words such as sheep -> sheep, and foot -> feet.
- Successor. Given a numeric value adds one to the value. E.g 99 -> 100
- Predecessor. Given a numeric value subtracts one from the value E.g 100 -> 99
Lets use an interested in animals to show how these grammars can be used
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="2.0">
<category>
<pattern>I WOULD LIKE A * AS A PET</pattern>
<template>
OK, how many <map name="plural"><star/></map> would you like?
</template>
<category>
<category>
<pattern>I HAVE * * AS PETS</pattern>
<template>
OK, whats the best thing about a <map name="singular"><star/></map>?
</template>
<category>
</aiml>
Loading, please wait...
No bot root argument set, defaulting to [.]
Y-Bot version 0.0.1, initiated March 14, 2017
Hi, how can I help you today?
>>>
Some very basic maths to demonstrate the us eof successor and predecessor
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="2.0">
<category>
<pattern>WHAT IS ONE MORE THAN *</pattern>
<template>
That would be <map name="successor"><star/></map>
</template>
<category>
<category>
<pattern>WHAT IS ONE LESS THAN *</pattern>
<template>
That would be <map name="predecessor"><star/></map>
</template>
<category>
</aiml>
Loading, please wait...
No bot root argument set, defaulting to [.]
Y-Bot version 0.0.1, initiated March 14, 2017
Hi, how can I help you today?
>>>
A more generalised version of the inbuilt maps are dynamic maps.
Infact all inbuilt maps are built using dynamic values, but they are loaded automatically and no not need to be specified in the dynamics section
For more information on maps see the wiki page Maps
Back to Tutorial | Back - Random Selection | Next - Properties
Email: [email protected] | Twitter: @keiffster | Facebook: keith.sterling | LinkedIn: keithsterling | My Blog
- Home
- Background
- Guiding Principles
- Reporting an Issue
- Installation
- You And Your Bot
- Bots
- Clients
- Configuration
- AIML
- Sentence Splitting
- Natural Langauge Processing
- Normalization
- Spelling
- Sentiment Analysis
- Translation
- Security
- Hot Reload
- Logging
- Out of Band
- Multi Language
- RDF Support
- Rich Media
- Asynchronous Events
- Triggers
- External Services
- Dynamic Sets, Maps & Vars
- Extensions
- Pre & Post Processors
- Custom Nodes
- The Brain Tree
- Utilities
- Building It Yourself
- Creating Your Own Bot
- Contributing
- Performance Testing
- FAQ
- History
- Website