Oracle by Example brandingCreating a Sentiment Classifier Preference with Oracle Text

section 0Before You Begin

This 15-minute tutorial shows you how to create a sentiment classifier preference and define its attributes with Oracle Text.

Background

A sentiment classifier is a type of document classifier that you use to extract sentiment metadata about a topic or document. To perform sentiment analysis by using a sentiment classifier, you must associate a sentiment classifier preference with the sentiment classifier.

What Do You Need?

  • Oracle Database 18c
  • Oracle SQL Developer 17.3.2

section 1Create a Database Connection

  1. Run sqldeveloper.exe in Windows or sqldeveloper.sh in Linux.
  2. On the Connections tab, right-click Connections and select New Connection.
  3. In the New / Select Database Connection window, enter or select the values for your database connection. This example uses the following values:
    • Connection Name: sys_conn
    • Username: sys
    • Password: your SYS user password
    • Role: SYSDBA
    • Hostname: localhost
    • Port: 1521
    • SID: orcl
  4. Click Test and verify the status of the connection. In this example, the status displays Success above the Help button.
    Status of sys_conn
    Description of the illustration sys_conn.png
  5. Click Save, click Connect, and close the window.
  6. When the connection is established, a SQL worksheet opens and you use it to run SQL commands.


section 2Connect to an Oracle Text User

  1. Create the user.
    CREATE USER myuser IDENTIFIED BY your_password;
  2. Grant roles to the user.
  3. GRANT RESOURCE, CONNECT, CTXAPP TO myuser;

    The CTXAPP role enables you to create Oracle Text indexes and index preferences and to use PL/SQL packages.

  4. Grant myuser an unlimited quota in the USERS tablespace.
    ALTER USER myuser QUOTA UNLIMITED ON USERS;
  5. To create a connection to myuser, click the Connections tab, right-click Connections, and select New Connection.
  6. In the New / Select Database Connection window, enter or select the values for your database connection. This example uses the following values:
    • Connection Name: myuser_conn
    • Username: myuser
    • Password: your user password
    • Role: default
    • Hostname: localhost
    • Port: 1521
    • SID: orcl
  7. Click Test and verify the status of the connection. In this example, the status displays Success above the Help button.
    Status of myuser_conn
    Description of the illustration myuser_conn.png
  8. Click Save, click Connect, and close the window.
  9. When the connection is established, a SQL worksheet opens and you use it to run SQL commands.


section 3Create a Sentiment Classifier Preference

  1. Create a sentiment classifier preference of SENTIMENT_CLASSIFIER type.
    EXEC CTX_DDL.CREATE_PREFERENCE('clsfier_camera','SENTIMENT_CLASSIFIER')
  2. Define the attributes of the sentiment classifier preference.
  3. EXEC CTX_DDL.SET_ATTRIBUTE('clsfier_camera','MAX_FEATURES','1000')
    EXEC CTX_DDL.SET_ATTRIBUTE('clsfier_camera','NUM_ITERATIONS','600')

    MAX_FEATURES enables you to specify the maximum number of distinct features (words, stems, and themes) to be extracted to build a sentiment classifier. NUM_ITERATIONS enables you to specify the number of iterations for which the sentiment classifier runs.