Natural Language Processing with JavaScript
Natural language processing – a form of AI ,refers to how to program computers to process and analyze every day human language.
It is the concept behind most of our speech recognition,text-to-speech and text generation as well as conversational AI.
In this tutorial we will be learning how to use JavaScript for natural language processing(NLP).
Javascript offers several libraries and packages for doing N.L.P.These include
- Compromise.js
- Sentiment
- Natural
- Franc
- Talisman
- etc
In this section we will be see how to use compromise.js (formally nlp_compromise).
This package can be used both on the server side as well as the client side.
It can be used to do the following:
-Tokenization
-Parts of Speech tagging
-Pluralization and Singularization
-Entity Recognition
-Matching
-Word Transformation
-Noun chunks
Installation
npm install compromise
Server Side
var nlp = require(‘compromise’);
var docx = nlp(“This is a cool library.”);
// Output in the most generic form
console.log(docx.data());
Client Side
You will need to add the scripts in your html file to start using it.
https://unpkg.com/compromise@latest/builds/compromise.min.js
Then inside your scripts tag you can do your analysis.
var docx = nlp(“Jack Ryan is a CIA Analyst in New York”);
// console.log(docx.data());
Sentences
console.log(docx.sentences().data());
Tokenization
console.log(docx.sentences().terms().out(‘array’));
Parts of Speech Tagging + Entities
console.log(docx.sentences().terms().out(‘tags’));
Entity Recognition (NER)
console.log(docx.topics().data());
Entity Recognition (NER) People
console.log(docx.topics().people().text());
console.log(docx.people().text());
Recognition of First name & Last name
console.log(docx.people().firstNames().text());
console.log(docx.people().lastNames().text());
Entity Recognition (NER) for Places
console.log(docx.places().text());
console.log(docx.topics().places().text());
Entity Recognition (NER) For Organization
console.log(docx.topics().organizations().text());
Working with Noun Chunks & Verbs
console.log(docx.nouns().text());
console.log(docx.verbs().data());
Word Transformation
var docx2 = nlp(“book”);
console.log(docx2.nouns().toLowerCase().text());
console.log(docx2.nouns().toUpperCase().text());
You can get the complete code here or you can check the video tutorial on youtube
Thank You
Jesus Saves @JCharisTech