{"id":92300,"date":"2021-08-30T18:20:50","date_gmt":"2021-08-30T18:20:50","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=92300"},"modified":"2022-04-24T21:17:22","modified_gmt":"2022-04-24T21:17:22","slug":"sentiment-analysis-oracle-text","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/bi-sql-server\/sentiment-analysis-oracle-text\/","title":{"rendered":"Text Mining and Sentiment Analysis: Oracle Text"},"content":{"rendered":"<p><strong>The series so far:<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/text-mining-and-sentiment-analysis-introduction\/\">Text Mining and Sentiment Analysis: Introduction<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/text-mining-and-sentiment-analysis-power-bi-visualizations\">Text Mining and Sentiment Analysis: Power BI Visualizations<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/text-mining-and-sentiment-analysis-with-r\/\">Text Mining and Sentiment Analysis: Analysis with R<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/sql\/bi\/sentiment-analysis-oracle-text\/\">Text Mining and Sentiment Analysis: Oracle Text<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/databases\/sql-server\/bi-sql-server\/text-mining-and-sentiment-analysis-data-visualization-in-tableau\/\">Text Mining and Sentiment Analysis:\u00a0Data Visualization in Tableau<\/a><\/li>\n<li><a href=\"https:\/\/www.red-gate.com\/simple-talk\/development\/data-science-development\/sentiment-analysis-python\/\">Sentiment Analysis with Python<\/a><\/li>\n<\/ol>\n\n<p>The fourth article of the series will focus on leveraging <em>Oracle<\/em>\u00a0<em>Text<\/em> features in Oracle Database to perform sentiment analysis.<\/p>\n<p>The first three articles of this series covered Sentiment Analysis using tools and services in the Microsoft ecosystem: Azure cognitive services and Power BI. This article will explore the Text features in an Oracle Database to perform Sentiment Analysis. The approach demonstrated in this article is useful in environments where the Oracle platform, tools, and technologies are predominantly used. Several organizations have not fully embraced the use of the public cloud for various reasons. This approach is suitable when using the public cloud may not be feasible in your organization.<\/p>\n<p>Oracle Text feature has been available since Oracle Database release 12c. It provides indexing, word and theme searching, sentiment analysis, and document classification capabilities. According to <a href=\"https:\/\/www.oracle.com\/database\/technologies\/enterprise-edition.html\">Oracle documentation<\/a> \u201cOracle Text can perform linguistic analysis on documents, as well as search text using a variety of strategies including keyword searching, context queries, Boolean operations, pattern matching, mixed thematic queries, HTML\/XML section searching, and so on. It can render search results in various formats including unformatted text, HTML with term highlighting, and original document format. Oracle Text supports multiple languages and uses advanced relevance-ranking technology to improve search quality. Oracle Text also offers advanced features like classification, clustering, and support for information visualization metaphors\u201d.<\/p>\n<p>This article will focus on performing sentiment analysis using Oracle Text.<a href=\"https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/19\/ccapp\/performing-sentiment-analysis-using-oracle-text.html#GUID-12014209-8E70-49A8-BD75-86A9C4D401F6\"> Oracle Application Developer\u2019s guide<\/a> describes this as \u201cOracle Text enables you to perform sentiment analysis for a topic or document by using sentiment classifiers that are trained to identify sentiment metadata. Sentiment analysis is the process of identifying and extracting sentiment metadata about a specified topic or entity from a set of documents. Trained sentiment classifiers identify the sentiment. When you run a query with sentiment analysis, in addition to the search results, sentiment metadata (positive or negative sentiment) is also identified and displayed\u201d.<\/p>\n<p>In Oracle Text, a sentiment classifier is a specific type of document classifier that is used to extract sentiment metadata. Oracle text provides a default sentiment classifier (unsupervised). If you have suitable training data, Oracle Text also gives you the ability to train your own sentiment classifiers.<\/p>\n<p>Please note that this article uses the <em>Oracle Database Application Development<\/em> virtual machine, running on a windows host for the demo.<\/p>\n<h2>Initial setup<\/h2>\n<ol>\n<li>Download and install VirtualBox by following instructions listed on <a href=\"https:\/\/www.virtualbox.org\/wiki\/Downloads\">VirtualBox website<\/a>.<\/li>\n<li>Download and set up <em>Oracle Database Virtual Box Appliance \/ Virtual Machine<\/em> by following instructions listed on the <a href=\"https:\/\/www.oracle.com\/database\/technologies\/databaseappdev-vm.html\">Oracle website<\/a>.<\/li>\n<li>Start up the Virtual Machine and ensure <em>SQL Developer<\/em> is available on the desktop screen. Please note that you may need to create a free account to download the Virtual Machine.<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1163\" height=\"933\" class=\"wp-image-92301\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu.png\" alt=\"Oracle DB Developer VM [Running] - Oracle VM VirtualBox\" \/><\/p>\n<p><strong>Figure 1. Oracle Database Developer Virtual Machine<\/strong><\/p>\n<ol start=\"4\">\n<li>This article uses the same Excel file raw data from previous articles, available on my <a href=\"https:\/\/github.com\/SQLSuperGuru\/SimpleTalkDemo_R\/blob\/master\/Oracle\/TeamHealthRawDataForDemo.xlsx\">GitHub repository<\/a>. Please download and save this file at a convenient location on your Virtual Machine<\/li>\n<\/ol>\n<h3>Set up an Oracle Text User<\/h3>\n<p>Set up a user with the CTXAPP role, enabling you to work with Oracle Text indexes and use Oracle Text PL\/SQL packages.<\/p>\n<ol>\n<li>On the Virtual Machine, launch the <em>Oracle SQL Developer<\/em> application. Under the Connections menu, click on <em>system &gt;.<\/em> When prompted for credentials, enter <em>sys as sysdba<\/em> in the username field and <em>oracle<\/em> in the password field.<\/li>\n<li>When a new worksheet opens, run this query <code>select * from v$database ;<\/code>. From the query result, verify the value under the <em>NAME<\/em> column is <em>ORCLDB<\/em>. You may also run the query <code>select user from dual<\/code> to verify the username of the current connection. It is important to verify this, as the subsequent steps for setting up the Oracle Text user need to be performed as the system administrator. The screenshot below unions the two queries for simplicity of display.<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1162\" height=\"933\" class=\"wp-image-92302\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-1.png\" alt=\"Oracle DB Developer VM [Running] - Oracle VM VirtualBox\" \/><\/p>\n<p><strong>Figure 2. Use Oracle SQL Developer to connect to ORCLDB database as \u201cSYS\u201d user<\/strong><\/p>\n<ol start=\"3\">\n<li>Run the following SQL statement to create user <em>redgatedemo<\/em>.<\/li>\n<\/ol>\n<pre class=\"lang:tsql theme:ssms2012-simple-talk\">CREATE USER redgatedemo IDENTIFIED BY mydemopassword;<\/pre>\n<p>Upon successful execution, you should see the message <em>User REDGATEDEMO created<\/em>.<\/p>\n<ol start=\"4\">\n<li>Run the following SQL statements to grant user <em>redgatedemo<\/em> the roles necessary for connecting and using database and CTXAPP resources. The CTXAPP role includes execute privileges on various CTX PL\/SQL packages.<\/li>\n<\/ol>\n<pre class=\"lang:tsql theme:ssms2012-simple-talk\">GRANT RESOURCE, CONNECT, CTXAPP TO redgatedemo;\r\nGRANT UNLIMITED TABLESPACE TO redgatedemo;<\/pre>\n<p>Upon successful execution, you should see the message <em>Grant<\/em> <em>succeeded<\/em>.<\/p>\n<h3>Import raw data file in Oracle Table<\/h3>\n<p>Click the green plus sign under <em>Connections<\/em> to open the <em>New \/ Select Database Connection<\/em> dialog. Connect to the Oracle Database with user <em>redgatedemo<\/em> as shown in Figure 3.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1162\" height=\"933\" class=\"wp-image-92303\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-2.png\" alt=\"Oracle DB Developer VM [Running] - Oracle VM VirtualBox\" \/><\/p>\n<p><strong>Figure 3. Connect to Oracle database with redgatedemo user<\/strong><\/p>\n<ol>\n<li>Run the following SQL to create a table, with a unique index and primary key.<\/li>\n<\/ol>\n<pre class=\"theme:ssms2012-simple-talk lang:tsql decode:true\">-- Create a Table to load text data\r\nCREATE TABLE REDGATEDEMO.DEMO_SENTIMENTANALYSIS_TEAMHEALTH\r\n(\r\n    ID                     NUMBER GENERATED ALWAYS AS IDENTITY\r\n   ,PERIOD                 VARCHAR2( 500 ) NOT NULL\r\n   ,MANAGER                VARCHAR2( 500 ) NOT NULL\r\n   ,TEAM                   VARCHAR2( 500 ) NOT NULL\r\n-- this will store raw text of survey response\r\n   ,RESPONSE               VARCHAR2( 4000 ) NOT NULL \r\n   ,DW_CREATION_DATE       DATE DEFAULT SYSDATE\r\n);\r\n\r\n-- create a unique index\r\nCREATE UNIQUE INDEX REDGATEDEMO.DEMO_SENTIANALYSIS_TEAMHEALTH_PK\r\n    ON REDGATEDEMO.DEMO_SENTIMENTANALYSIS_TEAMHEALTH(ID )\r\n    ONLINE;\r\n\r\n-- create a primary key\r\nALTER TABLE REDGATEDEMO.DEMO_SENTIMENTANALYSIS_TEAMHEALTH\r\n    ADD CONSTRAINT DEMO_SENTIANALYSIS_TEAMHEALTH_PK PRIMARY KEY\r\n    (ID )\r\nUSING INDEX REDGATEDEMO.DEMO_SENTIANALYSIS_TEAMHEALTH_PK ENABLE VALIDATE;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-92304\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-3.png\" alt=\"Image showing create table statement\" width=\"1546\" height=\"1024\" \/><\/p>\n<p><strong>Figure 4. Create table to load text data<\/strong><\/p>\n<ol start=\"2\">\n<li>If you haven\u2019t already, download the Excel file from the <a href=\"https:\/\/github.com\/SQLSuperGuru\/SentimentAnalysis\/blob\/main\/TeamHealthRawDataForDemo.xlsx\">Github repo<\/a> and save it to a convenient location on the Virtual Machine<\/li>\n<li>In Oracle SQL Developer, under the left side connection menu, navigate to <em>Oracle Connections &gt; redgatedemo &gt; Tables &gt; DEMO_SENTIMENTANALYSIS_TEAMHEALTH<\/em>. Right click on this table and select <em>Import<\/em> <em>Data<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-92305\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-4.png\" alt=\"Oracle DB Developer VM [Running] - Oracle VM VirtualBox Import data\" width=\"1272\" height=\"1010\" \/><\/p>\n<p><strong>Figure 5. Launch the Data Import Wizard<\/strong><\/p>\n<ol start=\"4\">\n<li>This will launch <em>Data Import Wizard<\/em>. Use this easy-to-follow five-step wizard to load the previously downloaded Excel file into the Oracle database table &#8211; <em>REDGATEDEMO.DEMO_SENTIANALYSIS_TEAMHEALTH<\/em><\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-92306\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-5.png\" alt=\"Data Import Wizard\" width=\"1272\" height=\"1010\" \/><\/p>\n<p><strong>Figure 6. Step 1 of the Data Import Wizard<\/strong><\/p>\n<p>Please note Step 3 of the <em>Data<\/em> <em>Import<\/em> <em>Wizard<\/em> is <em>Choose<\/em> <em>columns<\/em>. Please ensure you have selected only the four columns <em>Period<\/em>, <em>Manager<\/em>, <em>Team<\/em>, and <em>Response<\/em> to import. Sometimes you may see a long list of empty excel columns with headings like <em>column5<\/em>, <em>column6<\/em>, etc. under the <em>Available<\/em> <em>columns<\/em> section of the wizard, which should not be imported.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-92307\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-6.png\" alt=\"Data import wizard choose columns\" width=\"1546\" height=\"1024\" \/><\/p>\n<p><strong>Figure 7. Step 3 of the Data Import Wizard (select columns to import)<\/strong><\/p>\n<p>The wizard will display a success message upon completion<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-92308\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-7.png\" alt=\"Import complete\" width=\"1429\" height=\"764\" \/><\/p>\n<p><strong>Figure 8. Data Import wizard completed successfully<\/strong><\/p>\n<h2>Sentiment Classifier in Oracle text<\/h2>\n<p>In Oracle Text, a sentiment classifier is a specific type of document classifier that can extract sentiment metadata from a document. To use a sentiment classifier, it is first associated with a sentiment classifier preference, then trained.<\/p>\n<p><a href=\"https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/18\/ccapp\/performing-sentiment-analysis-using-oracle-text.html#GUID-BFCAB1FF-C8A1-4B1F-A2DD-ADD202306A65\">Oracle documentation<\/a> describes a sentiment classifier preference as \u201cIt specifies the parameters that are used to train a sentiment classifier. These parameters are defined as attributes of the sentiment classifier preference. You can either create a sentiment classifier preference or use the default\u201d. The default sentiment classifier is <code>CTXSYS.DEFAULT_SENTIMENT_CLASSIFIER<\/code>. The <code>CTX_DDL.CREATE_PREFERENCE<\/code>\u00a0procedure is used to create a user-defined sentiment classifier preference and the\u00a0<code>CTX_DDL.SET_ATTRIBUTE<\/code>\u00a0procedure is used to specify its parameters.<\/p>\n<p>Oracle Text provides a default sentiment classifier, a pre-trained out-of-the-box model that works well for most general-purpose sentiment analysis applications. It leverages an <a href=\"https:\/\/docs.oracle.com\/cd\/E18283_01\/text.112\/e16593\/cdatadic.htm#BHCGJHDH\"><code>AUTO_LEXER<\/code><\/a> that performs language identification, word segmentation, document analysis, part-of-speech tagging, and stemming. In the world of text processing and analysis, a lexer reads an input text and breaks it down into tokens using language-specific grammar rules. The lexer generates a stream of tokens as output. Oracle\u2019s <code>AUTO_LEXER<\/code> supports several languages and is most commonly used due to its ability to detect the language automatically. The default sentiment classifier is ideal for use in scenarios where a labeled training dataset is not available, and your sentiment classification needs are general purpose in nature (for example, social media posts, Google and Yelp reviews, etc.)<\/p>\n<p>Oracle Text also provides the ability to create your own user-defined sentiment classifiers. To train your own sentiment classifier, a user needs an associated sentiment classifier preference, a training set of documents, and the target sentiment categories. The <code>CTX_CLS.SA_TRAIN<\/code>\u00a0procedure is used to train a sentiment classifier. During training, a user assigns each sample document to a category, which Oracle Text uses to infer rules for how to perform sentiment analysis. This technique is an example of supervised machine learning and relies on suitable training data. You may need to train your own sentiment classifier if the default classifier does not meet the needs of your use-case (for example, complex text in a domain that needs deep subject matter understanding like medicine, international law, etc.). Training a user-defined sentiment classifier is out of scope for this article. To learn how to train your a user-defined sentiment classifier in Oracle Text, please follow this <a href=\"https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/18\/ccapp\/performing-sentiment-analysis-using-oracle-text.html#GUID-7F1B2D64-7F7F-436F-81D3-7C8D18E956BE\">link<\/a> to Oracle documentation.<\/p>\n<h2>Performing Sentiment Analysis using the default classifier<\/h2>\n<p>The <em>CTX_DOC PL\/SQL<\/em> package is a part of Oracle Text features and provides several functions and procedures for various document services, including <em>Sentiment<\/em>. The following steps demonstrate the use of the <em>CTX_DOC<\/em> package for performing sentiment analysis, using the unsupervised technique (with default sentiment classifier and sentiment classifier preference)<\/p>\n<ol>\n<li>Run the following SQL statement to create a sentiment classifier preference <em>demoautolexer<\/em> of type <em>AUTO_LEXER<\/em>. Oracle Text will default values for attributes that are not explicitly defined. Please note that the type <em>AUTO_LEXER<\/em> should be used only for the default classifier. When training a user-defined classifier, always use the type <em>SENTIMENT_CLASSIFIER<\/em>.<\/li>\n<\/ol>\n<pre class=\"lang:tsql theme:ssms2012-simple-talk\">exec ctx_ddl.create_preference('demoautolexer','AUTO_LEXER');<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-92309\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-8.png\" alt=\"Create auto-lexer\" width=\"1646\" height=\"1026\" \/><\/p>\n<p><strong>Figure 9. create a sentiment classifier preference of type AUTO_LEXER<\/strong><\/p>\n<ol start=\"2\">\n<li>Run the following SQL statement to create a context index on the document set (table with text data). The context parameters for this index specify the use of <code>AUTO_LEXER<\/code> and default <code>stoplist<\/code>. A <em>stoplist<\/em> refers to the list of most common words in a particular language, which are usually removed before processing natural language data. This step may take a few minutes to complete.<\/li>\n<\/ol>\n<pre class=\"lang:tsql theme:ssms2012-simple-talk \">create index DEMO_SENTIMENTANALYSIS_TEAMHEALTH_TXTIDX \r\non DEMO_SENTIMENTANALYSIS_TEAMHEALTH(RESPONSE) indextype is\r\nctxsys.context parameters \r\n('lexer demoautolexer stoplist ctxsys.default_stoplist');<\/pre>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-92310\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-9.png\" alt=\"create index using auto-lexer\" width=\"1354\" height=\"883\" \/><\/p>\n<p><strong>Figure 10. Create text index<\/strong><\/p>\n<ol start=\"3\">\n<li>You can now use this text index in a select statement using the <code>SENTIMENT_AGGREGATE<\/code> method of the <em>CTX_DOC<\/em> package. This method takes a document id as input, which in this example is the <code>ID<\/code> field (the primary key of table <em>DEMO_SENTIMENTANALYSIS_TEAMHEALTH<\/em>).<\/li>\n<\/ol>\n<p><a href=\"https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/19\/ccapp\/performing-sentiment-analysis-using-oracle-text.html#GUID-B18361E3-7A3E-4AA7-B96E-80F99247986D\">Oracle documentation<\/a> describes the output of the<code>CTX_DOC.SENTIMENT_AGGREGATE<\/code>\u00a0procedure as \u201ca single consolidated sentiment score for the document. The sentiment score is a value in the range of -100 to 100, and it indicates the strength of the sentiment. A negative score represents a negative sentiment, and a positive score represents a positive sentiment. Based on the sentiment scores, you can group scores into labels such as Strongly Negative (\u201380 to \u2013100), Negative (\u201380 to \u201350), Neutral (-50 to +50), Positive (+50 to +80), and Strongly Positive (+80 to +100).\u201d<\/p>\n<p>Run the following SQL statement to see the sentiment scores <code>document id = 3<\/code> (Row with ID = 3):<\/p>\n<pre class=\"lang:tsql theme:ssms2012-simple-talk\">SELECT ctx_doc.sentiment_aggregate('DEMO_SENTIMENTANALYSIS_TEAMHEALTH_TXTIDX','3') from dual;<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-92311\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-10.png\" alt=\"Run package to see sentiment analysis on row 3\" width=\"1354\" height=\"883\" \/><\/p>\n<p><strong>Figure 11. Use ctx_doc.sentiment_aggregate to generate sentiment score for document id = 3<\/strong><\/p>\n<ol start=\"4\">\n<li>Run the following SQL statement to see the text as well as sentiment scores for document ids 3 and 4.<\/li>\n<\/ol>\n<pre class=\"lang:tsql theme:ssms2012-simple-talk\">SELECT TO_CHAR(ID) DOC_ID, RESPONSE FROM DEMO_SENTIMENTANALYSIS_TEAMHEALTH WHERE ID = 3\r\nUNION ALL\r\nselect 'Sentiment Score -&gt; ', TO_CHAR(ctx_doc.sentiment_aggregate('DEMO_SENTIMENTANALYSIS_TEAMHEALTH_TXTIDX','3')) from dual\r\nUNION ALL\r\nSELECT TO_CHAR(ID) DOC_ID, RESPONSE FROM DEMO_SENTIMENTANALYSIS_TEAMHEALTH WHERE ID = 4\r\nUNION ALL\r\nselect 'Sentiment Score -&gt; ', TO_CHAR(ctx_doc.sentiment_aggregate('DEMO_SENTIMENTANALYSIS_TEAMHEALTH_TXTIDX','4')) from dual<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-92312\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/oracle-db-developer-vm-running-oracle-vm-virtu-11.png\" alt=\"Run sentiment analysis on Rows 3 and 4\" width=\"1466\" height=\"1026\" \/><\/p>\n<p><strong>Figure 12. SQL statement to select text and its sentiment score<\/strong><\/p>\n<p>The results of this SQL statement can be interpreted as:<\/p>\n<ol>\n<li>The sentiment for document id 3 with the text \u201cwe work well as a team, we have fun together, I think we are very healthy\u201d is 31, which falls within the Neutral range of -50 to +50<\/li>\n<li>The sentiment for document id 4 with text \u201cI fell pretty good about the health of our team. My main concerns re a lack of vision into what our application&#8217;s true purpose is and the future direction of our team.\u201d is -28, which also falls in the within the Neutral range of -50 to +50 but is relatively more negative than the sentiment for document id 3. This is confirmed by human interpretation of the text.<\/li>\n<\/ol>\n<p>A developer would run such SQL statement per document (per row in the table) using a looping operation weand wrapping it in a user-defined PL\/SQL package.<\/p>\n<h2>Conclusion<\/h2>\n<p>This article demonstrated how to perform sentiment analysis with Oracle Text features available in an Oracle Database, using the default sentiment classifier that comes out of the box in Oracle. I highlighted the potential scenarios where the default sentiment classifier may not fulfill your needs, and you may have to train your own user-defined sentiment classifier. This article also helped readers get familiar with how to write a SQL statement to generate sentiment scores and interpret them to gain meaningful insights.<\/p>\n<h2>References:<\/h2>\n<ul>\n<li>Introduction to Oracle Database &#8211; <a href=\"https:\/\/docs.oracle.com\/cd\/B19306_01\/server.102\/b14220\/intro.htm\">https:\/\/docs.oracle.com\/cd\/B19306_01\/server.102\/b14220\/intro.htm<\/a><\/li>\n<li>What is Oracle Text \u2013<\/li>\n<\/ul>\n<p><a href=\"https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/18\/ccapp\/understanding-oracle-text-application-development.html#GUID-CF13C01A-F5E6-4EF5-839B-C09CF0024D5E\">https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/18\/ccapp\/understanding-oracle-text-application-development.html#GUID-CF13C01A-F5E6-4EF5-839B-C09CF0024D5E<\/a><\/p>\n<ul>\n<li>Import excel file into Oracle table using SQL Developer &#8211; <a href=\"https:\/\/www.thatjeffsmith.com\/archive\/2012\/04\/how-to-import-from-excel-to-oracle-with-sql-developer\/\">https:\/\/www.thatjeffsmith.com\/archive\/2012\/04\/how-to-import-from-excel-to-oracle-with-sql-developer\/<\/a><\/li>\n<li>Oracle AUTO_LEXER &#8211; <a href=\"https:\/\/docs.oracle.com\/cd\/E18283_01\/text.112\/e16593\/cdatadic.htm#BHCGJHDH\">https:\/\/docs.oracle.com\/cd\/E18283_01\/text.112\/e16593\/cdatadic.htm#BHCGJHDH<\/a><\/li>\n<li>Oracle CTX_DOC package &#8211; <a href=\"https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/19\/ccref\/CTX_DOC-package.html#GUID-7A07AEB1-2647-468A-A071-A2443EF1A514\">https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/19\/ccref\/CTX_DOC-package.html#GUID-7A07AEB1-2647-468A-A071-A2443EF1A514<\/a><\/li>\n<li>Performing sentiment analysis with CTX_DOC package &#8211; <a href=\"https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/18\/ccapp\/performing-sentiment-analysis-using-oracle-text.html#GUID-B18361E3-7A3E-4AA7-B96E-80F99247986D\">https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/18\/ccapp\/performing-sentiment-analysis-using-oracle-text.html#GUID-B18361E3-7A3E-4AA7-B96E-80F99247986D<\/a><\/li>\n<li>Training user-defined sentiment classifiers &#8211; <a href=\"https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/18\/ccapp\/performing-sentiment-analysis-using-oracle-text.html#GUID-7F1B2D64-7F7F-436F-81D3-7C8D18E956BE\">https:\/\/docs.oracle.com\/en\/database\/oracle\/oracle-database\/18\/ccapp\/performing-sentiment-analysis-using-oracle-text.html#GUID-7F1B2D64-7F7F-436F-81D3-7C8D18E956BE<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Oracle has built-in functionality to analyze text. Sanil Mhatre demonstrates how to perform a sentiment analysis on data stored in a table using Oracle Text.&hellip;<\/p>\n","protected":false},"author":317671,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143528,143533],"tags":[4459,124952,145457],"coauthors":[101710],"class_list":["post-92300","post","type-post","status-publish","format-standard","hentry","category-bi-sql-server","category-oracle-databases","tag-oracle","tag-redgate-deploy","tag-sentiment-analysis"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/92300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/317671"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=92300"}],"version-history":[{"count":9,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/92300\/revisions"}],"predecessor-version":[{"id":92314,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/92300\/revisions\/92314"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=92300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=92300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=92300"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=92300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}