Applying Sentiment Analysis on User Feedback with Java

Applying Sentiment Analysis on User Feedback with Java

Sentiment analysis is an emerging Artificial Intelligence (AI) technique that combines natural language processing algorithms to analyze emotions connected with textual information. With a diversified audience, it is essential for businesses to...

Sentiment analysis is an emerging Artificial Intelligence (AI) technique that combines natural language processing algorithms to analyze emotions connected with textual information. With a diversified audience, it is essential for businesses to capitalize on AI development services that synthesize data from digital channels to extract actionable insights. Customer interactions across digital channels can be channelized using sentiment analysis to strengthen chatbot development services for global businesses.

Let’s explore how we can apply sentiment analysis to gauge the emotional relevance of feedback using IBM Watson.

Sentiment Analysis Of Manager’s Feedback
Sentiment analysis Of Manager’s Feedback. Through this document, we can understand how we can do the sentiment analysis of the real data which become very beneficial in today’s market.

The application does the sentiment analysis of the Manager’s Feedback. The application consists of the following main components:

Text Classifier – Datumbox.
MySQL WorkBench DataBase.
IBM Watson API.
Neuroph – v 2.92.
The main purpose of the task is to do the sentiment analysis of the text and the feedback of the manager’s comments and their feedback. These days there is a need to understand the reviews or any comments that are done on our work or on any product/service as it’s important to get the idea what our users/customers/peers are trying to say. Based on the result of Sentiment Analysis, We can make our business decisions accordingly.

In this use case, we’re just scanning the comments provided by Managers for their respective projects and trying to understand if the project is moving towards the direction expected by the Company or against it.

Scope
If we discuss the scope of this Application-

We can take it in use of Analysis of any speech or any text value.
We can use it for better production and make our work or product according to the reviewers.
We can get the maximum profit according to the sentiment analysis of the reviews and get the best result.
System Components
IBM Watson-7.1.1

The IBM Watson Assistant service combines natural language understanding and machine learning to create conversation flows between your app and your users.

The Assistant v2 API provides run time methods, the client application can use to send user input to an assistant and receive a response.

DatumBox-0.8.1

The Datumbox API is a web service that allows us to use our Machine Learning platform from our website, software or mobile application. The API gives you access to all of the supported functions of our service. It is designed to be easy to use and you can implement it in any model computer language that allows you to generating web requests.

Sentiment Analysis using IBM Watson
Analyzes the general sentiment of our content or sentiment toward specific target phrases. We can analyze sentiment for detected entities with entities.sentiment and for keywords with keywords.sentiment .

Code In Java

IamAuthenticator authenticator = new IamAuthenticator(“{apikey}”);

NaturalLanguageUnderstanding naturalLanguageUnderstanding = new NaturalLanguageUnderstanding(“2019-07-12”, authenticator);

naturalLanguageUnderstanding.setServiceUrl(“{url}”);

String url = “www.wsj.com/news/markets”;

List targets = new ArrayList<>();

targets.add(“stocks”);

SentimentOptions sentiment = new SentimentOptions.Builder()

.targets(targets)

.build();

Features features = new Features.Builder()

.sentiment(sentiment)

.build();

AnalyzeOptions parameters = new AnalyzeOptions.Builder()

.url(url)

.features(features)

.build();

AnalysisResults response = naturalLanguageUnderstanding

.analyze(parameters)

.execute()

.getResult();

System.out.println(response);

Response

{

“usage”: {

“text_units”: 1,

“text_characters”: 1188,

“features”: 1

},

“sentiment”: {

“targets”: [

  {

    “text”: “stocks”,

    “score”: 0.279964,

    “label”: “positive”

  }

],

“document”: {

  “score”: 0.127034,

  “label”: “positive”

}

},

“retrieved_url”: “https://www.wsj.com/news/markets”,

“language”: “en”

}

Limitations
There are some limitations to this Application.

For more accuracy, there is a need to train the machine by our own data set.
If the data is not available in the data set then it will show the wrong result for that case we have to give data dynamically.

Sentiment Analysis with Machine Learning

Sentiment Analysis with Machine Learning

What Is Sentiment Analysis? It is the process of determining if a piece of writing is positive, negative or neutral. This system for text analysis combines natural language processing and machine learning techniques to assign weighted sentiment...

What Is Sentiment Analysis?
It is the process of determining if a piece of writing is positive, negative or neutral. This system for text analysis combines natural language processing and machine learning techniques to assign weighted sentiment scores to the entities, topics, themes, and categories within a sentence or phrase. Sentiment analysis and artificial intelligence services enable data analysts to analyze public opinions, conduct in-depth market research, evaluate brand reputation, and enhance customer experiences. Moreover, businesses may integrate third-party sentiment analysis APIs into their database management systems for different platforms to extract customer insights.

How does sentiment analysis work?
Text documents follows the following process:

First of all Break each text document down into its component parts (sentences, phrases, tokens, and parts of speech).
Identify each sentiment-bearing phrase and component.
Then Assign a sentiment score to each phrase and component (-1 to +1).
Optional: Combine scores for multi-layered sentiment analysis.
Sentiment Analysis Algorithms
There can be many methods and algorithms to implement this systems, which can be classified as:

Automatic systems that work on machine learning techniques to learn from data.
Hybrid systems combine both rule-based and automatic approaches.
Rule-based systems perform sentiment analysis based on a set of manually crafted rules.
Sentiment Analysis Use Cases & Applications
Sentiment Analysis in Social Media Monitoring
In today’s day and age, brands of all shapes and sizes have meaningful interactions with customers, leads, and even competition on social networks like Facebook, Twitter, and Instagram. Most marketing departments are already tuned into online mentions as far as volume –they measure more chatter as more brand awareness. Nowadays, however, we can take a step deeper. By sentiment analysis on social media, we can get incredible insights into the quality of conversation that’s happening around a brand.

Analyze tweets and/or Facebook posts over a period of time to see sentiment a particular audience.
Run this analysis on all social media mentions to your brand and automatically categorize it by urgency.
Automatically route social media mentions to team members best fit to respond.
Automate any or all of these processes.
Use analytics to gain deep insight into what’s happening across on social media channels.
Sentiment Analysis in Brand Monitoring
Not only do brands have a wealth of information available on social media, but they also can look more broadly across the internet to see how people are talking about them online. Instead of focusing on specific social media platforms such as Facebook and Twitter, we can target mentions in places like news, blogs, and forums –again, looking at not just the volume of mentions, but also the quality of those mentions.

How Sentiment Analysis Can Be Used
Analyze news articles, blog posts, forum discussions, and other texts on the internet over a period of time to see the sentiment of a particular audience.
Automatically categorize the urgency of all online mentions to your brand via sentiment analysis.
Automatically alert designated team members of online mentions that concern their area of work.
Automate any or all of these processes.
Better understand a brand’s online presence by getting all kinds of interesting insights and analytics.
Sentiment Analysis in Customer Feedback
Social media & brand monitoring offer us immediate, unfiltered, invaluable information on customer sentiment. In parallel vein run two other troves of insight –surveys and customer support interactions. Teams often look at their Net Promoter Score (NPS), but we can also apply these analyses to any type of survey or communication channel that yields textual customer feedback.

In numerical survey data it is easily aggregated and assessed, but we want that same ease with the “why” answers as well. Regular NPS score simply gives a number, without the additional context of what it’s about and why the score landed there. However, AI-powered sentiment analysis provides an automated description of the text including the “what” and “why”.

Analyze aggregated NPS or other survey responses.
Analyze aggregated customer support interactions.
Track customer sentiment about specific aspects of the business over time. It adds depth to explain why the overall NPS score might have changed, or if specific aspects have shifted independently.
Target individuals to improve their service. By automating this analysis on incoming surveys, we can be alerted to customers who feel strongly negatively towards our product or service and can deal with them specifically.
If particular customer segments feel more strongly about our company. we can zero in on sentiment by certain demographics, interests, personas, etc.
Sentiment Analysis in Customer Support
We all know that stellar customer experiences = more probable returning customers. Particularly in recent years, there’s been a lot of talk (rightfully so) around customer experience and customer journeys. Leading companies have begun to realize that oftentimes how they deliver is just as (if not more) important as what they deliver. For these days, more than ever, customers expect their experience with companies to be immediate, intuitive, personal, and hassle-free. In fact, research shows that will switch to a competitor after just one negative interaction.

Sentiment Analysis Python | Twitter Sentiment Analysis Python | Intellipaat - YouTube

Sentiment Analysis Python | Twitter Sentiment Analysis Python | Intellipaat - YouTube

If you want to learn Python to become a Python programming expert then this Intellipaat Python tutorial for beginner will be your first step for you to learn Python. Since this Python tutorial and examples video can be taken by anybody, so if you are a computer programmer then you can also watch this Python tutorial to take your coding skills to the next level.

