superscriptjs / superscript

A dialogue engine for creating chat bots
http://superscriptjs.com
MIT License
1.65k stars 209 forks source link

How to add NLP to bot engine #363

Closed meghasoni closed 7 years ago

meghasoni commented 7 years ago

How do we add extra features to bot engine such as NLP tagging and question classification in super script js.

hailiang-wang commented 7 years ago

A great approach is adding plugin in ss-message. I have the the requirement for Chinese Parsing. So, you may take a look at this example

Add message plugin in options when init superscript instance

 {
    factSystem: {
      clean: true
    },
    importFile: './data.json',
    mongoURI: 'mongodb://localhost/SuperScriptSPA',
    pluginsPath: `${process.cwd()}/plugins`,
    messagePluginsPath: `${process.cwd()}/plugins_message`,
    historyCheckpoints: 100,
    conversationTimeout: 1000 * 60 * 30 // half an hour, conversation memory timeout
  },

Create a message plugin

Such as

const addWords = function addWords(cb) {
  this.message.words = this.message.clean.split(' ');
  cb();
};

You can find more examples in https://github.com/superscriptjs/ss-message

Get the NLP Tags when processing chat message

In a superscript plugin,

exports.checkMessageFeatures = async function (cb) {
    debug('checkMessageFeatures', this.message)
    cb(null, {
        lang_code: this.message.lang_code # note this lang_code is attached by the message plugin.
    })
}
bensalilijames commented 7 years ago

Thanks for the answer @Samurais!

I believe there are also POS tags already generated on this.message.nlp, and this.message.isQuestion will tell you whether the message is a question or not.

Alternatively, you can always add your own like above, using other libraries or web services!

dcsan commented 7 years ago

i think @Samurais is mainly doing POS tagging for Chinese so needed to insert his own NLP tagger calls. chinese also requires segmentation.