ヘッダーをスキップ
Oracle® Textアプリケーション開発者ガイド
12cリリース1 (12.1)
B71317-04
  目次へ移動
目次
索引へ移動
索引

前
次
 

カテゴリ・ルールの作成

CTX_CLS.TRAINプロシージャでは、入力トレーニング・ドキュメント・セットが必要です。トレーニング・セットとは、すでにカテゴリに割り当てられたドキュメントのセットです。

カテゴリ・ルールを作成するには、次の手順を実行します。

  1. トレーニング・ドキュメント表の作成および移入

    トレーニング・ドキュメントの表を作成してロードします。次の例では、単純なセットを使用します。ファスト・フード関連が3つとコンピュータ関連が2つです。

    create table docs (
      doc_id number primary key,
      doc_text   clob);
    
    insert into docs values
    (1, 'MacTavishes is a fast-food chain specializing in burgers, fries and -
    shakes. Burgers are clearly their most important line.');
    insert into docs values
    (2, 'Burger Prince are an up-market chain of burger shops, who sell burgers -
    and fries in competition with the likes of MacTavishes.');
    insert into docs values
    (3, 'Shakes 2 Go are a new venture in the low-cost restaurant arena, 
    specializing in semi-liquid frozen fruit-flavored vegetable oil products.');
    insert into docs values
    (4, 'TCP/IP network engineers generally need to know about routers, 
    firewalls, hosts, patch cables networking etc');
    insert into docs values
    (5, 'Firewalls are used to protect a network from attack by remote hosts,
     generally across TCP/IP');
    
  2. カテゴリ表、カテゴリ説明およびIDの作成

    ----------------------------------------------------------------------------
    -- Create category tables
    -- Note that "category_descriptions" isn't really needed for this demo -
    -- it just provides a descriptive name for the category numbers in
    -- doc_categories
    ----------------------------------------------------------------------------
    
    create table category_descriptions (
      cd_category    number,
      cd_description varchar2(80));
    
    create table doc_categories (
      dc_category    number,
      dc_doc_id      number,
      primary key (dc_category, dc_doc_id)) 
      organization index;
    
    -- descriptons for categories
    
    insert into category_descriptions values (1, 'fast food');
    insert into category_descriptions values (2, 'computer networking');
    
  3. カテゴリへの各ドキュメントの割当て

    この場合、ファスト・フードのドキュメントはすべてカテゴリ1に、コンピュータのドキュメントはカテゴリ2になります。

    insert into doc_categories values (1, 1);
    insert into doc_categories values (1, 2);
    insert into doc_categories values (1, 3);
    insert into doc_categories values (2, 4);
    insert into doc_categories values (2, 5);
    
  4. CTX_CLS.TRAINで使用するCONTEXT索引の作成

    索引用にOracle Textプリファレンスを作成します。これにより、次のように、テーマをオンにした場合とオフにした場合の効果を実験できます。

    exec ctx_ddl.create_preference('my_lex', 'basic_lexer');
    exec ctx_ddl.set_attribute    ('my_lex', 'index_themes', 'no');
    exec ctx_ddl.set_attribute    ('my_lex', 'index_text',   'yes');
    
    create index docsindex on docs(doc_text) indextype is ctxsys.context
    parameters ('lexer my_lex');
    
  5. ルール表の作成

    生成したルールに移入する表を作成します。

    create table rules(
      rule_cat_id     number,
      rule_text       varchar2(4000),
      rule_confidence number
    );
    
  6. カテゴリ・ルールを生成するCTX_CLS.TRAINプロシージャのコール

    ここで、CTX_CLS.TRAINプロシージャをコールしてルールの一部を生成します。すべての引数が、表、列またはこの例で以前に作成された索引の名前であることに注意してください。これにより、rules表にルールが含まれ、ユーザーが表示できるようになります。

    begin
      ctx_cls.train(
        index_name => 'docsindex',
        docid      => 'doc_id',
        cattab     => 'doc_categories',
        catdocid   => 'dc_doc_id',
        catid      => 'dc_category',
        restab     => 'rules',
        rescatid   => 'rule_cat_id',
        resquery   => 'rule_text',
        resconfid  => 'rule_confidence'
      );
    end;
    /
    
  7. カテゴリで表示される生成済ルールのフェッチ

    生成済のルールをフェッチします。便宜上、rules表はcategory_descriptionsと結合され、各ルールが適用されるカテゴリを表示できるようになります。

    select cd_description, rule_confidence, rule_text from rules, 
    category_descriptions where cd_category = rule_cat_id;