How to find all Pronouns in a String in Node.JS with NLP

In today’s tutorial, I’m going to be showing you how to apply NLP to the problem of filtering pronouns out of a string of text. While this may sound complicated or difficult, it’s actually going to be a breeze. This is because we have a special shortcut in the form of an API. Let me show you just how easy it is.

We start by running this command, which will have npm install set up our NLP client. Once this has finished, we can move on to calling the function we need.

npm install cloudmersive-nlp-api-client --save

We will be using wordsPronouns, implemented with this code here:

var CloudmersiveNlpApiClient = require('cloudmersive-nlp-api-client');var defaultClient = CloudmersiveNlpApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveNlpApiClient.WordsApi();var input = "input_example"; // String | Input stringvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.wordsPronouns(input, callback);

And that’s really all there is to it. How about we test it out really quick? Here are some sample results for this text from Moby Dick:

“Call me Ishmael. Some years ago — never mind how long precisely — having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation.”

{
"TaggedSentences": [
{
"Words": [
{
"Word": "me",
"Tag": "PRP"
}
]
},
{
"Words": [
{
"Word": "my",
"Tag": "PRP$"
},
{
"Word": "me",
"Tag": "PRP"
},
{
"Word": "I",
"Tag": "PRP"
},
{
"Word": "I",
"Tag": "PRP"
}
]
},
{
"Words": [
{
"Word": "It",
"Tag": "PRP"
},
{
"Word": "I",
"Tag": "PRP"
}
]
}
]
}
Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store