mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-09-18 13:34:53 +08:00
fix(tm):建立 Trusted 唯一性与 Supersede 治理
This commit is contained in:
@@ -23,7 +23,8 @@ pub use translation::{
|
||||
TranslationStatus,
|
||||
};
|
||||
pub use translation_memory::{
|
||||
TranslationMemoryContext, TranslationMemoryDraft, TranslationMemoryEntry,
|
||||
TranslationMemoryMatch, TranslationMemoryMatchKind, TranslationMemorySourceKind,
|
||||
TranslationMemorySourceTrace, TranslationMemorySummary, TranslationMemoryTrustStatus,
|
||||
TranslationMemoryConflict, TranslationMemoryContext, TranslationMemoryDraft,
|
||||
TranslationMemoryEntry, TranslationMemoryMatch, TranslationMemoryMatchKind,
|
||||
TranslationMemorySourceKind, TranslationMemorySourceTrace, TranslationMemorySummary,
|
||||
TranslationMemoryTrustStatus,
|
||||
};
|
||||
|
||||
@@ -57,6 +57,8 @@ impl TranslationMemoryTrustStatus {
|
||||
pub enum TranslationMemoryMatchKind {
|
||||
/// 原始 source 和上下文都完全匹配,且记录可信,可自动复用。
|
||||
StrongExact,
|
||||
/// 同一 exact identity 存在多个 Trusted,必须人工治理。
|
||||
TrustedConflict,
|
||||
/// 原始 source 完全匹配,但上下文不同或不足,不能自动复用。
|
||||
CandidateExact,
|
||||
/// 原始 source 匹配,但上下文不兼容,不能自动复用。
|
||||
@@ -68,6 +70,7 @@ impl TranslationMemoryMatchKind {
|
||||
pub const fn as_str(&self) -> &'static str {
|
||||
match self {
|
||||
Self::StrongExact => "strong_exact",
|
||||
Self::TrustedConflict => "trusted_conflict",
|
||||
Self::CandidateExact => "candidate_exact",
|
||||
Self::SourceOnly => "source_only",
|
||||
}
|
||||
@@ -210,6 +213,23 @@ pub struct TranslationMemoryMatch {
|
||||
pub can_auto_reuse: bool,
|
||||
}
|
||||
|
||||
/// 一个 exact identity 的历史多 Trusted 冲突组。
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct TranslationMemoryConflict {
|
||||
/// 原始 source text。
|
||||
pub source_text: String,
|
||||
/// source text hash,仅用于稳定定位和辅助查询。
|
||||
pub source_hash: String,
|
||||
/// 完整 source context。
|
||||
pub source_context: TranslationMemoryContext,
|
||||
/// source context hash,仅用于稳定定位和辅助查询。
|
||||
pub source_context_hash: String,
|
||||
/// 当前数据库中属于该冲突组的 Trusted record ID。
|
||||
pub trusted_record_ids: Vec<String>,
|
||||
/// 冲突组记录及其原始 trust provenance。
|
||||
pub records: Vec<TranslationMemoryEntry>,
|
||||
}
|
||||
|
||||
/// TM 仓储摘要。
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub struct TranslationMemorySummary {
|
||||
@@ -225,4 +245,8 @@ pub struct TranslationMemorySummary {
|
||||
pub superseded_count: u64,
|
||||
/// 已拒绝记录数。
|
||||
pub rejected_count: u64,
|
||||
/// exact identity 的 Trusted 冲突组数量。
|
||||
pub trusted_conflict_group_count: u64,
|
||||
/// 具备 current Trusted authorization 的 exact identity 数量。
|
||||
pub current_trusted_count: u64,
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
//! Translation Memory 仓储契约。
|
||||
|
||||
use crate::domain::{
|
||||
TranslationMemoryContext, TranslationMemoryDraft, TranslationMemoryEntry,
|
||||
TranslationMemoryMatch, TranslationMemorySummary,
|
||||
TranslationMemoryConflict, TranslationMemoryContext, TranslationMemoryDraft,
|
||||
TranslationMemoryEntry, TranslationMemoryMatch, TranslationMemorySummary,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
|
||||
/// 跨 official release 持久化的 Translation Memory 仓储。
|
||||
///
|
||||
/// 该契约只描述 V1 的精确查询和明确人工确认。仓储实现不得把
|
||||
/// 该契约描述 exact-match TM 和明确人工 Trusted 治理。仓储实现不得把
|
||||
/// `TranslationTaskStatus::Completed` 或 provider 成功隐式解释为 trusted。
|
||||
#[async_trait]
|
||||
pub trait TranslationMemoryRepository: Send + Sync {
|
||||
@@ -39,6 +39,27 @@ pub trait TranslationMemoryRepository: Send + Sync {
|
||||
reason: Option<String>,
|
||||
) -> crate::Result<TranslationMemoryEntry>;
|
||||
|
||||
/// 确认记录,并在需要时显式 supersede 当前唯一 Trusted。
|
||||
async fn confirm_with_supersede(
|
||||
&self,
|
||||
record_id: &str,
|
||||
reviewer: &str,
|
||||
reason: Option<String>,
|
||||
supersede_record_id: Option<&str>,
|
||||
) -> crate::Result<TranslationMemoryEntry>;
|
||||
|
||||
/// 列出历史上存在多个 Trusted 的 exact identity 冲突组。
|
||||
async fn list_conflicts(&self, limit: usize) -> crate::Result<Vec<TranslationMemoryConflict>>;
|
||||
|
||||
/// 使用事务内精确的 expected set 显式解决一个 Trusted 冲突组。
|
||||
async fn resolve_conflict(
|
||||
&self,
|
||||
winner_record_id: &str,
|
||||
expected_trusted_record_ids: &[String],
|
||||
reviewer: &str,
|
||||
reason: &str,
|
||||
) -> crate::Result<TranslationMemoryEntry>;
|
||||
|
||||
/// 按稳定记录 ID 读取一条 TM 记录。
|
||||
async fn find(&self, record_id: &str) -> crate::Result<TranslationMemoryEntry>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user