Definition

A pattern defines what user input is expected to trigger a scenario or sub scenario.

Two kind of these patterns exist, the difference relies on their election system :

  1. Keyword
  2. Classifier

Special patterns also exist and will be explained later :

  1. pattern condition
  2. pattern parameter
  3. pattern default
  4. pattern default forced

Keyword Matching

This pattern has the following syntax :

? HELLO

It always starts with a simple question mark and followed by a space.

The matching system is quite simple but you need to read the rules to understand it.

Keyword rules

  1. A keyword is composed of letters
  2. No special chars allowed
  3. No numbers allowed
  4. A keyword must be at least two characters long.

Preprocessing

The matching system before comparing user input and keywords preprocesses the words:

  1. All numbers and special chars are removed
  2. All accentuated letters are rewritten with non accentuated characters
  3. One letter word are removed.
  4. Input is upper cased

Keyword matching

The matching system compares keywords with their string equality, phonex equality and metaphone equality. This can correct some typos in user messages, or match two different words but close enough by their pronunciation.

Keyword order

Order is primordial in patterns : ? HELLO JOHN cannot match with ‘john hello’

Election system

Given those scenarios :

? HELLO
    - Hello you

? HELLO JOHN
    - Hello, my name is John

? BYE
    - goodbye

Here are some examples of rules applied :

  1. ‘hello’ -> first scenario
  2. ‘hello john’ -> second scenario
  3. ‘hello mark’ -> first scenario
  4. ‘bye’ -> goodbye
  5. ‘hello bye’ -> default (this is pattern conflict)

Pattern expansion

Because it can be a consuming task to define all possible patterns for a scenario, Athena includes pattern expansion.

This works only for keywords system.

Inline expansion

? (HELLO|HI) JOHN
    - Hello

Equivalent :

? HELLO JOHN
? HI JOHN
    - Hello

Optional expansion

If no word is defined after the last pipe, pattern without the expansion will be generated. As well for unique word in parenthesis.

? (HELLO|HI) (JOHN)
    - Hello

? (GOODBYE|BYE|) JOHN
    - Hello

Equivalent :

? HELLO JOHN
? HI JOHN
? HELLO
? HI
    - Hello

? GOODBYE JOHN
? BYE JOHN
? JOHN
    - Hello

Expansion factor

+ HELLO(HELLO|HI)

? __HELLO JOHN
    - Hi, i'm john

? __HELLO MARY
    - HI, i'm mary

Equivalent :

? HELLO JOHN
? HI JOHN
    - Hi, i'm john

? HELLO MARY
? HI MARY
    - Hi, i'm mary

An expansion factor is defined by a plus symbol followed by a space and an identifier, and an inline expansion.

To call the expansion factor, precede the identifier by two underscores.

Classifier

This pattern has the following syntax :

?! hello

It always starts with a simple question mark, followed by an exclamation point and a space.

The matching system is based on a classification system which is not part of Athena.

Election system

The classification system processes a sentence and returns to athena the list of intent score pair (for each intent defined in the application, a score is attributed to it)

Given those scenarios :

?! hello
    - Hello you

?! bye
    - goodbye

Athena will elect the scenario with the highest score. The minimum threshold of an elected score is 0.5 (the system is 50% sure that it is this intent)

Notes : you can override the minimum threshold, refer to the classification configuration.

Combined

You can use both Keywords Matching and Classification system in the same script and scenario :

?! hello
? HELLO
    - Hello you

? HELLO JOHN
    - Hello, my name is John

?! bye
? BYE
    - goodbye

If 100% words of user input match a keyword matching pattern, the classification system is not solicited since it’s a perfect match. What’s not a perfect match regarding the scenario :

  1. hello mark (mark is an extra word)
  2. Hello mister john (mister is an extra word)

If not 100% percent, the classification system takes the lead :

  1. Process the sentence to get scores over minimum threshold
  2. If valid scores (over minimum threshold), find a scenario with the intent name

If no valid scores, or no scenario with intent name, the keyword matching system takes the lead.

Special Patterns