You can learn Python much faster than any other programming language and this Python tutorial helps you do just that. Python programming is one of the best languages that is finding increased applications for machine learning. Our Python tutorial has been created with extensive inputs from the industry so that you can learn Python Programming and apply it for real world scenarios like machine learning and data science.

Sentiment Analysis with Node.js

Sentiment Analysis with Node.js

In this tutorial, we’ll be exploring what sentiment analysis is, why it’s useful, and building a simple program in Node.js that analyzes the sentiment of Reddit comments.

In this tutorial, we’ll be exploring what sentiment analysis is, why it’s useful, and building a simple program in Node.js that analyzes the sentiment of Reddit comments.


What it is

Sentiment analysis is the process of extracting key phrases and words from text to understand the author’s attitude and emotions. So, why is it useful? Companies can use it to make more informed marketing decisions. For example, they can analyze product reviews, feedback, and social media to track their reputation. Additionally, social networks can use sentiment analysis to weed out poor quality content.


How it works

There are two main approaches to sentiment detection: knowledge-based and statistical.

Knowledge-based approaches usually compare words in text to a defined list of negative and postive words. Finn Årup Nielsen from The University of Denmark published AFINN, a list of postive and negatives words, and a magnitude score of each on a scale between -5 and 5. For example, “gloom” has a score of -1, while “awful” has a score of -3. The score of all known words are added up to determine the overall sentiment of the text.

Statistical approaches make use of machine learning by analyzing known sentiments, and determining the unknown based on the knowns. For example, Amazon could create a machine learning model that analyzes the text and the 1 through 5 star rating of each product review. Then, they would be able to make an assumption about the star rating of a new review that doesn’t have a star rating yet.

With any approach, a score is typically given to each body of text that is analyzed. A negative score implies the text has a mostly negative attitude, and a positive score implies the text has a mostly positive attitude.


Potential problems

There can be some challenges in analyzing text. Because of this, sentiment analysis will never be completely accurate. Here’s a brief list of potential scenarios that can be tricky to analyze:

  • Double negatives: “I do not dislike running”
  • Inverted double negatives: “Not going to practice isn’t really my thing”
  • Adverb modifying adjective: “I really hate when people cut me off”
  • Possible sarcasm: “I love running with a knee injury”
  • Slang terms: “He ran a sick race!”

Our project

We’ll be making a Node.js app that calculates the sentiment of comments from a Reddit post asking how peoples’ days are going, and then displays the results in a webpage.

We’re going to be creating a Node.js app, so make sure you have it installed. Then:

  • Create an empty folder
  • cd into that directory (with cd ~/Desktop/folder for example)
  • run npm init to go through the creation wizard
  • Install the depenencies we need from npm by running npm install express ml-sentiment
  • Download the comments.json file and put it into the folder you created

File structure

Now that our dependencies are installed, let’s create and open a server.js file in the folder you created.

var express = require("express");
var app = express();

var ml = require("ml-sentiment")();
var redditComments = require("./comments.json");

const listener = app.listen(3000, function() {
console.log("Your app is listening on port " + listener.address().port);
});

What does this file do right now? The first block sets up Express, a web server library. The second block tells the program to import our sentiment analysis library, and the JSON data file of the Reddit comments. The last block starts our server and tells us which port it is listening on. There is nothing for the server to show though, because we haven’t defined any “routes” for Express to use yet.

The Node library we’re using for sentiment analysis, ml-sentiment, has documentation that tells us how we can use it:

var ml = require("ml-sentiment");
ml.classify("Rainy day but still in a good mood");
// returns 2 ... (overall positive sentiment)

This library uses AFINN-111, which has the ratings of 2477 words and phrases. The library simply looks at the words in the parameter of the .classify function, and compares each to AFINN-111. If a word like “not” or “don’t” precedes the word, it uses the absolute value of the score. For example, “anxious” has a score of -2, while “not anxious” has a score of 2.

This is by no means a comprehensive library, but it’s quick to implement, runs fast and works reliably on simple examples.

Let’s create a function that loops through all of the Reddit comments, uses the ml.classify function to get a sentiment score, and saves that value into the redditComments array.

redditComments.forEach(function(comment) {
comment.sentiment = ml.classify(comment.body);
if (comment.sentiment >= 5) {
comment.emoji = "😃";
} else if (comment.sentiment > 0) {
comment.emoji = "🙂";
} else if (comment.sentiment == 0) {
comment.emoji = "😐";
} else {
comment.emoji = "😕";
}
});

