Performing Real-Time Sentiment Analysis in Oracle BI 12c

"Embedded R" is one of the great new features of Oracle BI 12c and this article will show how it can be used to perform real-time sentiment analysis within your BI dashboards....completely open source! 

In this example, the sentiment analysis function will classify sentences or paragraphs of text as either "negative", "neutral" or "positive" in sentiment:

This capability demonstrates the versatility and value behind the new R integration feature, since we would normally have to turn to other products such as Oracle Endeca or Oracle Big Data Discovery (BDD) to perform sentiment analysis.

In this case, we are using the open source "tm.plugin.sentiment" R package to perform the sentiment analysis function.   Other packages are available.

Here are the required steps:

1) Install Oracle BI 12c and then enable the Embedded R feature

2) Install the additional R packages to perform sentiment analysis

    R    (command line executable)

    install.packages("tm")
    download.file("http://cran.cnr.berkeley.edu/src/contrib/Archive/Rstem/Rstem_0.4-1.tar.gz", "Rstem_0.4-1.tar.gz")

    install.packages("Rstem_0.4-1.tar.gz", repos=NULL, type="source")

    download.file("http://cran.r-project.org/src/contrib/Archive/sentiment/sentiment_0.2.tar.gz", "sentiment.tar.gz")

    install.packages("sentiment.tar.gz", repos=NULL, type="source")

3) Deploy file peak.Sentiment.xml

At the bottom of this article you can find a link to download the "peak.Sentiment.xml" file.   This is a custom R script we have developed that will invoke the tm.plugin.sentiment package and score your text as positive/negative/neutral.

Download this file and then copy it to the following "script_repository" location on your OBIEE server:

[Home]/user_projects/domains/bi/bidata/components/OBIS/advanced_analytics/script_repository

4) Create your Analysis within Oracle BI

For the R script to work, you simply need an analysis with a minimum of 2 columns:

    - A column that uniquely identifies the records

    - The text on which to perform sentiment analysis

5) Add your Sentiment Analysis calculation

Add a new column to your analysis with the following formula:

EVALUATE_SCRIPT('filerepo://peak.Sentiment.xml', 'sentiment', 'id=%1;text=%2', [ID Column], [Text Column])

You need to replace the parts in square brackets with the two corresponding columns from your analysis (you can supply expressions such as CASE..WHEN and also string literals instead of column names).    For example:

EVALUATE_SCRIPT('filerepo://peak.Sentiment.xml', 'sentiment', 'id=%1;text=%2', "Products"."Product Number", "Products"."Feedback"

6) That's It!

If you run your analysis you can see the sentiment analysis now being performed: 

NOTE: Sentiment Analysis is never 100% perfect, you can customise the R package to improve accuracy, or consider alternative packages

7) Summarise your Analysis

You may like to summarise your analysis by bringing in additional attributes.   In the example below we have summarised by Product Brand and presented the results on a 100% stacked bar graph.   You can of course configure a navigation to enable the user drill-down on the graph to see the underlying comments:


Subscribe to our Newsletter

If you enjoyed this article why not get great insights straight to your inbox

Comments (2)
Venkat 9 months ago

Thank you for excellent post. I'm not able to install R package that mentioned. Could you please help me on the elaborating the second step?

Peak Indicators 9 months ago

Hi Venkat, Thank you for taking the time to look through the blog. In order for the installation to work, with the commands we outlined in part 2, it is important to note the following: In order to use the first command 'R', the R.exe file path must be added to the 'Path' environment variable. To do this open 'Control Panel\System and Security\System' and click 'Advanced system settings', from the pop-up window click 'Environment Variables', select 'Path' and click 'Edit'. You will then be presented with another pop-up, click 'New' and enter the path to your R.exe file. Secondly, if you are presented with an error similar to "'make' not found" simply download Rtools from the following link https://cran.r-project.org/bin/windows/Rtools/ I hope this helps you, but if you have any further questions please feel free to get in touch.