Pattern condition

A scenario or sub scenario can be conditionally activated.

The syntax is :

?: @Time.BeforeNoon()
? HELLO
    - Good morning

?: @Time.AfterNoon()
? HELLO
    - Good afternoon 

It always starts with a simple question mark, followed by colon and a space.

The condition is expressed using an addin, or with code style syntax.

This allows in this example to elect a different scenario based on time of day.

Patterns fallbacks

Default

A sub scenario can define a default behavior if there is no match between user input and sub scenarios and root scenarios

? HELLO
    - How are you ?
        ? FINE
            - I'm glad
        ? BAD
            - Do you want a hug ?
        ??
            - I hope you're fine

? BYE
    - goodbye

Syntax is two interrogation mark

In this case, here is the behavior expected :

  1. hello -> How are you ? -> Fine -> I’m glad
  2. hello -> How are you ? -> Morose -> I hope you’re fine
  3. hello -> How are you ? -> Sorry i need to go, bye -> goodbye

Default forced

A sub scenario can define a default forced behavior if there is no match between user input and sub scenarios.

? HELLO
    - How are you ?
        ? FINE
            - I'm glad
        ? BAD
            - Do you want a hug ?
        ???
            - I hope you're fine

? BYE
    - goodbye

Syntax is three interrogation mark

In this case, here is the behavior expected :

  1. hello -> How are you ? -> Fine -> I’m glad
  2. hello -> How are you ? -> Morose -> I hope you’re fine
  3. hello -> How are you ? -> Sorry i need to go, bye -> I hope you’re fine

Notes on defaults

You can’t combine both default and default forced patterns.

Pattern parameter

A scenario can have pattern parameters, which will be extracted by extraction systems.

? HELLO
    - Hello

? HELLO
?% firstname
    - Hello %firstname

The syntax is a question mark followed by a percent and a space. The last particle is the identifier of entity that needs to be extracted.

In this case, we assume that the firstname extractor extract common first names. Here is the behavior expected :

  1. Hello -> Hello
  2. Hello John -> Hello John
  3. Hello there -> Hello

The syntax also keeps in memory the extracted values during whole scenario. Wich means that it will only be cleared when user reaches a root scenario :

? HELLO
    - Hello

? HELLO
?% firstname
    - Hello %firstname, how are you ?
        ? (FINE|GOOD)
            - Glad to hear that %firstname
        ? BAD
            - What's wrong %firstname

In that exemple we can use %firstname in the sub scenario, we can do it with calllabel as well :

? HELLO
    - Hello

? HELLO
?% firstname
    - Hello %firstname, how are you ?
        ? (FINE|GOOD)
            - {GOOD}
        ? BAD
            - {BAD}

[GOOD]
    - Glad to hear that %firstname

[BAD]
    - What's wrong %firstname

This notation allows you to omit calllabel parameters, but you must take care about callers ! The question you should ask yourself is : “Have they already extracted %firstname ?”

Technical Information

Extracted parameters use AthenaContext data as storage. Which means you can add extracted parameters using an addin.

Given the following addin :

[AthenaAddin(Name = "extract")]
public class ExtractAddin : AthenaAddin
{
    public string extract(string parameterName)
    {
        AthenaContext.Current.AddData(parameterName, "mathias");
        return NOTHING;
    }
}    

You can use it like this in Athena :

? HELLO
    -: @extract.extract("firstname")
    - Hello %firstname, how are you ?

Existing parameter extractors

Currently you must request xBrain to implement a new one.

How to create your own parameter extractor

Currently you must request xBrain to implement a new one.

Pattern triggers

Those patterns are used to trigger a specific sub scenario using a specific command:

? BUTTON CHOICE
    - Choose one option :[list][*] [button title="yes"]yes[/button][*] [button title="no"]no[/button][/list]
        ?! yes
        ?# yes
            - You choose yes
        ?! no
        ?# no
            - You choose no

In this case, the sub scenario accepts text responses, and click on yes/no buttons.

Click on button send a custom message, that triggers the specific pattern.