Classes

Ai
WingbotModel
CachedModel
AiMatching

{AiMatching}

Class responsible for NLP Routing by score

Typedefs

EntityExpression : Object
textFilterstring

Text filter function

IntentRule : string | EntityExpression
Entity : Object
Intent : Object
Result : Object
Entity : Object
Intent : Object
Result : Object
Compare : string
Entity : Object
Intent : Object
EntityExpression : Object
IntentRule : string | EntityExpression
RegexpComparator : Object
PreprocessorOutput : Object
AIRequest : Object
 

Ai

Kind: global class

 

ai.confidence : number

Upper threshold - for match method and for navigate method

Kind: instance property of Ai

 

ai.logger : Object

The logger (console by default)

Kind: instance property of Ai

 

ai.disableBookmarking : boolean

Backward compatibility - to be able to use older "callback" middleware

Kind: instance property of Ai

 

ai.matcher : AiMatching

AI Score provider

Kind: instance property of Ai

 

ai.getPrefix(prefix, req)

The prefix translator - for request-specific prefixes

Kind: instance method of Ai
Params

  • prefix string
  • req Request
 

ai.textFilter(text) : textFilter

Preprocess text for NLP For example to remove any confidential data

Kind: instance method of Ai
Params

  • text string
 

ai.mockIntent([intent], [score]) ⇒ this

Usefull method for testing AI routes

Kind: instance method of Ai
Params

  • [intent] string = null - intent name
  • [score] number = - the score of the top intent

Example

const { Tester, ai, Route } = require('bontaut');

const bot = new Route();

bot.use(['intentAction', ai.localMatch('intentName')], (req, res) => {
    res.text('PASSED');
});

describe('bot', function () {
    it('should work', function () {
        ai.mockIntent('intentName');

        const t = new Tester(bot);

        return t.text('Any text')
            .then(() => {
                t.actionPassed('intentAction');

            t.any()
                .contains('PASSED');
        })
    });
});
 

ai.register(model, prefix) ⇒ WingbotModel | T

Registers Wingbot AI model

Kind: instance method of Ai
Params

  • model string | WingbotModel | T - wingbot model name or AI plugin
  • prefix string = "default" - model prefix
 

ai.load()

Middleware, which ensures, that AI data are properly loaded in Request

Kind: instance method of Ai
Example

const { ai, Router } = require('wingbot');

const bot = new Router();

bot.use(ai.load());
 

ai.match(intent, [confidence]) ⇒ function

Returns matching middleware

supports:

  • intents ('intentName')
  • entities ('@entity')
  • entities with conditions ('@entity=PRG,NYC')
  • entities with conditions ('@entity>=100')
  • complex entities ({ entity:'entity', op:'range', compare:[null,1000] })
  • optional entities ({ entity:'entity', optional: true })
  • wildcard keywords ('#keyword#')
  • phrases ('#first-phrase|second-phrase')
  • emojis ('#😄🙃😛')

Kind: instance method of Ai
Returns: function - - the middleware
Params

Example

const { Router, ai } = require('wingbot');

ai.register('app-model');

bot.use(ai.match('intent1'), (req, res) => {
    console.log(req.intent(true)); // { intent: 'intent1', score: 0.9604 }

    res.text('Oh, intent 1 :)');
});
 

ai.localMatch(intent, [confidence]) ⇒ function

Returns matching middleware, that will export the intent to the root router so the intent will be matched in a local context (nested Router)

Kind: instance method of Ai
Returns: function - - the middleware
Params

Example

const { Router, ai } = require('wingbot');

ai.register('app-model');

bot.use(ai.localMatch('intent1'), (req, res) => {
    console.log(req.intent(true)); // { intent: 'intent1', score: 0.9604 }

    res.text('Oh, intent 1 :)');
});
 

ai.globalMatch(intent, [confidence]) ⇒ function

Returns matching middleware, that will export the intent to the root router so the intent will be matched in a global context

Kind: instance method of Ai
Returns: function - - the middleware
Params

Example

const { Router, ai } = require('wingbot');

ai.register('app-model');

bot.use(ai.globalMatch('intent1'), (req, res) => {
    console.log(req.intent(true)); // { intent: 'intent1', score: 0.9604 }

    res.text('Oh, intent 1 :)');
});
 

