Skip to content

Commit e1a0346

Browse files
Prefer grounded subject evidence before namesake profile scores (#1251)
* Prefer a namesake's grounded subject evidence over the chunk profile Signed-off-by: Virtue039 <virtue039@qq.com> * Make the subject-only evidence boundary explicit and keep focused regressions Signed-off-by: Virtue039 <virtue039@qq.com> --------- Signed-off-by: Virtue039 <virtue039@qq.com> Co-authored-by: WaylandYang <145302500+WaylandYang@users.noreply.github.com>
1 parent 9942c05 commit e1a0346

3 files changed

Lines changed: 371 additions & 17 deletions

File tree

‎crates/utopia-server/src/extraction_open.rs‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,41 @@ struct ChunkParsed {
4545
name_vecs: HashMap<String, Vec<f32>>,
4646
}
4747

48+
/// Identity clues belong to the statement's subject, not to every name in the chunk.
49+
/// Keep only grounded, single-sentence quotes with one subject owner. Overlapping
50+
/// quotes assigned to different subjects cannot tell us whose department was named.
51+
fn mention_evidence(
52+
extraction: &utopia_extract::open::OpenExtraction,
53+
text: &str,
54+
) -> HashMap<String, String> {
55+
let quotes: Vec<_> = extraction
56+
.statements
57+
.iter()
58+
.filter_map(|s| {
59+
let quote = s.quote.as_deref()?.trim();
60+
Some((name_key(&s.subject), quote, locate(text, quote)?))
61+
})
62+
.collect();
63+
let mut evidence = HashMap::<String, String>::new();
64+
for (subject, quote, (start, end)) in &quotes {
65+
// Conservative about abbreviations too: a missed clue falls back to the
66+
// existing resolver; joining separate sentences can attach to the wrong person.
67+
let body = quote.trim_end_matches(['.', '!', '?', '。', '!', '?', '"', '”', '’']);
68+
if body.contains(['.', '!', '?', '。', '!', '?', ';', ';'])
69+
|| !span_in_quote(subject, quote)
70+
|| quotes.iter().any(|(other, _, (a, b))| {
71+
other != subject && ((a < end && start < b) || span_in_quote(other, quote))
72+
})
73+
{
74+
continue;
75+
}
76+
let entry = evidence.entry(subject.clone()).or_default();
77+
entry.push_str(quote);
78+
entry.push('\n');
79+
}
80+
evidence
81+
}
82+
4883
/// 回复为什么是半截的:端点撞上了 token 上限(#760),或护栏看见它在复读、停了读(#1301)。
4984
/// 两种都当半截处理,丢弃行要说清是哪一种——复读的去查上限,是找错了地方
5085
#[derive(Debug, Clone, Copy)]
@@ -265,6 +300,10 @@ async fn apply_open_extraction(
265300
touched_names: &mut HashSet<String>,
266301
) -> anyhow::Result<()> {
267302
// ---- 东西:有名字的走身份消解,被描述的建成没有名字事实的实体 ----
303+
// Object-only mentions and rejected quotes deliberately supply None, including
304+
// to the old #331 tie/grey-zone paths: another subject's chunk is not their clue.
305+
// With no owned clue, profile tiers and their ordinary review requests decide.
306+
let evidence = mention_evidence(extraction, &chunk.text);
268307
let mut response_claims: HashMap<String, Vec<Uuid>> = HashMap::new();
269308
let mut local: HashMap<String, Uuid> = HashMap::new();
270309
// 被描述的东西:先记下名字和类别词,等陈述指到它再建(见 `place`)
@@ -290,7 +329,7 @@ async fn apply_open_extraction(
290329
name,
291330
ctx,
292331
name_vecs.get(&key).map(Vec::as_slice),
293-
Some(&chunk.text),
332+
evidence.get(&key).map(String::as_str),
294333
&mut response_claims,
295334
handled_by_name,
296335
ambiguous_bare_cache,

0 commit comments

Comments
 (0)