How to Detect Subjectivity in Text using Node.JS

For platforms that receive widespread input such as forums and question sites like Stack Overflow, checking for subjectivity in text allows your programs to maintain a high level of factual response. For example, if a user asks a question on any topic, they are looking to receive the most succinct and useful answer. By scanning input text for subjectivity, you can cut down on lists of opinionated responses that do not help the question-asker with their issue. The following API will analyze input text using advances subjectivity and objectivity language analysis to determine if a string is factually or opinion based.

Image for post
Image for post

To start our API, we first need to run this command to install the SDK:

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

Or, you can also add this snippet to your package.json:

"dependencies": {
"cloudmersive-nlp-api-client": "^2.0.9"
}

Then, we can call our function:

var CloudmersiveNlpApiClient = require('cloudmersive-nlp-api-client');
var defaultClient = CloudmersiveNlpApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveNlpApiClient.AnalyticsApi();var input = new CloudmersiveNlpApiClient.SubjectivityAnalysisRequest(); // SubjectivityAnalysisRequest | Input subjectivity analysis requestvar callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.analyticsSubjectivity(input, callback);

Once you have completed these steps, you can be confident in your program’s ability to parse, detect, and compare the subjectivity or objectivity of any text string.

You can retrieve the API Key from Cloudmersive at no cost and with no commitment. This gives you access to 800 monthly calls across our API library.

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