ADD_EXTRACT_RULE

The ADD_EXTRACT_RULE procedure adds a single extraction rule to extract policy. Invokers add rules into their own extraction policy.

Extraction rules have sentence-wide scopes. Extraction rules have to be case-sensitive except for entity types and rule operators in the rule expression. Order of rule addition is not important. Addition of a rule will not be effective until CTX_ENTITY.COMPILE is executed. This procedure issues a commit.

Syntax

CTX_ENTITY.ADD_EXTRACT_RULE(
  policy_name                 IN VARCHAR2,
  rule_id                     IN INTEGER,
  extraction_rule             IN VARCHAR2);

policy_name

Specify the policy name.

rule_id

Specify a unique rule ID within an extraction policy. The rule ID must be greater than 0.

extraction_rule

The rule text in XML format specifies the language, expression, and entities to be extracted. The rule text follows the XML schema as follows:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="rule">
  <xsd:sequence>
    <xsd:element name="expression" type="xsd:string"/>
    <xsd:complexType>
      <xsd:attribute name="refid" type="xsd:positiveInteger"/>
    </xsd:complexType>
    <xsd:element name="comments type="xsd:string" default="\0"/>
  </xsd:sequence>
  </xsd:attribute name="language" type="xsd:string" default="ALL"/>
</xsd:element>
</xsd:schema>

Where:

Table 1 Supplied Entity Types

Supplied Entity Type Explanation Example
building Name of a building Gallery House
city Name of a city New York
company Name of a company Oracle Corporation
country Name of a country United States
currency Currency Dollar
date Date July 4
day Day Monday, Tuesday
email_address Email address person@example.com
geo_political A political or strategic organization United Nations
holiday Name of a country holiday Labor Day
location_other Other types of locations Atlantic Ocean
month Month June, July
non_profit Non-profit organization Red Cross
organization_other Other types of organizations Supreme Court
percent Expressed as number and % 10%
person_jobtitle Person referred to by title President, Professor
person_name Person referred to by name John Doe
person_other Other types of persons Other types of persons (for example, criminal)
phone_number Phone number (123)-456-7890
postal_address Postal address Redwood Shores, CA
product Name of a product Oracle Text
region Name of a region North America
ssn Social Security Number 123-45-6789
state A state or province California
time_duration A length of time 10 seconds
tod Time of day 8:00 AM
url Web address www.example.com
zip_code Zip Code CA 94065

Example 1

The following example shows how to define an extraction rule and associate it with an entity extraction policy. The following rule defines a simple extraction rule for finding email addresses in documents.

begin
  ctx_entity.add_extract_rule('pol1', 1,
  '<rule>
    <expression>email is (\w+@\w+\.\w+)</expression>
    <type refid = "1">email_address</type>
   </rule>');
end;
/

Where:

Example 2

The following rule defines a simple extraction rule for finding phone numbers in documents:

begin
  ctx_entity.add_extract_rule('pol1', 2,
  '<rule language="english">
     <expression>((d{3}) \d{3}-\d{3}-\d{4})</expression>
     <comments>Rule for phone numbers</comments>
     <type refid="1">email_address</type>
   </rule>';
end;
/

Where: