Repository navigation
Expand file tree
/
Copy pathlib.rs
More file actions
39 lines (36 loc) · 1.92 KB
/
Copy pathlib.rs
File metadata and controls
39 lines (36 loc) · 1.92 KB
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
//! Deliberately not a truth classifier. Scores only the completeness of a user's evidence ledger.
//! ABI inputs are bounded integers: kind 1=independent primary support, 2=independent secondary
//! support, 3=contradiction, 4=context, 5=unverified. 0..1000 represents an integer grade.
#[no_mangle]
pub extern "C" fn evidence_points(kind: u32, independent: u32, dated: u32, direct: u32) -> i32 {
let (base, accuracy): (i32, i32) = match kind {
1 => (210, 100),
2 => (130, 60),
3 => (-240, -80),
4 => (45, 25),
5 => (0, 0),
_ => return 0,
};
let bonus: i32 = if independent != 0 { accuracy } else { 0 };
let date_bonus = if dated != 0 { 35 } else { 0 };
let direct_bonus = if direct != 0 { 35 } else { 0 };
base + if base < 0 { -bonus.abs() - date_bonus - direct_bonus } else { bonus + date_bonus + direct_bonus }
}
#[no_mangle]
pub extern "C" fn coverage_grade(support: i32, contradiction: i32, contexts: u32, distinct: u32) -> u32 {
// Coverage is not a probability or truth verdict; contradictions increase review burden.
let breadth = (distinct.min(5) * 80) as i32;
let context_bonus = (contexts.min(3) * 35) as i32;
let review_penalty = contradiction.saturating_abs().min(450);
(100_i32.saturating_add(support.min(650)).saturating_add(breadth)
.saturating_add(context_bonus).saturating_sub(review_penalty))
.clamp(0, 1000) as u32
}
#[cfg(test)]
mod tests {
use super::*;
#[test] fn primary_beats_secondary() { assert!(evidence_points(1, 1, 1, 1) > evidence_points(2, 1, 1, 1)); }
#[test] fn contradiction_reduces_coverage() { assert!(coverage_grade(300, 0, 2, 2) > coverage_grade(300, -240, 2, 2)); }
#[test] fn bounded_grade() { assert_eq!(coverage_grade(i32::MAX, 0, u32::MAX, u32::MAX), 1000); assert_eq!(coverage_grade(0, -999, 0, 0), 0); }
#[test] fn unknown_kind_is_zero() { assert_eq!(evidence_points(99, 1, 1, 1), 0); }
}