Skip to content
Ben James edited this page Jan 9, 2017 · 10 revisions

IntroductionTriggersRepliesConversationsTopicsPlugins and FunctionsKnowledgeUnder the Hood


Triggers

Triggers form the basis of all chat conversation. When a user sends a message to our bot, we try matching it against several triggers until we find one that matches. In SuperScript, triggers are identified by + in front of them, and replies by - . The example below is a simple gambit and includes a trigger and a reply:

+ hello bot
- Hello, human!

If the user input is hello bot, the system will reply with Hello, human!.

Basic rules

Triggers are cleaned and normalized prior to being exposed to the engine. Extra whitespaces are removed, and the trigger is made case-insensitive.

For example, the following rules are all identical:

+ hello bot
+ Hello     bot
+ HELLO BOT

Note: We strip punctuation out of any user messages at runtime, so it's clearer if you write triggers without punctuation.

Inputs are processed by bot-lang to make them easy to understand for a bot. This performs tasks such as:

  • cleaning and normalization
  • spelling corrections for common spelling errors (or British spelling)
  • idiom conversion
  • junk word removal
  • abbreviation expansion and more

For example:

  • It’s a nice day becomes it is a nice day.
  • teh supermarket is colourful becomes the supermarket is colorful

Warning: normalization might remove some words from the input (like “really?” or “quite”), which might make rule triggering awkward sometimes.

Note: as of v1.0.0, phrases like hello are no longer expanded to tags like ~emohello. Instead, they are added to a tags property on the message object and accessed via plugins. For more information, visit Upgrading to v1.

Note: as of v1.0.0, message bursting no longer occurs. You'll want to instead use the {continue} reply tag to keep matching after a single match.

Wildcards

We use wildcards to allow for more natural and expressive rules. A wildcard will match one or more characters, words or tokens. Depending on the type of wildcard, the input may or may NOT be captured or saved by the system.

Generic wildcards

Will match zero to unlimited characters, words or tokens. The input is NOT captured or saved by the system.

+ * hello *
- That is crazy.
  • Matches The dog said hello to the cat.
  • Matches Hello world.
  • Matches While hello.

Exact length wildcards

If you know exactly how many words you want to accept, but don't want to list what the words are, then an exact length wildcard might be what you're after.

The syntax is *n, where n is the exact number of words you want to let through.

+ hello *2
  • Matches Hello John Doe
  • Does not match Hello John

The wildcards will be captured by the system and can later be used in replies.

Variable length wildcards

If you want to only allow a few words though, you might consider using a variable length wildcard. The syntax for variable length wildcards is *~n, where n is the maximum number of words you want to let through.

+ hello *~2
- That is crazy!
  • Matches Hello!
  • Matches Hello John!
  • Matches Hello John Doe
  • Does not match Hello John George Doe

Variable length wildcards are great for capturing input where an adjective might be slipped in before a noun.

Min-max wildcards

These are useful if you want to capture, let’s say, at least 2 words but no more than 4 words (the example below). Using *(n) is the equivalent of *n(exact length wildcard). The wildcards are captured by the system and can be used in replies.

+ hello *(2-4)
  • Matches Hello John Doe and Hello John Dorian Doe
  • Does not match Hello John

Alternates

Alternates are used when you have a range of words that could fit into the rule, but one is required. The alternate in the input is captured by the system and can be used in replies.

+ i go by (bus|train|car)
  • Matches I go by bus
  • Matches I go by train
  • Matches I go by car
  • Does not match I go by

Optionals

Optionals can be used to check for extra/optional words. Optionals are not captured by the system.

+ my [big] red balloon [is awesome]
  • Matches my red balloon
  • Matches my big red balloon
  • Matches my red balloon is awesome
  • Matches my big red balloon is awesome
  • Does not match my big red balloon awesome

WordNet expansion

WordNet is a database of words and ontology including hypernym, synonyms and lots of other neat relationships between words. SuperScript is using the raw WordNet library, as well it has expanded it to include fact triples and provide even more relationships, through its scripted fact graph database. These terms are expanded by using a tilde ~ before the word you want to expand.

+ I ~like ~sport
  • Matches I like hockey
  • Matches I love baseball
  • Matches I care for soccer
  • Matches I prefer lacrosse

Parts of speech

When input comes into the system, we tag it and analyze it to help make sense of what is being said. SuperScript has a few tagged keywords you can use in triggers. These tags can also have a numeric value attached to them to get even more specific.

  • <noun>, <nounN>, <nouns>
  • <adjective>, <adjectiveN>, <adjectives>
  • <verb>, <verbN>, <verbs>
  • <adverb>, <adverbN>, <adverbs>
  • <pronoun>, <pronounN>, <pronouns>
  • <name>, <nameN>, <names>
+ <name1> is [more|less] <adjectives> than <name2>
  • Matches Tom is taller than Mary
  • Matches John is less disciplined than Jack.

Note that pronouns are a subclass of nouns, so I, you, her will match both <noun> and <pronoun>. For an input like I’m an engineer, the system will normalize it to I am an engineer then tag it:

taggedWords:
  [ [ 'I', 'NN' ],
    [ 'am', 'VBP' ],
    [ 'an', 'DT' ],
    [ 'engineer', 'NN' ],

The <noun> only matches the first noun in the lookup, where <nouns> matches all nouns, therefore

  • I am a <noun> will match I am a I
  • I am a <nouns> Will match I am a I or I am an engineer
  • I am a <noun2> Will match I am a cow or I am an engineer

Question types

We can identify questions (with or without the ending question mark) in the input, so you can create specific rules (by using ? to begin your trigger pattern).

?:Will you do *
- Hmmm, let me get back to you on that.

Note: as of v1.0.0, question types such as ?:CH or ?:ABBR:exp are no longer used. We simply identify whether the trigger is a question or not. We may return to look at this again with a learned ML model. In the future, we may also look at other types of classification that follow more linguistic types like speech acts and adjacency pairs.


Continue to Replies