@nlpjs/console-connector
Advanced tools
Comparing version 4.11.0 to 4.13.0
{ | ||
"name": "@nlpjs/console-connector", | ||
"version": "4.11.0", | ||
"version": "4.13.0", | ||
"description": "Console Connector", | ||
@@ -30,3 +30,3 @@ "author": { | ||
}, | ||
"gitHead": "9b24db3f2a381399cad134bdab734e36744fcde1" | ||
"gitHead": "926fe345330eca1a13eaaf04d0bba3631a5bba8b" | ||
} |
@@ -32,6 +32,40 @@ ![NLPjs logo](../../screenshots/nlplogo.gif) | ||
## Example of use | ||
## Example of use inside NLP.js | ||
This is a little bit special component. It allows to manage scenarios where the main interface way is the console. You can find an example of use on **`examples/02-qna-classic`**. | ||
## Example of use of the package | ||
```javascript | ||
const { ConsoleConnector } = require('@nlpjs/console-connector'); | ||
const connector = new ConsoleConnector(); | ||
connector.onHear = (self, text) => { | ||
self.say(`You said "${text}"`); | ||
}; | ||
connector.say('Say something!'); | ||
``` | ||
## Example of use with @nlpjs/basic | ||
You must have a file _corpus.json_ in the folder of the source code: | ||
```javascript | ||
const { dockStart } = require('@nlpjs/basic'); | ||
(async () => { | ||
const dockConfiguration = { | ||
settings: { | ||
nlp: { corpora: ['./corpus.json'] }, | ||
}, | ||
use: ['Nlp', 'ConsoleConnector'] | ||
}; | ||
const dock = await dockStart(dockConfiguration); | ||
const nlp = dock.get('nlp'); | ||
await nlp.train(); | ||
const connector = dock.get('console'); | ||
connector.say('Say something!'); | ||
})(); | ||
``` | ||
## Contributing | ||
@@ -38,0 +72,0 @@ |
@@ -44,2 +44,3 @@ /* | ||
); | ||
this.context = {}; | ||
this.initialize(); | ||
@@ -93,7 +94,11 @@ } | ||
if (nlp) { | ||
const result = await nlp.process({ | ||
message: line, | ||
channel: 'console', | ||
app: this.container.name, | ||
}); | ||
const result = await nlp.process( | ||
{ | ||
message: line, | ||
channel: 'console', | ||
app: this.container.name, | ||
}, | ||
undefined, | ||
this.context | ||
); | ||
this.say(result); | ||
@@ -100,0 +105,0 @@ } else { |
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
10545
140
112