Sentiment Analysis for Oracle APEX using client side JavaScript
- Get link
- X
- Other Apps
If you have an interactive grid with any sort of review text a nice value add for the reviews is the addition of sentiment analysis. This post will show you how to add a sentiment column of positive, negative or neutral and a score to your interactive grid using a couple of lines of code.
Demo app
This post is a quick front end value add of sentiment analysis to your app using client side JavaScript. If this works for you I suggest using Oracle Text or some other sentiment analysis tool to do the sentiment analysis on the database rather than the front end as shown here.
We are using a client side JavaScript library compendium to do the sentiment analysis. First download compendium.js from here and upload it to static application files in your APEX app. Get the reference to the JS file, in my case #APP_IMAGES#compendium.js
Create a new page and include the JavaScript library.Create a new IG region with the static ID ANSWERS_IG. Sample SQL for your interactive grid with 2 placeholder columns for the sentiment analysis, SENTIMENT to hold the text, positive, negative or neutral and SENTIMENT_VALUE to hold the score.
We will use JQuery to populate the sentiment columns, so give the columns PRODUCT_REVIEW, SENTIMENT and SENTIMENT_VALUE the same class names so JQuery can access the column text. An example is the PRODUCT_REVIEW column.
Add the following JS to execute when page loads.
The JQuery code loops round all the rows in your IG. The analysis happens on this line where the text is passed to the JS code for analysis
var sentiment = compendium.analyse(responseCell.text())[0];
We are interested in the returned sentiment profile which you can view here,
Lastly I have added some styling to the sentiment which you can change to suit.
For example I want positive sentiment to show green with a larger font size.
$(item).find('.SENTIMENT').html('<p style="color:green;font-size: 125%"">'+sentiment.profile.label+'</p>');
- Get link
- X
- Other Apps
Comments
Post a Comment