1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/// Base confidence per pattern family, before proximity decay.
pub mod base {
/// A kinship or role noun in a possessive states the relation outright.
pub const POSSESSIVE_FACTUAL: f32 = 0.85;
/// A social-stance noun ("friend", "enemy", "rival") in the same
/// possessive shape. IMPORTANT: the phrasing is as explicit, but the claim
/// is not. Stance is routinely negated, hypothetical, or narrated from a
/// character's mistaken view, so it does not earn the factual base.
pub const POSSESSIVE_STANCE: f32 = 0.70;
/// A direct verb between the two mentions.
pub const VERB: f32 = 0.78;
/// An exact-phrase rule whose verb states the relation outright
/// ("married", "lives in").
pub const PHRASE_FACTUAL: f32 = 0.78;
/// An exact-phrase rule naming a feeling or stance ("loves", "friends with").
pub const PHRASE_STANCE: f32 = 0.68;
/// An exact-phrase rule naming an event rather than a standing relation
/// ("met", "kissed", "taught"): true when narrated, but not a lasting fact.
pub const PHRASE_EVENT: f32 = 0.62;
/// A relative clause, which puts more text between the mentions and more
/// ways for the attachment to be wrong.
pub const RELATIVE_CLAUSE: f32 = 0.70;
}
/// Scale a pattern's base confidence by how close the subject and object are
/// in the source text (`gap`: bytes between the end of the subject mention and
/// the start of the object mention).
///
/// Closer entities are less likely to be an accidental co-occurrence, so gap
/// distance scales the base score down as the gap widens.
pub fn score_confidence(base: f32, gap: usize) -> f32 {
// gap is already bounded to <= 30 by the caller; scale the last 15 bytes
// of that range down to a floor of 0.85x base, so a close match keeps the
// full base score and a far one loses up to 15%.
let proximity_penalty = (gap.saturating_sub(15) as f32 / 15.0).min(1.0) * 0.15;
(base - base * proximity_penalty).clamp(0.0, 1.0)
}