Classes

Ai
CustomEntityDetectionModel
WingbotModel
CachedModel
AiMatching

{AiMatching}

Class responsible for NLP Routing by score

Members

handlebars : Handlebars

Constants

ISO_8601_REGEX : RegExp

RegExp to test a string for a ISO 8601 Date spec YYYY YYYY-MM YYYY-MM-DD YYYY-MM-DDThh:mmTZD YYYY-MM-DDThh:mm:ssTZD YYYY-MM-DDThh:mm:ss.sTZD

Typedefs

EntityExpression : object
textFilterstring

Text filter function

IntentRule : string | EntityExpression
BotPath : object
WordDetectorData : object
WordEntityDetectorFactoryPromise.<WordDetectorData>
DetectedEntity : object
EntityDetectorArray.<DetectedEntity> | DetectedEntity | Promise.<DetectedEntity> | Promise.<Array.<DetectedEntity>>
ValueExtractor*
Entity : object
Intent : object
Result : object
DetectorOptions : object
WordEntityDetectorArray.<DetectedEntity>
Phrases : object
Entity : object
Intent : object
Result : object
Entity : object
Intent : object
Result : object
EntityMatchingResult : object
Compare : string
Entity : object
Intent : object
Comparable : string | number | function
EntityExpression : object
IntentRule : string | EntityExpression
RegexpComparator : object
PreprocessorOutput : object
AIRequest : object
ConfidenceProvider : 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.sttMaxAlternatives : number

Upper limit for NLP resolving of STT alternatives

Kind: instance property of Ai

 

ai.sttScoreThreshold : number

Minimal score to consider text as recognized well

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.DEFAULT_PREFIX : string

Kind: instance property of Ai

 

ai.getPrefix(defaultModel, req)

The prefix translator - for request-specific prefixes

Kind: instance method of Ai

ParamType
defaultModelstring
reqRequest
 

ai.textFilter(text) : textFilter

Preprocess text for NLP For example to remove any confidential data

Kind: instance method of Ai

ParamType
textstring
 

ai.detectEntities(text, prefix) ⇒ Promise.<Array.<Entity>>

Kind: instance method of Ai

ParamType
textstring
prefixstring | Request
 

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

Usefull method for testing AI routes

Kind: instance method of Ai

ParamTypeDefaultDescription
[intent]stringnullintent name
[score]numberthe 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, [options]) ⇒ T

Registers Wingbot AI model

Kind: instance method of Ai

ParamTypeDefaultDescription
modelstring | WingbotModel | Tnullwingbot model name or AI plugin
prefixstringmodel prefix
[options]object{}
[options.cacheSize]number
[options.verbose]boolean
[options.cachePhrasesTime]number
 

ai.registerEntityDetector(name, detector, [options]) ⇒ this

Kind: instance method of Ai

ParamTypeDescription
namestring
detectorEntityDetector | RegExp
[options]object
[options.anonymize]booleanif true, value will not be sent to NLP
[options.extractValue]function | stringentity extractor
[options.matchWholeWords]booleanmatch whole words at regular expression
[options.replaceDiacritics]booleankeep diacritics when matching regexp
[options.caseSensitiveRegex]booleanmake regex case sensitive
[options.dependencies]Array.<string>array of dependent entities
[options.clearOverlaps]booleanlet longer entities from NLP to replace entity
 

ai.setWordEntityDetector(wordEntityDetector)

Kind: instance method of Ai

 

ai.configureEntityDetector(name, options) ⇒ this

Sets options to entity detector. Useful for disabling anonymization of local system entities.

Kind: instance method of Ai

ParamTypeDescription
namestring
optionsobject
[options.anonymize]boolean
[options.clearOverlaps]booleanset true to override entities from NLP

Example

ai.register('wingbot-model-name')
.setDetectorOptions('phone', { anonymize: false })
.setDetectorOptions('email', { anonymize: false })
 

ai.deregister([prefix])

Remove registered model

Kind: instance method of Ai

ParamType
[prefix]string
 

ai.getModel(prefix) ⇒ CustomEntityDetectionModel

Returns registered AI model

Kind: instance method of Ai

ParamTypeDescription
prefixstringmodel 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

ParamTypeDefaultDescription
pathstring
intentsIntentRule | Array.<IntentRule>
[title]string | functionnulldisambiguation title
[meta]objectmetadata for multibot environments
[meta.targetAppId]objecttarget application id
[meta.targetAction]objecttarget 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

