There are many useful NLP libraries available such as Spacy, NLTK, and CoreNLP
Below are the top 2 NLP libraries which work with NodeJS and Javascript with the examples:
1 NLP.js
Github: https://github.com/axa-group/nlp.js
NLP.js is developed by the AXA group. It is an NLP library for building bots, with entity extraction, sentiment analysis, automatic language identify, and so more, supports 40 languages.
Here is a basic code snippet to help you understand how easy it is to set it up.
const { NlpManager } = require('node-nlp');
const manager = new NlpManager({ languages: ['en'] });
// Adds the utterances and intents for the NLP
manager.addDocument('en', 'goodbye for now', 'greetings.bye');
manager.addDocument('en', 'bye bye take care', 'greetings.bye');
// Train also the NLG
manager.addAnswer('en', 'greetings.bye', 'Till next time');
manager.addAnswer('en', 'greetings.bye', 'see you soon!');
// Train and save the model.
(async() => {
await manager.train();
manager.save();
const response = await manager.process('en', 'I should go now');
console.log(response);
})();
2 Natural
Github: https://github.com/NaturalNode/natural
Natural is another famous NLP library for Node.js. “Natural” is a general natural language facility for Node.js. It currently supports tokenizing, stemming, classification, phonetics, tf-idf, WordNet, string similarity, and some inflections.
var natural = require('natural');
var tokenizer = new natural.WordTokenizer();
console.log(tokenizer.tokenize("your dog has fleas."));
// [ 'your', 'dog', 'has', 'fleas' ]
console.log(natural.HammingDistance("karolin", "kathrin", false));
console.log(natural.HammingDistance("karolin", "kerstin", false));
// If strings differ in length -1 is returned
More libraries and sample code is present here:
https://www.kommunicate.io/blog/nlp-libraries-node-javascript/