Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

chat - How to use contextdata in node-nlp properly?

I am currently trying to create a chatbot and adding some contextdata to it, like in this example: https://github.com/axa-group/nlp.js/tree/master/examples/14-ner-corpus

I have tried several variants of configs, filenames, file paths etc. I even looked up the source code if the contextdata corpus gets read, which it does.

But at the end when running my code against "what is the real name of spiderman?" the {{ hero }} part gets replaced, but the {{ _data[entities.hero.option].realName }} doesn't.

My code currently looks like this:

import { NlpManager, ConversationContext } from 'node-nlp'
const manager = new NlpManager({
    languages: ['en'],
    forceNER: true,
    autoSave: false,
    nlu: { useNoneFeature: true }
})
const context = new ConversationContext()
manager.addCorpora('./corpus.json')
await manager.train()

const response = await manager.process(
    'en',
    'what is the real name of spiderman?',
    context
)
console.log(response)

The corpus files i use are those linked in the example above:

https://github.com/axa-group/nlp.js/blob/master/examples/14-ner-corpus/corpus.json

https://github.com/axa-group/nlp.js/blob/master/examples/14-ner-corpus/heros.json

I hope someone can give me a pointer at what i am doing wrong here.

question from:https://stackoverflow.com/questions/65878376/how-to-use-contextdata-in-node-nlp-properly

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I solved it with the help of https://github.com/jesus-seijas-sp

const { NlpManager } = require('node-nlp');

(async () => {
  const activity = {
    conversation: {
      id: 'a1'
    }
  }

  const manager = new NlpManager({
    languages: ['en'],
    forceNER: true,
    autoSave: false,
    nlu: { useNoneFeature: true }
  })
  manager.addCorpora('./corpus.json')
  await manager.train()
  const response = await manager.process({ locale: 'en', utterance: 'what is the real name of spiderman?', activity });
  console.log(response)
})();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...