ParamTypeDefaultDescription
pathstring
intentsIntentRule | Array.<IntentRule>
[title]string | functionnulldisambiguation 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) ⇒ Resolver

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

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.preloadDetectors() ⇒ Promise

Kind: instance method of Ai

 

ai.preloadAi(req, [res]) ⇒ Promise

Kind: instance method of Ai

ParamTypeDefault
reqRequest
[res]Responder
 

ai.getPhrases(req) ⇒ Promise.<Phrases>

Returns phrases model from AI

Kind: instance method of Ai

ParamType
reqRequest
 

ai._setResultToReqRes(req, res, result) ⇒ void

Kind: instance method of Ai

ParamType
reqRequest
resResponder
resultResult
 

ai._preloadIntent(req, [res]) ⇒ Promise

Kind: instance method of Ai

ParamTypeDefault
reqRequest
[res]Responder
 

ai.shouldDisambiguate(aiActions, [forQuickReplies]) ⇒ boolean

Kind: instance method of Ai

ParamTypeDefault
aiActionsArray.<IntentAction>
[forQuickReplies]booleanfalse
 

CustomEntityDetectionModel

Kind: global class

 

new CustomEntityDetectionModel(options, [log])

ParamType
optionsobject
[options.prefix]string
[options.verbose]boolean
[log]Object
 

customEntityDetectionModel.phrasesCacheTime : number

Kind: instance property of CustomEntityDetectionModel

 

customEntityDetectionModel.maxWordCount : number

Kind: instance property of CustomEntityDetectionModel

 

customEntityDetectionModel.wordEntityDetector : WordEntityDetector

Kind: instance property of CustomEntityDetectionModel

 

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

Kind: instance method of CustomEntityDetectionModel

ParamType
entitiesArray.<DetectedEntity>
entitystring
textstring
offsetnumber
originalTextstring
 

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

Kind: instance method of CustomEntityDetectionModel

ParamType
entitystring
textstring
entitiesArray.<DetectedEntity>
subWordArray.<DetectedEntity>
 

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

Kind: instance method of CustomEntityDetectionModel

ParamType
entitystring
textstring
entitiesArray.<DetectedEntity>
subWordArray.<DetectedEntity>
detectSubWordsboolean
 

customEntityDetectionModel.nonOverlapping(entities, [expectedEntities], [justDuplicates]) ⇒ Array.<DetectedEntity>

Return only entities without overlap

Kind: instance method of CustomEntityDetectionModel

ParamTypeDefault
entitiesArray.<DetectedEntity>
[expectedEntities]Array.<string>
[justDuplicates]booleanfalse
 

customEntityDetectionModel.getDependentEntities([known]) ⇒ Array.<string>

Kind: instance method of CustomEntityDetectionModel
Returns: Array.<string> - -

ParamTypeDefault
[known]boolean
 

customEntityDetectionModel.resolveEntities(text, [singleEntity], [expected], [prevEnts], [subWord]) ⇒ Promise.<Array.<DetectedEntity>>

Kind: instance method of CustomEntityDetectionModel

ParamTypeDefaultDescription
textstring
[singleEntity]stringnull
[expected]Array.<string>
[prevEnts]Array.<DetectedEntity>previously detected entities to include
[subWord]Array.<DetectedEntity>previously detected entities within words
 

customEntityDetectionModel.resolve(text, [req]) ⇒ Promise.<Result>

Kind: instance method of CustomEntityDetectionModel

ParamTypeDescription
textstringthe user input
[req]Request
 

customEntityDetectionModel._extractRegExpDependencies(regexp)

Kind: instance method of CustomEntityDetectionModel

ParamType
regexpRegExp | string
 

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

Kind: instance method of CustomEntityDetectionModel

ParamType
entitiesArray.<DetectedEntity>
dependencystring
 

customEntityDetectionModel._regexpToDetector(regexp, [options])

Kind: instance method of CustomEntityDetectionModel

ParamTypeDescription
regexpRegExp
[options]object
[options.extractValue]function | stringentity extractor
[options.matchWholeWords]booleanmatch whole words at regular expression
[options.replaceDiacritics]booleanreplace diacritics when matching regexp
[options.dependencies]Array.<string>array of dependent entities
[options.caseSensitiveRegex]booleanmake regex case sensitive
 

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

Kind: instance method of CustomEntityDetectionModel

ParamType
namestring
detectorEntityDetector | RegExp
[options]DetectorOptions
 

customEntityDetectionModel.setDetectorOptions(name, options) ⇒ this

