You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Oracle文本分类:新增辅助列实现多规则集隔离方案咨询

Great question! Oracle Text absolutely supports this approach—you can use an auxiliary doc_type column to isolate rule sets without duplicating tables. Here's how it impacts your existing script and how to implement it:

核心结论

Oracle Text fully supports isolating multiple rule sets using an auxiliary column, eliminating the need for separate table sets. We can achieve this by modifying table structures, training logic, and prediction logic.

关键 Modifications to Your Existing Script

Below are the core adjustments you need to make:

1. Extend Table Structures

First, add a doc_type column to relevant tables to mark the group that documents, categories, and rules belong to:

-- Add doc_type to the document table with a default value of 1 (adjust as needed)
alter table ml_docs add doc_type number default 1 not null;
-- Update existing documents: set network-related docs to doc_type=2
update ml_docs set doc_type = 2 where doc_id in (4,5);

-- Add doc_type to the category association table, sync with the document table
alter table ml_doc_categories add doc_type number not null;
update ml_doc_categories dc
set dc.doc_type = (select d.doc_type from ml_docs d where d.doc_id = dc.dc_doc_id);

-- Add doc_type to the rules table to distinguish rule groups
alter table ml_rules add doc_type number not null;

2. Adjust Training Logic

Oracle Text's ctx_cls.train procedure supports limiting the training document subset with where_clause, and writing doc_type to the rules table using rescols. You'll need to train a separate rule set for each doc_type:

-- Optional: Clear existing rules before retraining
truncate table ml_rules;

-- Train rule set for doc_type=1 (fast food)
begin
  ctx_cls.train(
    index_name     => 'ml_docsindex',
    docid          => 'doc_id',
    cattab         => 'ml_doc_categories',
    catdocid       => 'dc_doc_id',
    catid          => 'dc_category',
    restab         => 'ml_rules',
    rescatid       => 'rule_cat_id',
    resquery       => 'rule_text',
    resconfid      => 'rule_confidence',
    where_clause   => 'doc_type = 1', -- Only train on doc_type=1 documents
    rescols        => 'doc_type'      -- Write doc_type to the rules table
  );
end;
/

-- Train rule set for doc_type=2 (computer networking)
begin
  ctx_cls.train(
    index_name     => 'ml_docsindex',
    docid          => 'doc_id',
    cattab         => 'ml_doc_categories',
    catdocid       => 'dc_doc_id',
    catid          => 'dc_category',
    restab         => 'ml_rules',
    resquery       => 'rule_text',
    resconfid      => 'rule_confidence',
    where_clause   => 'doc_type = 2',
    rescols        => 'doc_type'
  );
end;
/

3. Adjust Prediction Logic

When predicting, only match rules from the corresponding group based on the incoming document's doc_type to ensure full rule set isolation:

set serveroutput on;
declare
  incoming_doc clob;
  v_doc_type number := 1; -- Specify the doc_type of the incoming document (adjust as needed)
begin
  incoming_doc := 'I have spent my entire life managing restaurants selling burgers';
  
  for c in (
    select distinct cd_description
    from ml_rules r
    join ml_category_descriptions cd on cd.cd_category = r.rule_cat_id
    where r.doc_type = v_doc_type -- Only use rules for the target doc_type
      and matches(r.rule_text, incoming_doc) > 0
  ) loop
    dbms_output.put_line('CATEGORY: '||c.cd_description);
  end loop;
end;
/
Additional Optimization Tips
  • Create a regular index on the doc_type column of ml_rules to speed up prediction queries:
    create index ml_rules_doc_type_idx on ml_rules(doc_type);
    
  • When inserting new documents, always set the correct doc_type value and ensure ml_doc_categories syncs with the document table to maintain training accuracy.

内容的提问来源于stack exchange,提问作者Ctznkane525

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:25:42