Classes

Ai
CustomEntityDetectionModel
WingbotModel
CachedModel
AiMatching

{AiMatching}

Class responsible for NLP Routing by score

Typedefs

EntityExpression : object
textFilterstring

Text filter function

IntentRule : string | EntityExpression
BotPath : object
IntentAction : object
DetectedEntity : object
EntityDetectorArray.<DetectedEntity> | DetectedEntity | Promise.<DetectedEntity> | Promise.<Array.<DetectedEntity>>
ValueExtractor*
Entity : object
Intent : object
Result : object
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.threshold : number

Lower threshold - for disambiguation

Kind: instance property of Ai

 

ai.logger : object

The logger (console by default)

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

Param Type
prefix string
req Request
 

ai.textFilter(text) : textFilter

Preprocess text for NLP For example to remove any confidential data

Kind: instance method of Ai

Param Type
text string
 

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

Usefull method for testing AI routes

Kind: instance method of Ai

Param Type Default Description
[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

Param Type Default Description
model string \ WingbotModel \ T wingbot model name or AI plugin
prefix string "default" model prefix
 

ai.getModel(prefix) ⇒ WingbotModel

Returns registered AI model

Kind: instance method of Ai

Param Type Default Description
prefix string "default" model prefix
 

ai.global(path, intents, [title], [meta]) ⇒ object

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: object - - the middleware

Param Type Default Description
path string
intents IntentRule \ Array.<IntentRule>
[title] string null disambiguation title
[meta] object metadata for multibot environments
[meta.targetAppId] object target application id
[meta.targetAction] object target action

Example

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

ai.register('app-model');

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

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

ai.local(path, intents, [title]) ⇒ object

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

Kind: instance method of Ai
Returns: object - - the middleware

Param Type Default Description
path string
intents IntentRule \ Array.<IntentRule>
[title] string null disambiguation title

Example

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

ai.register('app-model');

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

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

ai.match(intent) ⇒ 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

Param Type
intent IntentRule \ Array.<IntentRule>

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.shouldDisambiguate(aiActions) ⇒ boolean

Kind: instance method of Ai

Param Type
aiActions Array.<IntentAction>
 

CustomEntityDetectionModel

Kind: global class

 

new CustomEntityDetectionModel(options, [log])

Param Type
options object
[log] Object
 

customEntityDetectionModel._normalizeResult(entities, entity, text, offset, originalText)

Kind: instance method of CustomEntityDetectionModel

Param Type
entities Array.<DetectedEntity>
entity string
text string
offset number
originalText string
 

customEntityDetectionModel._detectEntities(entity, text, entities) ⇒ Promise.<Array.<DetectedEntity>>

Kind: instance method of CustomEntityDetectionModel

Param Type
entity string
text string
entities Array.<DetectedEntity>
 

customEntityDetectionModel._nonOverlapping(entities)

Kind: instance method of CustomEntityDetectionModel

Param Type
entities Array.<DetectedEntity>
 

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

Kind: instance method of CustomEntityDetectionModel

Param Type
text string
 

customEntityDetectionModel._extractRegExpDependencies(regexp)

Kind: instance method of CustomEntityDetectionModel

Param Type
regexp RegExp
 

customEntityDetectionModel._entityByDependency(entities, dependency) ⇒ DetectedEntity | null

Kind: instance method of CustomEntityDetectionModel

Param Type
entities Array.<DetectedEntity>
dependency string
 

customEntityDetectionModel._regexpToDetector(regexp, dependencies, extractValue)

Kind: instance method of CustomEntityDetectionModel

Param Type Default
regexp RegExp
dependencies Array.<string>
extractValue string \ function null
 

customEntityDetectionModel.setEntityDetector(name, detector, [options]) ⇒ this

Kind: instance method of CustomEntityDetectionModel

Param Type Description
name string
detector EntityDetector \ RegExp
[options] object
[options.anonymize] boolean if true, value will not be sent to NLP
[options.extractValue] function \ string entity extractor
[options.dependencies] Array.<string> array of dependent entities
 

WingbotModel

Kind: global class

 

new WingbotModel(options, [log])

Param Type
options object
[options.serviceUrl] string
options.model string
[options.cacheSize] number
[options.matches] number
[options.fetch] function
[log] Object
 

wingbotModel._fetch : fetch

Kind: instance property of WingbotModel

 

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

Kind: instance method of WingbotModel

Param Type
text string
 

CachedModel

Kind: global class

 

new CachedModel(options, [log])

Param Type
options object
[options.cacheSize] number
[log] Object
 

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

Kind: instance method of CachedModel

Param Type Description
text string the user input
 

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

Kind: instance method of CachedModel

Param Type
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.03 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.06 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.getSetStateForEntityRules(rule) ⇒ object

Kind: instance method of AiMatching

Param Type
rule PreprocessorOutput
 

aiMatching.preprocessRule(intent) ⇒ PreprocessorOutput

Create a rule to be cached inside a routing structure

Kind: instance method of AiMatching

Param Type
intent IntentRule \ Array.<IntentRule>
 

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

Calculate a matching score of preprocessed rule against the request

Kind: instance method of AiMatching

Param Type Default
req AIRequest
rule PreprocessorOutput
stateless boolean false
 

aiMatching._matchRegexp(req, regexps) ⇒ boolean

Kind: instance method of AiMatching

Param Type
req AIRequest
regexps Array.<RegexpComparator>
 

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

Param Type Description
text string input text
 

IntentRule : string | EntityExpression

Kind: global typedef

 

BotPath : object

Kind: global typedef
Properties

Name Type
path string
 

IntentAction : object

Kind: global typedef
Properties

Name Type
action string
intent Intent
sort number
local boolean
aboveConfidence boolean
[winner] boolean
[title] string
 

DetectedEntity : object

Kind: global typedef
Properties

Name Type
[start] number
[entity] string
[end] number
[score] number
[value] string \ number \ boolean
[text] string
 

EntityDetector ⇒ Array.<DetectedEntity> | DetectedEntity | Promise.<DetectedEntity> | Promise.<Array.<DetectedEntity>>

Kind: global typedef

Param Type Description
text string part of text
entities Array.<DetectedEntity> dependent entities
 

ValueExtractor ⇒ *

Kind: global typedef

Param Type Description
match Array.<string> regexp result
entities Array.<DetectedEntity> dependent entities
 

Entity : object

Kind: global typedef

Param Type
entity string
value string
score number
 

Intent : object

Kind: global typedef

Param Type
intent string
score number
[entities] Array.<Entity>
 

Result : object

Kind: global typedef

Param Type
text string
entities Array.<Entity>
intents Array.<Intent>
 

Entity : object

Kind: global typedef

Param Type
entity string
value string
score number
 

Intent : object

Kind: global typedef

Param Type
intent string
score number
[entities] Array.<Entity>
 

Result : object

Kind: global typedef

Param Type
entities Array.<Entity>
intents Array.<Intent>
 

Entity : object

Kind: global typedef

Param Type
entity string
value string
score number
 

Intent : object

Kind: global typedef

Param Type
intent string
score number
[entities] Array.<Entity>
 

Result : object

Kind: global typedef

Param Type
entities Array.<Entity>
intents Array.<Intent>
 

Compare : string

Kind: global typedef

 

Entity : object

Kind: global typedef

Param Type
entity string
value string
score number
 

Intent : object

Kind: global typedef

Param Type
[intent] string
score number
[entities] Array.<Entity>
 

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>
[state] object

results matching ""

    No results matching ""