TRAIN
Use this procedure to generate query rules that select document categories. You must supply a training set consisting of categorized documents. Documents can be in any format supported by Oracle Text and must belong to one or more categories. This procedure generates the queries that define the categories and then writes the results to a table.
You must also have a document table and a category table. The category table must contain at least two categories.
For example, your document and category tables can be defined as:
create table trainingdoc(
docid number primary key,
text varchar2(4000));
create table category (
docid trainingdoc(docid),
categoryid number);
You can use one of two syntaxes depending on the classification algorithm you need. The query compatible syntax uses the RULE_CLASSIFIER preference and generates rules as query strings. The Support Vector Machine syntax uses the SVM_CLASSIFER preference and generates rules in binary format. The SVM_CLASSIFIER is good for high classification accuracy, but because its rules are generated in binary format, they cannot be examined like the query strings generated with the RULE_CLASSIFIER. Note that only those document ids that appear in both the document table and the category table will impact RULE_CLASSIFIER and SVM_CLASSIFIER learning.
The CTX_CLS.TRAIN procedure requires that your document table have an associated context index. For best results, the index should be synchronized before running this procedure. SVM_CLASSIFIER syntax enables the use of an unpopulated context index, while query-compatible syntax requires that the context index be populated.
Note: When downgrading the database, you must drop any models that were created in Oracle Database 12c Release 2 (
12.2) using TRAIN. These models are not compatible with earlier releases. The following error occurs if the models are not dropped before the downgrade: ORA-40350: One or more models exist that cannot be downgraded.
See Also: Oracle Text Application Developer’s Guide for more on document classification
Query Compatible Syntax
The following syntax generates query-compatible rules and is used with the RULE_CLASSIFIER preference. Use this syntax and preference when different categories are separated from others by several key words. An advantage of generating your rules as query strings is that you can easily examine the generated rules. This is different from generating SVM rules, which are in binary format.
CTX_CLS.TRAIN(
index_name in varchar2,
docid in varchar2,
cattab in varchar2,
catdocid in varchar2,
catid in varchar2,
restab in varchar2,
rescatid in varchar2,
resquery in varchar2,
resconfid in varchar2,
preference in varchar2 DEFAULT NULL
);
index_name
Specify the name of the context index associated with your document training set.
docid
Specify the name of the document ID column in the document table. The document IDs in this column must be unique, and this column must be of datatype NUMBER. The values for this column must be stored in an unsigned 32-bit integer and must be in the range 0-4294967295.
cattab
Specify the name of the category table. You must have the READ or SELECT privilege on this table. (See Oracle Database Security Guide for information about the READ privilege.)
catdocid
Specify the name of the document ID column in the category table. The document IDs in this table must also exist in the document table. This column must be a NUMBER. The values for this column must be stored in an unsigned 32-bit integer and must be in the range 0-4294967295.
catid
Specify the name of the category ID column in the category table. This column must be a NUMBER. The values for this column must be stored in an unsigned 32-bit integer and must be in the range 0-4294967295.
restab
Specify the name of the result table. You must have INSERT privilege on this table.
rescatid
Specify the name of the category ID column in the result table. This column must be a NUMBER. The values for this column must be stored in an unsigned 32-bit integer and must be in the range 0-4294967295.
resquery
Specify the name of the query column in the result table. This column must be VARACHAR2, CHAR, CLOB, NVARCHAR2, or NCHAR.
The queries generated in this column connects terms with AND or NOT operators, such as:
'T1 & T2 ~ T3'
Terms can also be theme tokens and be connected with the ABOUT operator, such as:
'about(T1) & about(T2) ~ about(T3)'
Generated rules also support WITHIN queries on field sections.
resconfid
Specify the name of the confidence column in result table. This column contains the estimated probability from training data that a document is relevant if that document satisfies the query.
preference
Specify the name of the preference. For classifier types and attributes, see “Classifier Types” in Oracle Text Indexing Elements.
Syntax for Support Vector Machine (SVM) Rules
The Support Vector Machine, or SVM, rules preference generates rules in binary format. Use this syntax when your application requires high classification accuracy.
The following syntax generates Support Vector Machine (SVM) rules with the SVM_CLASSIFIER preference.
CTX_CLS.TRAIN(
index_name in varchar2,
docid in varchar2,
cattab in varchar2,
catdocid in varchar2,
catid in varchar2,
restab in varchar2,
preference in varchar2 );
index_name
Specify the name of the text index.
docid
Specify the name of docid column in document table.
cattab
Specify the name of category table.
catdocid
Specify the name of docid column in category table.
catid
Specify the name of category ID column in category table.
restab
Specify the name of result table.
The result table has the following format:
| Column Name | Datatype | Description |
|---|---|---|
CAT_ID |
NUMBER |
The ID of the category. |
TYPE |
NUMBER(3) NOT NULL |
0 for the actual rule or catid; 1 for other. |
RULE |
BLOB |
The returned rule. |
preference
Specify the name of user preference. For classifier types and attributes, see “Classifier Types” in Oracle Text Indexing Elements.
Note: Column names must not be prefixed by the owner, schema or table name.
Example
The CTX_CLS.TRAIN procedure is used in supervised classification. For an extended example, see Oracle Text Application Developer’s Guide.