Now, our redditComments variable is an array of objects with the link, body, author, emoji, and sentiment keys. For example, here’s how one object in the array looks:

  {
"link": "https://reddit.com/r/AskReddit/comments/6szu5h/reddit_how_was_your_day/dlgtei6/",
"body": "It was so nice day. it was my memorable day. ",
"author": "Gemma_Youl",
"sentiment": 3,
"emoji": "🙂"
} ...

Next, we’ll define two routes in Express that sends our redditComments data in a webpage. Routes have to be defined after app is defined, but before app.listen is called.

app.get("/", function(req, res) {
res.sendFile(__dirname + "/index.html");
});

app.get("/data", function(req, res) {
res.json(redditComments);
});

This first route says that when the / directory receives a GET request, Express should send the index.html file. The second route says that when the /data directory receives a GET request, Express should send a JSON response of the redditComments variable.

Here’s how the server.js file looks now:

var express = require("express");
var app = express();

var ml = require("ml-sentiment")();
var redditComments = require("./comments.json");

redditComments.forEach(function(comment) {
comment.sentiment = ml.classify(comment.body);
if (comment.sentiment >= 5) {
comment.emoji = "😃";
} else if (comment.sentiment > 0) {
comment.emoji = "🙂";
} else if (comment.sentiment == 0) {
comment.emoji = "😐";
} else {
comment.emoji = "😕";
}
});

app.get("/", function(req, res) {
res.sendFile(__dirname + "/index.html");
});

app.get("/data", function(req, res) {
res.json(redditComments);
});

const listener = app.listen(process.env.PORT, function() {
console.log("Your app is listening on port " + listener.address().port);
});

It doesn’t work just yet! We haven’t created the index.html file yet. Make a new file called index.html. Code this into the file:

<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.4/css/bulma.min.css" rel="stylesheet" />
<style>
#main {
margin: 2rem;
}

.big {
  font-size: 1.2rem;
}

</style>
</head>

<body>
<section class="hero is-success">
<div class="hero-body">
<div class="container">
<h1 class="title">How was your day?</h1>
<h2 class="subtitle">Sentiment analysis demo</h2>
</div>
</div>
</section>
<div id="main">
<table class="table is-fullwidth">
<thead>
<tr>
<th>Feeling</th>
<th>Score</th>
<th>Author</th>
<th>Comment</th>
</tr>
</thead>
<tbody id="sentimentTable">
</tbody>
</table>
</div>
<script>
var request = new XMLHttpRequest();
request.open('GET', '/data', true);

request.onload = function() {
  if (request.status &gt;= 200 &amp;&amp; request.status &lt; 400) {
    var table = document.getElementById("sentimentTable")
    var data = JSON.parse(request.responseText);
    data.forEach(function(comment){
      var newRow = table.insertRow(table.rows.length);
      newRow.insertCell(0).innerHTML = comment.emoji
      newRow.insertCell(1).innerHTML = comment.sentiment
      var rowLink = document.createElement('a')
      rowLink.innerHTML = comment.author
      rowLink.href = comment.link
      newRow.insertCell(2).appendChild(rowLink)
      newRow.insertCell(3).innerHTML = comment.body
    })
  } else {
    alert("Could not retrieve data")
  }
};

request.onerror = function() {
  alert("Could not retrieve data")
};

request.send();

</script>
</body>

How does this work? In the HTML page, a script is defined that sends a web request to /data, and creates a new row in a table for each sentiment we analyzed.

Everything is good to go! To run your program, go back to the terminal and run node server.js. Make sure you are still in your project’s directory. Now, go to your browser and open localhost:3000. You should see our new webpage with the sentiment of each Reddit comment!

Notice how some comments have negations, like “not bad”, and the sentiment has a postive value. This is because the sentiment library we used has basic support for negation.

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow us on Facebook | Twitter

Learn More

The Complete Node.js Developer Course (3rd Edition)

Angular & NodeJS - The MEAN Stack Guide

NodeJS - The Complete Guide (incl. MVC, REST APIs, GraphQL)

Node.js: The Complete Guide to Build RESTful APIs (2018)

Learn and Understand NodeJS

MERN Stack Front To Back: Full Stack React, Redux & Node.js

Front-end Developer Handbook 2019

Best Practices For Using TypeScript with Node.js

Introducing Node.js 12

Creating a RESTful Web API with Node.js and Express.js from scratch

Node, Express, React.js, Graphql and MongoDB CRUD Web Application

Restful API with NodeJS, Express, PostgreSQL, Sequelize, Travis, Mocha, Coveralls and Code Climate

A Beginner’s Guide to npm — the Node Package Manager

Building REST API with Nodejs / MongoDB /Passport /JWT

Originally published on https://enlight.nyc