WingbotModel

Kind: global class

 

new WingbotModel(options, [log])

Params

  • options Object
    • [.serviceUrl] string
    • .model string
    • [.cacheSize] number
    • [.matches] number
  • [log] Object
 

wingbotModel._queryModel(text) ⇒ Promise.<Result>

Kind: instance method of WingbotModel
Params

  • text string
 

CachedModel

Kind: global class

 

new CachedModel(options, [log])

Params

  • options Object
    • [.cacheSize] number
  • [log] Object
 

cachedModel.resolve(text) ⇒ Promise.<Result>

Kind: instance method of CachedModel
Params

  • text string - the user input
 

cachedModel._queryModel(text) ⇒ Promise.<(Array.<Intent>|Result)>

Kind: instance method of CachedModel
Params

  • text string
 

AiMatching

{AiMatching}

Class responsible for NLP Routing by score

Kind: global class

 

aiMatching.optionalHandicap : number

When the entity is optional, the final score should be little bit lower (0.001 by default)

Kind: instance property of AiMatching

 

aiMatching.redundantEntityHandicap : number

When there are additional entities then required add a handicap for each unmatched entity Also works, when an optional entity was not matched (0.05 by default)

Kind: instance property of AiMatching

 

aiMatching.redundantIntentHandicap : number

When there is additional intent, the final score will be lowered by this value (0.15 by default)

Kind: instance property of AiMatching

 

aiMatching.multiMatchGain : number

When more than one AI features (Intent, Entity, Regex) are matching, enrich the score using the {multiMatchGain} ^ {additionalFeaturesCount} (1.2 by default)

Kind: instance property of AiMatching

 

aiMatching.preprocessRule(intent) ⇒ PreprocessorOutput

Create a rule to be cached inside a routing structure

Kind: instance method of AiMatching
Params

 

aiMatching.match(req, rule) ⇒ Intent | null

Calculate a matching score of preprocessed rule against the request

Kind: instance method of AiMatching
Params

 

aiMatching._matchRegexp(req, regexps) ⇒ boolean

Kind: instance method of AiMatching
Params

 

COMPARE : enum

Kind: global enum
Properties

Name Type Default
EQUAL Compare eq
NOT_EQUAL Compare ne
RANGE Compare range
GT Compare gt
GTE Compare gte
LT Compare lt
LTE Compare lte
 

EntityExpression : Object

Kind: global typedef
Properties

Name Type Description
entity string the requested entity
[optional] boolean entity is optional, can be missing in request
[op] Compare comparison operation (eq ne range)
[compare] Array.<string> \ Array.<number> value to compare with
 

textFilter ⇒ string

Text filter function

Kind: global typedef
Returns: string - - filtered text
Params

  • text string - input text
 

IntentRule : string | EntityExpression

Kind: global typedef

 

Entity : Object

Kind: global typedef
Params

  • entity string
  • value string
  • score number
 

Intent : Object

Kind: global typedef
Params

 

Result : Object

Kind: global typedef
Params

 

Entity : Object

Kind: global typedef
Params

  • entity string
  • value string
  • score number
 

Intent : Object

Kind: global typedef
Params

 

Result : Object

Kind: global typedef
Params

 

Compare : string

Kind: global typedef

 

Entity : Object

Kind: global typedef
Params

  • entity string
  • value string
  • score number
 

Intent : Object

Kind: global typedef
Params

 

EntityExpression : Object

Kind: global typedef
Properties

Name Type Description
entity string the requested entity
[optional] boolean the match is optional
[op] Compare comparison operation
[compare] Array.<string> \ Array.<number> value to compare with
 

IntentRule : string | EntityExpression

Kind: global typedef

 

RegexpComparator : Object

Kind: global typedef
Properties

Name Type Description
r RegExp regular expression
t boolean use normalized text
 

PreprocessorOutput : Object

Kind: global typedef
Properties

Name Type
regexps Array.<RegexpComparator>
intents Array.<string>
entities Array.<EntityExpression>
 

AIRequest : Object

Kind: global typedef
Properties

Name Type
text function
intents Array.<Intent> \ null
entities Array.<Entity>

results matching ""

    No results matching ""