@nlpjs/nlu
Advanced tools
Comparing version 4.19.1 to 4.19.8
{ | ||
"name": "@nlpjs/nlu", | ||
"version": "4.19.1", | ||
"version": "4.19.8", | ||
"description": "Natural Language Understanding", | ||
@@ -33,3 +33,3 @@ "author": { | ||
}, | ||
"gitHead": "3d7b54a00945a739c656e05a1dd44a7fb4bcca37" | ||
"gitHead": "49e973312ce0d74e38c6a7bec8610a7e50b4ec65" | ||
} |
@@ -24,3 +24,3 @@ /* | ||
const { Clonable } = require('@nlpjs/core'); | ||
const { Clonable, compareWildcars } = require('@nlpjs/core'); | ||
@@ -261,6 +261,18 @@ const defaultDomainName = 'master_domain'; | ||
async classifyByStemDict(utterance, domainName) { | ||
matchAllowList(intent, allowList) { | ||
for (let i = 0; i < allowList.length; i += 1) { | ||
if (compareWildcars(intent, allowList[i])) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
async classifyByStemDict(utterance, domainName, allowList) { | ||
const key = await this.generateStemKey(utterance); | ||
const resolved = this.stemDict[key]; | ||
if (resolved && (!domainName || resolved.domain === domainName)) { | ||
if (allowList && !this.matchAllowList(resolved.intent, allowList)) { | ||
return undefined; | ||
} | ||
const classifications = []; | ||
@@ -282,12 +294,2 @@ classifications.push({ | ||
isAllowed(intent, allowList) { | ||
if (!allowList) { | ||
return true; | ||
} | ||
if (Array.isArray(allowList)) { | ||
return allowList.includes(intent); | ||
} | ||
return !!allowList[intent]; | ||
} | ||
async innerClassify(srcInput, domainName) { | ||
@@ -297,12 +299,8 @@ const input = srcInput; | ||
if (settings.useStemDict) { | ||
const result = await this.classifyByStemDict(input.utterance, domainName); | ||
if ( | ||
result && | ||
this.isAllowed( | ||
result.classifications[0] | ||
? result.classifications[0].intent | ||
: undefined, | ||
settings.allowList | ||
) | ||
) { | ||
const result = await this.classifyByStemDict( | ||
input.utterance, | ||
domainName, | ||
srcInput.settings ? srcInput.settings.allowList : undefined | ||
); | ||
if (result) { | ||
input.classification = result; | ||
@@ -309,0 +307,0 @@ input.explanation = [ |
@@ -24,3 +24,3 @@ /* | ||
const { Clonable } = require('@nlpjs/core'); | ||
const { Clonable, compareWildcars } = require('@nlpjs/core'); | ||
const { SpellCheck } = require('@nlpjs/similarity'); | ||
@@ -267,2 +267,5 @@ | ||
} | ||
if (!result.length) { | ||
result.push({ intent: 'None', score: 1 }); | ||
} | ||
input.classifications = result.sort((a, b) => b.score - a.score); | ||
@@ -282,9 +285,17 @@ } | ||
matchAllowList(intent, allowList) { | ||
for (let i = 0; i < allowList.length; i += 1) { | ||
if (compareWildcars(intent, allowList[i])) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
intentIsActivated(intent, tokens, allowList) { | ||
if (allowList) { | ||
if (Array.isArray(allowList)) { | ||
if (!allowList.includes(intent)) { | ||
return false; | ||
} | ||
} else if (!allowList[intent]) { | ||
return this.matchAllowList(intent, allowList); | ||
} | ||
if (!allowList[intent]) { | ||
return false; | ||
@@ -291,0 +302,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62298
1363