Sets options to entity detector. Useful for disabling anonymization of local system entities.

Kind: instance method of CustomEntityDetectionModel

ParamType
namestring
optionsobject
[options.anonymize]boolean
[options.clearOverlaps]boolean

Example

ai.register('wingbot-model-name')
.setDetectorOptions('phone', { anonymize: false })
.setDetectorOptions('email', { anonymize: false })
 

WingbotModel

Kind: global class

 

new WingbotModel(options, [log])

ParamType
optionsobject
[options.prefix]string
[options.serviceUrl]string
[options.trainingUrl]string
options.modelstring
[options.cacheSize]number
[options.matches]number
[options.verbose]boolean
[options.fetch]function
[log]Object
 

wingbotModel._fetch : fetch

Kind: instance property of WingbotModel

 

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

Kind: instance method of WingbotModel

ParamTypeDefault
textstring
entitiesArray.<Entity>
 

CachedModel

Kind: global class

 

new CachedModel(options, [log])

ParamType
optionsobject
[options.prefix]string
[options.cacheSize]number
[options.verbose]boolean
[options.cachePhrasesTime]number
[log]Object
 

cachedModel.phrasesCacheTime : number

Kind: instance property of CachedModel

 

cachedModel.resolve(text, [req]) ⇒ Promise.<Result>

Kind: instance method of CachedModel

ParamTypeDefaultDescription
textstringthe user input
[req]Requestthe user input
 

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

Kind: instance method of CachedModel

ParamType
textstring
entitiesArray.<Entity>
 

AiMatching

{AiMatching}

Class responsible for NLP Routing by score

Kind: global class

 

new AiMatching(ai)

 

aiMatching.optionalHandicap : number

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

Kind: instance property of AiMatching

 

aiMatching.optionalEqualityHandicap : number

When the entity is equal-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.02 by default)

Kind: instance property of AiMatching

 

aiMatching.redundantEntityClamp : number

Upper threshold for redundant entity handicaps

Kind: instance property of AiMatching

 

aiMatching.redundantIntentHandicap : number

