Skip to main content

RedactionEngine

Trait RedactionEngine 

Source
pub trait RedactionEngine: Send + Sync {
    // Required method
    fn infer(&self, text: &str) -> Result<Vec<Finding>, EngineError>;

    // Provided method
    fn infer_with_lang(
        &self,
        text: &str,
        _lang: Option<&str>,
    ) -> Result<Vec<Finding>, EngineError> { ... }
}
Expand description

Privacy Filter 推理引擎抽象。scan_text_with_engine 通过本 trait 拿 Model 侧 findings, 与 Hard 侧 [crate::scan::collect_hard_findings] 输出送 merge_findings 决策合并。

实现要求:

  • 必须 Send + Sync(由 trait bound 强制;scan_text_with_engine&dyn, 线程边界由 caller 决定)。
  • infer 失败应返 EngineError 各分类;scan_text_with_engineFrom<EngineError> for ScanError 自动转 ScanError::InferenceFailed
  • 返回的 Finding risk_delta 可填 0:caller 在 scan_text_with_engine 内会 按 risk_of(kind) 重新补值(engine 与 risk 表彻底解耦,SSOT 见 ADR 0012 §1.3)。 kind 字段必须是 &'static str(由 crate::label::PrivacyLabel::as_str 提供)。

Required Methods§

Source

fn infer(&self, text: &str) -> Result<Vec<Finding>, EngineError>

text 做模型推理,返回 Model 侧 findings。

§Errors

任意 EngineError 变体表示推理失败;caller 的 scan_text_with_engine 会以 ?ScanError::InferenceFailed 早返(fail-closed)。

Provided Methods§

Source

fn infer_with_lang( &self, text: &str, _lang: Option<&str>, ) -> Result<Vec<Finding>, EngineError>

v0.9 Sprint 1 P1.2 — 带 lang 上下文的推理(spike)。

default 实现:忽略 lang 参数,委托 Self::infer(向后兼容,SemVer 安全;现有 RedactionEngine 实现不需改)。

OrtEngine override:若 descriptor 提供 crate::model_descriptor::LangConditionalThresholdProfile(通过新方法 lang_conditional_profile()),threshold 应用时优先查 (lang, label) override;无则 fallback default profile。

lang 规范:case-sensitive,推荐 ISO 639-1 lowercase("en" / "de" / "it" / "fr" / …),与 fixture lang 字段对齐。None 等价 infer() 行为(无 lang 上下文)。

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§