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 - textFilter ⇒
string Text filter function
- IntentRule :
string|EntityExpression - BotPath :
object - WordDetectorData :
object - WordEntityDetectorFactory ⇒
Promise.<WordDetectorData> - DetectedEntity :
object - EntityDetector ⇒
Array.<DetectedEntity>|DetectedEntity|Promise.<DetectedEntity>|Promise.<Array.<DetectedEntity>> - ValueExtractor ⇒
* - Entity :
object - Intent :
object - Result :
object - DetectorOptions :
object - WordEntityDetector ⇒
Array.<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 - .threshold :
number - .sttMaxAlternatives :
number - .sttScoreThreshold :
number - .logger :
object - .matcher :
AiMatching - .DEFAULT_PREFIX :
string - .getPrefix(defaultModel, req)
- .textFilter(text) :
textFilter - .detectEntities(text, prefix) ⇒
Promise.<Array.<Entity>> - .mockIntent([intent], [score]) ⇒
this - .register(model, prefix, [options]) ⇒
T - .registerEntityDetector(name, detector, [options]) ⇒
this - .setWordEntityDetector(wordEntityDetector)
- .configureEntityDetector(name, options) ⇒
this - .deregister([prefix])
- .getModel(prefix) ⇒
CustomEntityDetectionModel - .global(path, intents, [title], [meta]) ⇒
object - .local(path, intents, [title]) ⇒
object - .match(intent) ⇒
Resolver - .preloadDetectors() ⇒
Promise - .preloadAi(req, [res]) ⇒
Promise - .getPhrases(req) ⇒
Promise.<Phrases> - ._setResultToReqRes(req, res, result) ⇒
void - ._preloadIntent(req, [res]) ⇒
Promise - ._queryModelWithTexts(model, texts, [req]) ⇒
Promise.<Result> - .queryModel(text, langOrReq) ⇒
Promise.<Result> - .shouldDisambiguate(aiActions, [forQuickReplies]) ⇒
boolean
- .confidence :
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
| Param | Type |
|---|---|
| defaultModel | string |
| req | IStateRequest |
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.detectEntities(text, prefix) ⇒ Promise.<Array.<Entity>>
Kind: instance method of Ai
| Param | Type |
|---|---|
| text | string |
| prefix | string | Request |
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, [options]) ⇒ T
Registers Wingbot AI model
Kind: instance method of Ai
| Param | Type | Default | Description |
|---|---|---|---|
| model | string | WingbotModel | T | null | wingbot model name or AI plugin |
| prefix | string | model prefix | |
| [options] | object | {} | |
| [options.cacheSize] | number | ||
| [options.verbose] | boolean | ||
| [options.cachePhrasesTime] | number |
ai.registerEntityDetector(name, detector, [options]) ⇒ this
Kind: instance method of Ai
| 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.matchWholeWords] | boolean | match whole words at regular expression |
| [options.replaceDiacritics] | boolean | keep diacritics when matching regexp |
| [options.caseSensitiveRegex] | boolean | make regex case sensitive |
| [options.dependencies] | Array.<string> | array of dependent entities |
| [options.clearOverlaps] | boolean | let longer entities from NLP to replace entity |
ai.setWordEntityDetector(wordEntityDetector)
Kind: instance method of Ai
| Param | Type |
|---|---|
| wordEntityDetector | WordEntityDetector | WordEntityDetectorFactory | WordDetectorData |
ai.configureEntityDetector(name, options) ⇒ this
Sets options to entity detector. Useful for disabling anonymization of local system entities.
Kind: instance method of Ai
| Param | Type | Description |
|---|---|---|
| name | string | |
| options | object | |
| [options.anonymize] | boolean | |
| [options.clearOverlaps] | boolean | set 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
| Param | Type |
|---|---|
| [prefix] | string |
ai.getModel(prefix) ⇒ CustomEntityDetectionModel
Returns registered AI model
Kind: instance method of Ai
| Param | Type | Description |
|---|---|---|
| prefix | string | 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 | function | 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 | function | 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) ⇒ 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
| 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.preloadDetectors() ⇒ Promise
Kind: instance method of Ai
ai.preloadAi(req, [res]) ⇒ Promise
Kind: instance method of Ai
| Param | Type | Default |
|---|---|---|
| req | Request | |
| [res] | Responder | |
ai.getPhrases(req) ⇒ Promise.<Phrases>
Returns phrases model from AI
Kind: instance method of Ai
| Param | Type |
|---|---|
| req | Request |
ai._setResultToReqRes(req, res, result) ⇒ void
Kind: instance method of Ai
| Param | Type |
|---|---|
| req | Request |
| res | Responder |
| result | Result |
ai._preloadIntent(req, [res]) ⇒ Promise
Kind: instance method of Ai
| Param | Type | Default |
|---|---|---|
| req | Request | |
| [res] | Responder | |
ai._queryModelWithTexts(model, texts, [req]) ⇒ Promise.<Result>
Kind: instance method of Ai
| Param | Type | Default |
|---|---|---|
| model | CustomEntityDetectionModel | |
| texts | Array.<TextAlternative> | |
| [req] | Request | |
ai.queryModel(text, langOrReq) ⇒ Promise.<Result>
Kind: instance method of Ai
| Param | Type |
|---|---|
| text | string |
| langOrReq | string | IStateRequest |
ai.shouldDisambiguate(aiActions, [forQuickReplies]) ⇒ boolean
Kind: instance method of Ai
| Param | Type | Default |
|---|---|---|
| aiActions | Array.<IntentAction> | |
| [forQuickReplies] | boolean | false |
CustomEntityDetectionModel
Kind: global class
- CustomEntityDetectionModel
- new CustomEntityDetectionModel(options, [log])
- .phrasesCacheTime :
number - .maxWordCount :
number - .wordEntityDetector :
WordEntityDetector - ._normalizeResult(entities, entity, text, offset, originalText)
- ._detectAllEntities(entity, text, entities, subWord) ⇒
Promise.<Array.<DetectedEntity>> - ._detectEntities(entity, text, entities, subWord, detectSubWords) ⇒
Promise.<Array.<DetectedEntity>> - .nonOverlapping(entities, [expectedEntities], [justDuplicates]) ⇒
Array.<DetectedEntity> - .getDependentEntities([known]) ⇒
Array.<string> - .resolveEntities(text, [singleEntity], [expected], [prevEnts], [subWord]) ⇒
Promise.<Array.<DetectedEntity>> - .resolve(text, [req]) ⇒
Promise.<Result> - ._extractRegExpDependencies(regexp)
- ._entityByDependency(entities, dependency) ⇒
DetectedEntity|null - ._regexpToDetector(regexp, [options])
- .setEntityDetector(name, detector, [options]) ⇒
this - .setDetectorOptions(name, options) ⇒
this
new CustomEntityDetectionModel(options, [log])
| Param | Type |
|---|---|
| options | object |
| [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
| Param | Type |
|---|---|
| entities | Array.<DetectedEntity> |
| entity | string |
| text | string |
| offset | number |
| originalText | string |
customEntityDetectionModel._detectAllEntities(entity, text, entities, subWord) ⇒ Promise.<Array.<DetectedEntity>>
Kind: instance method of CustomEntityDetectionModel
| Param | Type |
|---|---|
| entity | string |
| text | string |
| entities | Array.<DetectedEntity> |
| subWord | Array.<DetectedEntity> |
customEntityDetectionModel._detectEntities(entity, text, entities, subWord, detectSubWords) ⇒ Promise.<Array.<DetectedEntity>>
Kind: instance method of CustomEntityDetectionModel
| Param | Type |
|---|---|
| entity | string |
| text | string |
| entities | Array.<DetectedEntity> |
| subWord | Array.<DetectedEntity> |
| detectSubWords | boolean |
customEntityDetectionModel.nonOverlapping(entities, [expectedEntities], [justDuplicates]) ⇒ Array.<DetectedEntity>
Return only entities without overlap
Kind: instance method of CustomEntityDetectionModel
| Param | Type | Default |
|---|---|---|
| entities | Array.<DetectedEntity> | |
| [expectedEntities] | Array.<string> | |
| [justDuplicates] | boolean | false |
customEntityDetectionModel.getDependentEntities([known]) ⇒ Array.<string>
Kind: instance method of CustomEntityDetectionModel
Returns: Array.<string> - -
| Param | Type | Default |
|---|---|---|
| [known] | boolean | |
customEntityDetectionModel.resolveEntities(text, [singleEntity], [expected], [prevEnts], [subWord]) ⇒ Promise.<Array.<DetectedEntity>>
Kind: instance method of CustomEntityDetectionModel
| Param | Type | Default | Description |
|---|---|---|---|
| text | string | ||
| [singleEntity] | string | null | |
| [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
| Param | Type | Description |
|---|---|---|
| text | string | the user input |
| [req] | Request |
customEntityDetectionModel._extractRegExpDependencies(regexp)
Kind: instance method of CustomEntityDetectionModel
| Param | Type |
|---|---|
| regexp | RegExp | string |
customEntityDetectionModel._entityByDependency(entities, dependency) ⇒ DetectedEntity | null
Kind: instance method of CustomEntityDetectionModel
| Param | Type |
|---|---|
| entities | Array.<DetectedEntity> |
| dependency | string |
customEntityDetectionModel._regexpToDetector(regexp, [options])
Kind: instance method of CustomEntityDetectionModel
| Param | Type | Description |
|---|---|---|
| regexp | RegExp | |
| [options] | object | |
| [options.extractValue] | function | string | entity extractor |
| [options.matchWholeWords] | boolean | match whole words at regular expression |
| [options.replaceDiacritics] | boolean | replace diacritics when matching regexp |
| [options.dependencies] | Array.<string> | array of dependent entities |
| [options.caseSensitiveRegex] | boolean | make regex case sensitive |
customEntityDetectionModel.setEntityDetector(name, detector, [options]) ⇒ this
Kind: instance method of CustomEntityDetectionModel
| Param | Type |
|---|---|
| name | string |
| detector | EntityDetector | 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
| Param | Type |
|---|---|
| name | string |
| options | object |
| [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])
| Param | Type |
|---|---|
| options | object |
| [options.prefix] | string |
| [options.serviceUrl] | string |
| [options.trainingUrl] | string |
| options.model | string |
| [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
| Param | Type | Default |
|---|---|---|
| text | string | |
| entities | Array.<Entity> | |
CachedModel
Kind: global class
- CachedModel
- new CachedModel(options, [log])
- .phrasesCacheTime :
number - .resolve(text, [req]) ⇒
Promise.<Result> - ._queryModel(text, entities) ⇒
Promise.<(Array.<Intent>|Result)>
new CachedModel(options, [log])
| Param | Type |
|---|---|
| options | object |
| [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
| Param | Type | Default | Description |
|---|---|---|---|
| text | string | the user input | |
| [req] | Request | | the user input |
cachedModel._queryModel(text, entities) ⇒ Promise.<(Array.<Intent>|Result)>
Kind: instance method of CachedModel
| Param | Type |
|---|---|
| text | string |
| entities | Array.<Entity> |
AiMatching
{AiMatching}
Class responsible for NLP Routing by score
Kind: global class
- AiMatching
- new AiMatching(ai)
- .optionalHandicap :
number - .optionalEqualityHandicap :
number - .redundantEntityHandicap :
number - .redundantEntityClamp :
number - .redundantIntentHandicap :
number - .multiMatchGain :
number - .stateEntityScore
- .regexpScore
- .getSetStateForEntityRules(rule) ⇒
object - .parseEntitiesFromIntentRule(intentRule, onlyExpected) ⇒
Array.<string> - ._parseEntitiesFromIntentRule(intentRules) ⇒
Array.<EntityExpression> - .preprocessRule(intentRule) ⇒
PreprocessorOutput - .matchText(text, rule, nlpResult, state) ⇒
Intent|null - .match(req, rule, [stateless], [reqEntities], [noEntityThreshold]) ⇒
Intent|null - ._matchRegexp(text, tokenized, regexps, noIntentHandicap) ⇒
number
new AiMatching(ai)
| Param | Type |
|---|---|
| ai | ConfidenceProvider |
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
| Param | Type |
|---|---|
| rule | PreprocessorOutput |
aiMatching.parseEntitiesFromIntentRule(intentRule, onlyExpected) ⇒ Array.<string>
Create a rule to be cached inside a routing structure
Kind: instance method of AiMatching
| Param | Type | Default |
|---|---|---|
| intentRule | IntentRule | Array.<IntentRule> | |
| onlyExpected | boolean | false |
aiMatching._parseEntitiesFromIntentRule(intentRules) ⇒ Array.<EntityExpression>
Kind: instance method of AiMatching
| Param | Type |
|---|---|
| intentRules | Array.<IntentRule> |
aiMatching.preprocessRule(intentRule) ⇒ PreprocessorOutput
Create a rule to be cached inside a routing structure
Kind: instance method of AiMatching
| Param | Type |
|---|---|
| intentRule | IntentRule | Array.<IntentRule> |
aiMatching.matchText(text, rule, nlpResult, state) ⇒ Intent | null
Kind: instance method of AiMatching
| Param | Type |
|---|---|
| text | string |
| rule | PreprocessorOutput |
| nlpResult | Result |
| state | Object |
aiMatching.match(req, rule, [stateless], [reqEntities], [noEntityThreshold]) ⇒ 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 |
| [reqEntities] | Array.<Entity> | |
| [noEntityThreshold] | boolean | false |
aiMatching._matchRegexp(text, tokenized, regexps, noIntentHandicap) ⇒ number
Kind: instance method of AiMatching
| Param | Type |
|---|---|
| text | string |
| tokenized | string |
| regexps | Array.<RegexpComparator> |
| noIntentHandicap | number |
handlebars : Handlebars
Kind: global variable
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 |
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
| Name | Type | Description |
|---|---|---|
| entity | string | the requested entity |
| [optional] | boolean | entity is optional, can be missing in request |
| [op] | Compare | comparison operation (eq |
| [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 |
WordDetectorData : object
Kind: global typedef
Properties
| Name | Type |
|---|---|
| detector | WordEntityDetector |
| [maxWordCount] | number |
WordEntityDetectorFactory ⇒ Promise.<WordDetectorData>
Kind: global typedef