When there is additional intent, the final score will be lowered by this value (0.02 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.stateEntityScore

Score of a context entity within a conversation state (1 by default)

Kind: instance property of AiMatching

 

aiMatching.regexpScore

Score of matched regexp (1.02 by default)

Kind: instance property of AiMatching

 

aiMatching.getSetStateForEntityRules(rule) ⇒ object

Kind: instance method of AiMatching

ParamType
rulePreprocessorOutput
 

aiMatching.parseEntitiesFromIntentRule(intentRule, onlyExpected) ⇒ Array.<string>

Create a rule to be cached inside a routing structure

Kind: instance method of AiMatching

ParamTypeDefault
intentRuleIntentRule | Array.<IntentRule>
onlyExpectedbooleanfalse
 

aiMatching._parseEntitiesFromIntentRule(intentRules) ⇒ Array.<EntityExpression>

Kind: instance method of AiMatching

ParamType
intentRulesArray.<IntentRule>
 

aiMatching.preprocessRule(intentRule) ⇒ PreprocessorOutput

Create a rule to be cached inside a routing structure

Kind: instance method of AiMatching

ParamType
intentRuleIntentRule | Array.<IntentRule>
 

aiMatching.match(req, rule, [stateless], [reqEntities], [noEntityThreshold]) ⇒ Intent | null

Calculate a matching score of preprocessed rule against the request

Kind: instance method of AiMatching

ParamTypeDefault
reqAIRequest
rulePreprocessorOutput
[stateless]booleanfalse
[reqEntities]Array.<Entity>
[noEntityThreshold]booleanfalse
 

aiMatching._matchRegexp(req, regexps, noIntentHandicap) ⇒ number

Kind: instance method of AiMatching

ParamType
reqAIRequest
regexpsArray.<RegexpComparator>
noIntentHandicapnumber
 

handlebars : Handlebars

Kind: global variable

 

COMPARE : enum

Kind: global enum
Properties

NameTypeDefault
EQUALCompareeq
NOT_EQUALComparene
RANGEComparerange
GTComparegt
GTEComparegte
LTComparelt
LTEComparelte
 

ISO_8601_REGEX : RegExp

RegExp to test a string for a ISO 8601 Date spec YYYY YYYY-MM YYYY-MM-DD YYYY-MM-DDThh:mmTZD YYYY-MM-DDThh:mm:ssTZD YYYY-MM-DDThh:mm:ss.sTZD

Kind: global constant
See: https://www.w3.org/TR/NOTE-datetime

 

EntityExpression : object

Kind: global typedef
Properties

NameTypeDescription
entitystringthe requested entity
[optional]booleanentity is optional, can be missing in request
[op]Comparecomparison operation (eq
[compare]Array.<string> | Array.<number>value to compare with
 

textFilter ⇒ string

Text filter function

Kind: global typedef
Returns: string - - filtered text

ParamTypeDescription
textstringinput text
 

IntentRule : string | EntityExpression

Kind: global typedef

 

BotPath : object

Kind: global typedef
Properties

NameType
pathstring
 

WordDetectorData : object

Kind: global typedef
Properties

NameType
detectorWordEntityDetector
[maxWordCount]number
 

WordEntityDetectorFactory ⇒ Promise.<WordDetectorData>

Kind: global typedef

 

DetectedEntity : object

Kind: global typedef
Properties

NameType
[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

ParamTypeDescription
textstringpart of text
entitiesArray.<DetectedEntity>dependent entities
[searchWithinWords]booleanoptional ability to search within words
 

ValueExtractor ⇒ *

Kind: global typedef

ParamTypeDescription
matchArray.<string>regexp result
entitiesArray.<DetectedEntity>dependent entities
 

Entity : object

Kind: global typedef
Properties

NameType
entitystring
valuestring
scorenumber
 

Intent : object

Kind: global typedef
Properties

NameType
intentstring
scorenumber
[entities]Array.<Entity>
 

Result : object

Kind: global typedef
Properties

NameType
[text]string
entitiesArray.<Entity>
intentsArray.<Intent>
 

DetectorOptions : object

Kind: global typedef
Properties

NameTypeDescription
[anonymize]booleanif true, value will not be sent to NLP
[extractValue]function | stringentity extractor
[matchWholeWords]booleanmatch whole words at regular expression
[replaceDiacritics]booleankeep diacritics when matching regexp
[options.caseSensitiveRegex]booleanmake regex case sensitive
[dependencies]Array.<string>array of dependent entities
[clearOverlaps]booleanlet longer entities from NLP to replace entity
 

WordEntityDetector ⇒ Array.<DetectedEntity>

Kind: global typedef

ParamType
textstring
[entities]Array.<DetectedEntity>
[startIndex]number
[prefix]string
 

Phrases : object

Kind: global typedef
Properties

NameType
phrasesMap.<string, Array.<string>>
 

Entity : object

Kind: global typedef

ParamType
entitystring
valuestring
scorenumber
 

Intent : object

Kind: global typedef

ParamType
intentstring
scorenumber
[entities]Array.<Entity>
 

Result : object

Kind: global typedef

ParamType
entitiesArray.<Entity>
intentsArray.<Intent>
 

Entity : object

Kind: global typedef
Properties

NameType
entitystring
valuestring
scorenumber
 

Intent : object

Kind: global typedef
Properties

NameType
intentstring
scorenumber
[entities]Array.<Entity>
 

Result : object

Kind: global typedef
Properties

NameType
[text]string
entitiesArray.<Entity>
intentsArray.<Intent>
 

EntityMatchingResult : object

Kind: global typedef
Properties

NameType
scorenumber
handicapnumber
fromStatenumber
minScorenumber
metlnumber
matchedArray.<Entity>
 

Compare : string

Kind: global typedef

 

Entity : object

Kind: global typedef

ParamType
entitystring
valuestring
scorenumber
 

Intent : object

Kind: global typedef

ParamType
[intent]string
scorenumber
[entities]Array.<Entity>
 

Comparable : string | number | function

Kind: global typedef

 

EntityExpression : object

Kind: global typedef
Properties

NameTypeDescription
entitystringthe requested entity
[optional]booleanthe match is optional
[op]Comparecomparison operation
[compare]Array.<Comparable>value to compare
 

IntentRule : string | EntityExpression

Kind: global typedef

 

RegexpComparator : object

Kind: global typedef
Properties

NameTypeDescription
rRegExpregular expression
tbooleanuse normalized text
fbooleanis full match
 

PreprocessorOutput : object

Kind: global typedef
Properties

NameType
regexpsArray.<RegexpComparator>
intentsArray.<string>
entitiesArray.<EntityExpression>
 

AIRequest : object

Kind: global typedef
Properties

NameType
textfunction
intentsArray.<Intent> | null
entitiesArray.<Entity>
[configuration]object
[state]object
[actionData]function
 

ConfidenceProvider : object

Kind: global typedef
Properties

NameType
confidencenumber