nx_anti_slop.nx source
↩ module page · 61 lines · 3626 B
1// nx_anti_slop.nx -- LIB: anti-slop QUALITY FILTER = the 2026 relevance edge (AI content farms lost 50-90% traffic;
2// the web drowns in AI slop). Scores a document's "real human content" likelihood from measurable text signals and
3// returns a rank MULTIPLIER (0..1000 permille) that DOWN-RANKS slop -- it NEVER deletes (composes the content-neutrality
4// charter: no dead-internet walls, freedom of expression; even the worst slop keeps a positive FLOOR so it still
5// appears, just lower). Signals: lexical diversity (unique/total -- real content is diverse; AI-slop + keyword-stuffing
6// are not), keyword-stuffing repetition (max-token-freq/total), thin-content length. Data-driven thresholds. Built +
7// gated NOW; runs over the ingested corpus at NAS scale later, fused as a quality prior into nx_rank_fused. No float.
8// license_tier: ORIGINAL
9import "nx_syscalls.nx"
10const AS_MAGIC_1469598103934665603: i64 = 1469598103934665603
11const AS_MAGIC_1099511628211: i64 = 1099511628211
12const AS_MAGIC_8192: i64 = 8192
13
14const AS_MIN: i64 = 5 // min tokens for "adequate length"
15const AS_FLOOR: i64 = 50 // quality floor (>0): slop is DOWN-ranked, never removed (neutrality)
16const AS_THRESH: i64 = 500 // >= this = KEEP (real content); below = down-ranked slop
17
18func as_lc(c: i64) -> i64 { if c >= 0x41 { if c <= 0x5a { return c + 0x20 } } return c }
19func as_is_tok(c: i64) -> i64 { if c >= 0x30 { if c <= 0x39 { return 1 } } if c >= 0x41 { if c <= 0x5a { return 1 } } if c >= 0x61 { if c <= 0x7a { return 1 } } return 0 }
20func as_tok_hash(text: *u8, s: i64, e: i64) -> i64 { var h: i64 = AS_MAGIC_1469598103934665603; var i: i64 = s; while i < e { h = h ^ as_lc(text[i] as i64); h = h * AS_MAGIC_1099511628211; i = i + 1 } return h }
21
22// quality permille (0..1000, higher = more human/real). rank multiplier.
23func as_quality(text: *u8, len: i64) -> i64 {
24 let hashes: *i64 = sys_mmap(8*AS_MAGIC_8192) as *i64
25 var ntok: i64 = 0
26 var i: i64 = 0
27 while i < len {
28 if as_is_tok(text[i] as i64) == 0 { i = i + 1 } else {
29 let s: i64 = i
30 var go: i64 = 1
31 while go == 1 { if i < len { if as_is_tok(text[i] as i64)==1 { i=i+1 } else { go=0 } } else { go=0 } }
32 if ntok < AS_MAGIC_8192 { hashes[ntok] = as_tok_hash(text, s, i); ntok = ntok + 1 }
33 }
34 }
35 if ntok == 0 { return AS_FLOOR }
36 var unique: i64 = 0; var maxfreq: i64 = 0
37 var a: i64 = 0
38 while a < ntok {
39 var seen: i64 = 0; var b: i64 = 0
40 while b < a { if hashes[b] == hashes[a] { seen = 1 } b = b + 1 }
41 if seen == 0 {
42 unique = unique + 1
43 var f: i64 = 0; var c: i64 = 0
44 while c < ntok { if hashes[c] == hashes[a] { f = f + 1 } c = c + 1 }
45 if f > maxfreq { maxfreq = f }
46 }
47 a = a + 1
48 }
49 let diversity: i64 = unique * 1000 / ntok
50 let repetition: i64 = maxfreq * 1000 / ntok
51 var quality: i64 = diversity
52 if repetition > 400 { quality = quality - (repetition - 400) } // keyword-stuffing penalty
53 if ntok < AS_MIN { quality = quality * ntok / AS_MIN } // thin-content penalty
54 if quality < AS_FLOOR { quality = AS_FLOOR } // never suppress fully (neutrality floor)
55 if quality > 1000 { quality = 1000 }
56 return quality
57}
58// apply the quality multiplier to a base relevance score (down-ranks slop; floor keeps it present).
59func as_apply(base: i64, quality: i64) -> i64 { return base * quality / 1000 }
60// KEEP (real content) vs down-ranked slop.
61func as_keep(quality: i64) -> i64 { if quality >= AS_THRESH { return 1 } return 0 }