Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-disable no-unused-expressions */
import { BayesClassifier } from 'natural'
import { NlpManager, NluManager } from 'node-nlp'
import logger from 'hoopa-logger'
import baseKnowledge from '../../brain/knowledge'
const LanguageProcessor = new NlpManager({ languages: 'en' })
const UnderstandingProcessor = new NluManager({ languages: 'en' })
const NLP = {
Bayes: new BayesClassifier(),
LanguageProcessor,
UnderstandingProcessor,
trainModel: (newKnowledge = null, bayes, manager) => {
logger.info('Cognitive analysis (NLP & NLU), basic training...')
const trainingContext = baseKnowledge.natural
if (newKnowledge) {
newKnowledge.map(token => trainingContext.push(token))
}
trainingContext.map(token => {
UnderstandingProcessor.addDocument('en', token.input, token.class)
manager.addDocument('en', token.input, token.class)