Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/aienos.com/blob/main/crates/site-builder/src/components/machines.rs
# aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
branch `main` Branches Tags History
`aienos.com / crates / site-builder / src / components / machines.rs`
3476 lines · 139775 bytes Raw Blame History
1 //! The machines and the speeds: what the project runs on today and how
2 //! fast its own engine goes, with a receipt beside every number.
3 //!
4 //! One data file, `data/machines.json`, compiled in with `include_str!`
5 //! and validated at build time and in the tests. Every machine and every
6 //! speed row must carry a public link; a row without one fails the build.
7 //! Numbers stand beside the physical ceiling of the machine they ran on
8 //! and beside my own previous run. A comparison with another project is
9 //! allowed when the same sentence has a real ISO date and a link to an
10 //! aien-dev receipt or to that project's own published numbers. Overclaims
11 //! and unsourced comparisons are refused. The one allowlisted sentence is
12 //! "Slower than I want."
13 //! The homepage shows both sections; /machine/ shows the machines first,
14 //! before the theory, so the page describes real hardware.
15
16 use std::sync::OnceLock;
17
18 use maud::{html, Markup};
19 use serde::Deserialize;
20
21 use super::boxlink::{foot, Target};
22
23 /// The raw data file, compiled into the binary.
24 pub const RAW: &str = include_str!("../../data/machines.json");
25
26 /// Phrases matched case-insensitively, with a word boundary on each side.
27 /// These are claims on their own. "faster than", "half", "twice", "parity",
28 /// and "beat" are context-bound: they count only in `context_is_claim`.
29 pub const COMPARISON_PHRASES: &[&str] = &[
30 "better than",
31 "worse than",
32 "slower than",
33 "level with",
34 "ahead of",
35 "same speed as",
36 "as fast as",
37 "factor of",
38 "comparable to",
39 "competitive with",
40 "edges out",
41 ];
42
43 /// Whole words, case-insensitively. Not stems. A claim on their own.
44 /// Bare "behind" is ordinary English, so it is not a claim.
45 /// "match", "matched", "tie", "ties", "tied", "equal", "equals", "equaled",
46 /// "equalled", "tied with", "equal to" and "on par with" are context-bound,
47 /// in `TIE_WORDS` and `TIE_PHRASES`: they count beside an outside name, a
48 /// rival noun, a multiplier, or the "best measured CUDA number" bar.
49 /// "rivals", "rivaled" and "rivalled" are comparison words on their own.
50 /// Superlatives ("fastest", "slowest", "quickest", "best", "worst") count only
51 /// beside a project name, in `has_guarded_word`.
52 /// "beat", "parity", "trails" and "lags" are context-bound, in `CONTEXT_WORDS`.
53 pub const COMPARISON_WORDS: &[&str] = &["outdoes", "tops", "rivals", "rivaled", "rivalled"];
54
55 /// Count only when the same sentence also names an outside system, a rival
56 /// noun, or a number glued to the comparative ("2x faster", "half as fast").
57 const CONTEXT_PHRASES: &[&str] = &[
58 "faster than",
59 "quicker than",
60 "cheaper than",
61 "more efficient than",
62 ];
63
64 const CONTEXT_WORDS: &[&str] = &[
65 "half", "twice", "double", "parity", "trails", "lags",
66 "beat", "beats", "beating", "beaten",
67 ];
68
69 /// Tie words. Same targets as the other context words, plus a multiplier
70 /// or the bar phrase "best measured CUDA number". A different word in a
71 /// CUDA bar sentence does not stay on the exact-sentence list.
72 const TIE_WORDS: &[&str] = &[
73 "match", "matches", "matching", "matched",
74 "tie", "ties", "tied",
75 "equal", "equals", "equaled", "equalled",
76 ];
77
78 const TIE_PHRASES: &[&str] = &["tied with", "equal to", "on par with", "on a par with"];
79
80 /// Connectors. They count when the same sentence names a rival.
81 const CONNECTORS: &[&str] = &[
82 "versus",
83 "compared with",
84 "compared to",
85 "relative to",
86 "speedup over",
87 ];
88
89 /// A generic rival. Not a project name. Context-bound words count beside one of these.
90 const RIVAL_NOUNS: &[&str] = &[
91 "competitors",
92 "the competition",
93 "alternatives",
94 "other systems",
95 "other frameworks",
96 "other stacks",
97 "other compilers",
98 "other runtimes",
99 "the industry",
100 "state of the art",
101 "sota",
102 "incumbent",
103 "leader",
104 "leading",
105 "market leader",
106 "gpu stack",
107 "gpu stacks",
108 "the field",
109 "everyone else",
110 "existing tools",
111 "rival",
112 ];
113
114 /// A word that starts with one of these, case-insensitively: outperforms,
115 /// outpaced, surpasses, exceeded. "rival" is a noun in `RIVAL_NOUNS`, not a
116 /// stem: "holds back every rival" is not a comparison. The verb "rivals" is
117 /// a comparison word on its own.
118 pub const COMPARISON_STEMS: &[&str] = &["outperform", "outpace", "surpass", "exceed"];
119
120 /// Overclaims. These stay banned even when a date and a link sit beside them.
121 /// Phrases are lowercase; callers compare a lowercased string.
122 pub const OVERCLAIMS: [&str; 5] = [
123 "replacement for cuda",
124 "everything cuda gives you",
125 "omega's replacement and its status",
126 "beating cuda",
127 "matching and then",
128 ];
129
130 /// The only sentence that may say "slower than" with no date and no link.
131 const OWNED_SLOWER: &str = "Slower than I want.";
132
133 fn is_owned_slower(s: &str) -> bool {
134 let t = s.trim();
135 t == OWNED_SLOWER || t == "Slower than I want"
136 }
137
138 fn is_real_date(year: i32, month: u32, day: u32) -> bool {
139 if !(1..=9999).contains(&year) || !(1..=12).contains(&month) || day == 0 {
140 return false;
141 }
142 let leap = year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
143 let dim = match month {
144 1 | 3 | 5 | 7 | 8 | 10 | 12 => 31,
145 4 | 6 | 9 | 11 => 30,
146 2 if leap => 29,
147 2 => 28,
148 _ => return false,
149 };
150 day <= dim
151 }
152
153 /// A real calendar date written YYYY-MM-DD. `2026-02-31` and `2026-13-01`
154 /// do not count. A digit glued on either side does not count.
155 fn has_real_iso_date(s: &str) -> bool {
156 let b = s.as_bytes();
157 if b.len() < 10 {
158 return false;
159 }
160 for i in 0..=b.len() - 10 {
161 if i > 0 && b[i - 1].is_ascii_digit() {
162 continue;
163 }
164 if i + 10 < b.len() && b[i + 10].is_ascii_digit() {
165 continue;
166 }
167 let w = &b[i..i + 10];
168 if w[4] != b'-' || w[7] != b'-' {
169 continue;
170 }
171 if !w[..4].iter().all(u8::is_ascii_digit)
172 || !w[5..7].iter().all(u8::is_ascii_digit)
173 || !w[8..10].iter().all(u8::is_ascii_digit)
174 {
175 continue;
176 }
177 let year: i32 = std::str::from_utf8(&w[..4]).unwrap().parse().unwrap();
178 let month: u32 = std::str::from_utf8(&w[5..7]).unwrap().parse().unwrap();
179 let day: u32 = std::str::from_utf8(&w[8..10]).unwrap().parse().unwrap();
180 if is_real_date(year, month, day) {
181 return true;
182 }
183 }
184 false
185 }
186
187 /// Domains that publish the other project's own numbers.
188 pub const PROJECT_SOURCE_DOMAINS: &[&str] = &[
189 "docs.vllm.ai",
190 "vllm.ai",
191 "developer.nvidia.com",
192 "pytorch.org",
193 "huggingface.co",
194 ];
195
196 /// Outside systems. "cuda" does not match when "++" follows it: CUDA++ is this project.
197 /// "nvidia" is an outside system only when the sentence compares against it
198 /// (`nvidia_is_target`). A descriptive mention ("NVIDIA GPUs", "no NVIDIA software")
199 /// does not, by itself, turn "half" or "parity" into a claim. Superlatives and
200 /// "vs" still see every token here, including a descriptive NVIDIA.
201 const PROJECT_TOKENS: &[&str] = &[
202 "cuda", "nvidia", "vllm", "llama.cpp", "llama", "tensorrt", "pytorch", "triton", "cudnn",
203 "chatgpt", "openai", "gemini", "claude", "tgi", "sglang", "cutlass",
204 "ollama", "mlx", "rocm", "groq",
205 ];
206
207 /// Multi-word rival names. "onnx runtime" is not a single token.
208 const PROJECT_PHRASES: &[&str] = &["onnx runtime"];
209
210 fn url_is_allowed(url: &str) -> bool {
211 let lower = url.to_ascii_lowercase();
212 let Some(rest) = lower
213 .strip_prefix("https://")
214 .or_else(|| lower.strip_prefix("http://"))
215 else {
216 return false;
217 };
218 let rest = rest.strip_prefix("www.").unwrap_or(rest);
219 let cut = rest.find(|c: char| c.is_whitespace() || matches!(c, '"' | '\'' | '<' | '>')).unwrap_or(rest.len());
220 let rest = &rest[..cut];
221 let (host, path) = match rest.find('/') {
222 Some(i) => (&rest[..i], &rest[i..]),
223 None => (rest, ""),
224 };
225 let host = host.split('@').next_back().unwrap_or(host);
226 let host = host.split(':').next().unwrap_or(host);
227 // My own record lives on the forge; GitHub is never a source link.
228 if (host == "interplane.io" && path.starts_with("/drakestapleton/"))
229 || (host == "aienos.com" && path.starts_with("/forge/drakestapleton/"))
230 {
231 return true;
232 }
233 PROJECT_SOURCE_DOMAINS.iter().any(|d| host == *d || host.ends_with(&format!(".{d}")))
234 }
235
236 fn each_url(s: &str, mut f: impl FnMut(&str)) {
237 let lower = s.to_ascii_lowercase();
238 let bytes = lower.as_bytes();
239 let mut i = 0;
240 while i < bytes.len() {
241 let rest = &lower[i..];
242 let http = rest.find("http://");
243 let https = rest.find("https://");
244 let at = match (http, https) {
245 (Some(a), Some(b)) => Some(a.min(b)),
246 (Some(a), None) => Some(a),
247 (None, Some(b)) => Some(b),
248 (None, None) => None,
249 };
250 let Some(at) = at else { break };
251 let start = i + at;
252 let url = &s[start..];
253 let end = url.find(|c: char| c.is_whitespace() || matches!(c, '"' | '\'' | '<' | '>')).unwrap_or(url.len());
254 f(&url[..end]);
255 i = start + end.max(1);
256 }
257 }
258
259 /// A receipt on an aien-dev host, or the other project's own domain, in this same sentence.
260 /// The bare words "receipt" and "published" are not a link. An unrelated https URL is not a source.
261 fn has_allowed_source(s: &str) -> bool {
262 let mut ok = false;
263 each_url(s, |url| {
264 if url_is_allowed(url) {
265 ok = true;
266 }
267 });
268 ok
269 }
270
271 fn is_word_char(c: char) -> bool {
272 c.is_ascii_alphanumeric() || c == '_'
273 }
274
275 fn boundary_phrase(lower: &str, phrase: &str) -> bool {
276 let mut from = 0;
277 while let Some(at) = lower[from..].find(phrase) {
278 let i = from + at;
279 let before_ok = i == 0 || !is_word_char(lower.as_bytes()[i - 1] as char);
280 let after = i + phrase.len();
281 let after_ok = after >= lower.len() || !is_word_char(lower.as_bytes()[after] as char);
282 if before_ok && after_ok {
283 return true;
284 }
285 from = i + phrase.len();
286 }
287 false
288 }
289
290 fn has_word_form(lower: &str) -> bool {
291 for word in lower.split(|c: char| !is_word_char(c)) {
292 if word.is_empty() {
293 continue;
294 }
295 if COMPARISON_WORDS.contains(&word) || COMPARISON_STEMS.iter().any(|stem| word.starts_with(stem)) {
296 return true;
297 }
298 }
299 false
300 }
301
302 /// A project token on a word boundary. "cuda" followed by "++" is CUDA++, this project, and does not count.
303 fn token_present(lower: &str, token: &str) -> bool {
304 let mut from = 0;
305 while let Some(rel) = lower[from..].find(token) {
306 let i = from + rel;
307 let before_ok = i == 0 || !is_word_char(lower[..i].chars().next_back().unwrap());
308 let after = i + token.len();
309 let after_ok = after >= lower.len() || !is_word_char(lower[after..].chars().next().unwrap());
310 let cuda_plus = token == "cuda" && lower[after..].starts_with("++");
311 if before_ok && after_ok && !cuda_plus {
312 return true;
313 }
314 from = i + token.len().max(1);
315 }
316 false
317 }
318
319 fn word_ending_at(lower: &str, at: usize) -> Option<(usize, &str)> {
320 let trimmed = lower[..at].trim_end_matches(|c: char| !is_word_char(c));
321 if trimmed.is_empty() {
322 return None;
323 }
324 let start = trimmed
325 .rfind(|c: char| !is_word_char(c))
326 .map(|i| i + trimmed[i..].chars().next().unwrap().len_utf8())
327 .unwrap_or(0);
328 Some((start, &trimmed[start..]))
329 }
330
331 /// NVIDIA is the thing being compared, not a description of hardware or a missing stack.
332 /// "faster than NVIDIA", "parity with NVIDIA", "twice NVIDIA", and "half of NVIDIA" count.
333 /// "NVIDIA GPUs", "no NVIDIA software", and "with no NVIDIA user-space" do not.
334 fn nvidia_is_target(lower: &str) -> bool {
335 const MARKERS: &[&str] = &[
336 "than", "with", "versus", "against", "vs", "of",
337 "twice", "double", "half",
338 "beat", "beats", "beating", "beaten",
339 "parity", "trails", "lags",
340 "faster", "quicker", "cheaper",
341 ];
342 let mut from = 0;
343 while let Some(rel) = lower[from..].find("nvidia") {
344 let i = from + rel;
345 let before_ok = i == 0 || !is_word_char(lower[..i].chars().next_back().unwrap());
346 let after = i + "nvidia".len();
347 let after_ok = after >= lower.len() || !is_word_char(lower[after..].chars().next().unwrap());
348 if before_ok && after_ok {
349 let mut word = word_ending_at(lower, i);
350 if matches!(word, Some((_, "the" | "a" | "an"))) {
351 if let Some((start, _)) = word {
352 word = word_ending_at(lower, start);
353 }
354 }
355 if let Some((_, w)) = word {
356 if MARKERS.contains(&w) {
357 return true;
358 }
359 }
360 }
361 from = i + "nvidia".len();
362 }
363 false
364 }
365
366 /// A comparison word other than "half", "twice" or "double". Those three stay
367 /// descriptive in "GPU half" and do not, by themselves, make a nearby NVIDIA a rival.
368 fn comparison_word_activates_nvidia(lower: &str) -> bool {
369 const WORDS: &[&str] = &[
370 "parity", "trails", "lags",
371 "beat", "beats", "beating", "beaten",
372 "match", "matches", "matching", "matched",
373 "tie", "ties", "tied",
374 "equal", "equals", "equaled", "equalled",
375 "slower", "faster", "quicker", "cheaper",
376 ];
377 if lower.split(|c: char| !is_word_char(c)).any(|word| {
378 WORDS.contains(&word)
379 || COMPARISON_WORDS.contains(&word)
380 || COMPARISON_STEMS.iter().any(|stem| word.starts_with(stem))
381 }) {
382 return true;
383 }
384 if CONTEXT_PHRASES.iter().any(|phrase| boundary_phrase(lower, phrase))
385 || TIE_PHRASES.iter().any(|phrase| boundary_phrase(lower, phrase))
386 || COMPARISON_PHRASES.iter().any(|phrase| boundary_phrase(lower, phrase))
387 || CONNECTORS.iter().any(|phrase| boundary_phrase(lower, phrase))
388 {
389 return true;
390 }
391 has_attached_comparative(lower) || has_vs(lower)
392 }
393
394 fn has_outside_system(lower: &str) -> bool {
395 if nvidia_is_target(lower) || (token_present(lower, "nvidia") && comparison_word_activates_nvidia(lower)) {
396 return true;
397 }
398 PROJECT_TOKENS.iter().any(|token| *token != "nvidia" && token_present(lower, token))
399 || PROJECT_PHRASES.iter().any(|phrase| boundary_phrase(lower, phrase))
400 }
401
402 /// Every rival name, in any position. NVIDIA counts here too. Used when the
403 /// sentence already has a connector or a `: Nx` multiplier, so a
404 /// descriptive NVIDIA sentence with no comparison word never reaches this.
405 fn names_rival(lower: &str) -> bool {
406 PROJECT_TOKENS.iter().any(|token| token_present(lower, token))
407 || PROJECT_PHRASES.iter().any(|phrase| boundary_phrase(lower, phrase))
408 || has_rival(lower)
409 }
410
411 fn has_rival(lower: &str) -> bool {
412 RIVAL_NOUNS.iter().any(|noun| boundary_phrase(lower, noun))
413 }
414
415 fn project_near(lower: &str, at: usize) -> bool {
416 let start = lower.floor_char_boundary(at.saturating_sub(48));
417 let end = lower.ceil_char_boundary((at + 48).min(lower.len()));
418 let window = &lower[start..end];
419 PROJECT_TOKENS.iter().any(|token| token_present(window, token))
420 }
421
422 /// Superlatives only when a project name sits nearby.
423 /// Bare uses ("the quickest walkthrough", "the best way") are not claims.
424 /// "twice", "double", and "half" are context-bound, not superlatives.
425 fn has_guarded_word(lower: &str) -> bool {
426 const GUARDED: &[&str] = &["best", "worst", "fastest", "slowest", "quickest"];
427 let mut from = 0;
428 while from < lower.len() {
429 let rest = &lower[from..];
430 let mut found: Option<(usize, usize)> = None;
431 for word in GUARDED {
432 if let Some(at) = rest.find(word) {
433 let i = from + at;
434 let before_ok = i == 0 || !is_word_char(lower.as_bytes()[i - 1] as char);
435 let after = i + word.len();
436 let after_ok = after >= lower.len() || !is_word_char(lower.as_bytes()[after] as char);
437 if before_ok && after_ok && found.map(|(p, _)| at < p).unwrap_or(true) {
438 found = Some((at, word.len()));
439 }
440 }
441 }
442 let Some((at, len)) = found else { break };
443 let i = from + at;
444 if project_near(lower, i) {
445 return true;
446 }
447 from = i + len;
448 }
449 false
450 }
451
452 fn has_vs(lower: &str) -> bool {
453 let b = lower.as_bytes();
454 let mut i = 0;
455 while i + 2 <= b.len() {
456 if &b[i..i + 2] == b"vs" {
457 let before = i == 0 || b[i - 1].is_ascii_whitespace();
458 let mut end = i + 2;
459 if end < b.len() && b[end] == b'.' {
460 end += 1;
461 }
462 let after_ok = end >= b.len()
463 || b[end].is_ascii_whitespace()
464 || matches!(b[end], b')' | b']' | b',' | b';' | b':' | b'!' | b'?');
465 if before && after_ok && project_near(lower, i) {
466 return true;
467 }
468 }
469 i += 1;
470 }
471 false
472 }
473
474 fn has_within_percent(lower: &str) -> bool {
475 let bytes = lower.as_bytes();
476 let mut from = 0;
477 while let Some(at) = lower[from..].find("within") {
478 let i = from + at;
479 let before_ok = i == 0 || !is_word_char(bytes[i - 1] as char);
480 let mut j = i + "within".len();
481 if !before_ok || j >= bytes.len() || !bytes[j].is_ascii_whitespace() {
482 from = i + "within".len();
483 continue;
484 }
485 while j < bytes.len() && bytes[j].is_ascii_whitespace() {
486 j += 1;
487 }
488 if j >= bytes.len() || !bytes[j].is_ascii_digit() {
489 from = i + "within".len();
490 continue;
491 }
492 while j < bytes.len() && bytes[j].is_ascii_digit() {
493 j += 1;
494 }
495 if j + 1 < bytes.len() && bytes[j] == b'.' && bytes[j + 1].is_ascii_digit() {
496 j += 2;
497 while j < bytes.len() && bytes[j].is_ascii_digit() {
498 j += 1;
499 }
500 }
501 while j < bytes.len() && bytes[j].is_ascii_whitespace() {
502 j += 1;
503 }
504 if j < bytes.len() && bytes[j] == b'%' {
505 j += 1;
506 while j < bytes.len() && bytes[j].is_ascii_whitespace() {
507 j += 1;
508 }
509 if lower[j..].starts_with("of") {
510 let after = j + 2;
511 if after >= lower.len() || !is_word_char(lower.as_bytes()[after] as char) {
512 return true;
513 }
514 }
515 }
516 from = i + "within".len();
517 }
518 false
519 }
520
521 fn is_timezone(word: &str) -> bool {
522 matches!(word, "cdt" | "cst" | "edt" | "est" | "mdt" | "mst" | "pdt" | "pst" | "utc" | "gmt")
523 }
524
525 /// `19:3x`, `~19:30` and a trailing timezone are clock tokens. They are not
526 /// multipliers. A later `3x faster` in the same sentence still counts.
527 fn is_clock_multiplier(chars: &[char], number_start: usize, after_mark: usize) -> bool {
528 if number_start > 0 && chars[number_start - 1] == ':' {
529 let mut k = number_start - 1;
530 if k > 0 {
531 k -= 1;
532 if chars[k].is_ascii_digit() {
533 let mut digits = 1usize;
534 while k > 0 && chars[k - 1].is_ascii_digit() && digits < 2 {
535 k -= 1;
536 digits += 1;
537 }
538 let before = if k == 0 { None } else { Some(chars[k - 1]) };
539 if matches!(before, None | Some('~')) || before.is_some_and(|c| c.is_whitespace()) {
540 return true;
541 }
542 }
543 }
544 }
545 let mut m = after_mark;
546 while m < chars.len() && chars[m] == ' ' {
547 m += 1;
548 }
549 if m >= chars.len() {
550 return false;
551 }
552 let rest: String = chars[m..].iter().collect();
553 let word = rest.split(|c: char| !is_word_char(c)).next().unwrap_or("");
554 is_timezone(word)
555 }
556
557 fn is_x_tail(c: char) -> bool {
558 c.is_whitespace()
559 || matches!(c, '.' | ',' | ';' | ':' | '!' | '?' | ')' | ']' | '"' | '\'' | '\u{201d}' | '\u{2019}')
560 }
561
562 fn without_urls(s: &str) -> String {
563 let mut out = String::with_capacity(s.len());
564 let mut rest = s;
565 loop {
566 let http = rest.find("http://");
567 let https = rest.find("https://");
568 let i = match (http, https) {
569 (Some(a), Some(b)) => Some(a.min(b)),
570 (Some(a), None) => Some(a),
571 (None, Some(b)) => Some(b),
572 (None, None) => None,
573 };
574 let Some(i) = i else {
575 out.push_str(rest);
576 break;
577 };
578 out.push_str(&rest[..i]);
579 rest = &rest[i..];
580 let end = rest.find(char::is_whitespace).unwrap_or(rest.len());
581 rest = &rest[end..];
582 out.push(' ');
583 }
584 out
585 }
586
587 fn negated_before(lower: &str, at: usize) -> bool {
588 let start = lower.floor_char_boundary(at.saturating_sub(48));
589 let mut window = &lower[start..at];
590 if let Some(i) = window.rfind(['.', '!', '?']) {
591 window = &window[i + 1..];
592 }
593 for word in ["not", "never", "no"] {
594 if boundary_phrase(window, word) {
595 return true;
596 }
597 }
598 false
599 }
600
601 fn phrase_claim(lower: &str) -> bool {
602 for phrase in COMPARISON_PHRASES {
603 let mut from = 0;
604 while let Some(at) = lower[from..].find(phrase) {
605 let i = from + at;
606 let before_ok = i == 0 || !is_word_char(lower.as_bytes()[i - 1] as char);
607 let after = i + phrase.len();
608 let after_ok = after >= lower.len() || !is_word_char(lower.as_bytes()[after] as char);
609 if before_ok && after_ok {
610 // "ahead of time" is an idiom, not a comparison. "ahead of NVIDIA" still is.
611 if *phrase == "ahead of" {
612 let rest = lower[after..].trim_start();
613 if rest.starts_with("time") {
614 let n = "time".len();
615 let boundary = n >= rest.len() || !is_word_char(rest[n..].chars().next().unwrap());
616 if boundary {
617 from = i + phrase.len();
618 continue;
619 }
620 }
621 }
622 let denial = (*phrase == "comparable to" || *phrase == "competitive with") && negated_before(lower, i);
623 if !denial {
624 return true;
625 }
626 }
627 from = i + phrase.len();
628 }
629 }
630 false
631 }
632
633 fn has_context_word(lower: &str) -> bool {
634 lower.split(|c: char| !is_word_char(c)).any(|word| CONTEXT_WORDS.contains(&word))
635 }
636
637 fn has_context_phrase(lower: &str) -> bool {
638 CONTEXT_PHRASES.iter().any(|phrase| boundary_phrase(lower, phrase))
639 }
640
641 fn adjective_at(rest: &str, words: &[&str]) -> bool {
642 words.iter().any(|adj| {
643 rest.starts_with(adj)
644 && (adj.len() >= rest.len() || !is_word_char(rest[adj.len()..].chars().next().unwrap()))
645 })
646 }
647
648 /// "half as fast", "2x faster", "40% cheaper", "N times faster".
649 /// A bare "2x" or "137 times" is not attached.
650 fn has_attached_comparative(lower: &str) -> bool {
651 const LOOSE: &[&str] = &[
652 "faster", "slower", "cheaper", "quicker", "more efficient",
653 "fast", "slow", "cheap", "quick", "efficient",
654 ];
655 for lead in ["half as", "twice as", "double as"] {
656 let mut from = 0;
657 while let Some(rel) = lower[from..].find(lead) {
658 let i = from + rel;
659 let before_ok = i == 0 || !is_word_char(lower[..i].chars().next_back().unwrap());
660 let after = i + lead.len();
661 let after_ok = after >= lower.len() || !is_word_char(lower[after..].chars().next().unwrap());
662 if before_ok && after_ok {
663 let rest = lower[after..].trim_start_matches(' ');
664 if adjective_at(rest, LOOSE) {
665 return true;
666 }
667 }
668 from = i + lead.len().max(1);
669 }
670 }
671 const TIGHT: &[&str] = &["faster", "slower", "cheaper", "quicker", "more efficient"];
672 let chars: Vec = lower.chars().collect();
673 let mut i = 0;
674 while i < chars.len() {
675 let start_ok = chars[i].is_ascii_digit() && (i == 0 || !is_word_char(chars[i - 1]));
676 if !start_ok {
677 i += 1;
678 continue;
679 }
680 let mut j = i + 1;
681 while j < chars.len() && chars[j].is_ascii_digit() {
682 j += 1;
683 }
684 if j + 1 < chars.len() && chars[j] == '.' && chars[j + 1].is_ascii_digit() {
685 j += 2;
686 while j < chars.len() && chars[j].is_ascii_digit() {
687 j += 1;
688 }
689 }
690 let mut k = j;
691 while k < chars.len() && chars[k] == ' ' {
692 k += 1;
693 }
694 let rest_at = |m: usize| chars[m..].iter().collect::();
695 if chars.get(k) == Some(&'%') {
696 let mut m = k + 1;
697 while m < chars.len() && chars[m] == ' ' {
698 m += 1;
699 }
700 if adjective_at(&rest_at(m), TIGHT) {
701 return true;
702 }
703 }
704 if k < chars.len() && (chars[k] == 'x' || chars[k] == '\u{00d7}') {
705 let mut m = k + 1;
706 while m < chars.len() && chars[m] == ' ' {
707 m += 1;
708 }
709 if adjective_at(&rest_at(m), TIGHT) {
710 return true;
711 }
712 }
713 if k > j {
714 let rest = rest_at(k);
715 if rest.starts_with("times") {
716 let after_times = "times".len();
717 let boundary = after_times >= rest.len()
718 || !is_word_char(rest[after_times..].chars().next().unwrap());
719 if boundary {
720 let mut m = k + "times".chars().count();
721 while m < chars.len() && chars[m] == ' ' {
722 m += 1;
723 }
724 if adjective_at(&rest_at(m), TIGHT) {
725 return true;
726 }
727 }
728 }
729 }
730 i = j;
731 }
732 false
733 }
734
735 fn has_nx_own(lower: &str) -> bool {
736 let chars: Vec = lower.chars().collect();
737 let mut i = 0;
738 while i < chars.len() {
739 let start_ok = chars[i].is_ascii_digit() && (i == 0 || !is_word_char(chars[i - 1]));
740 if !start_ok {
741 i += 1;
742 continue;
743 }
744 let mut j = i + 1;
745 while j < chars.len() && chars[j].is_ascii_digit() {
746 j += 1;
747 }
748 if j + 1 < chars.len() && chars[j] == '.' && chars[j + 1].is_ascii_digit() {
749 j += 2;
750 while j < chars.len() && chars[j].is_ascii_digit() {
751 j += 1;
752 }
753 }
754 let mut k = j;
755 while k < chars.len() && chars[k] == ' ' {
756 k += 1;
757 }
758 if k < chars.len() && (chars[k] == 'x' || chars[k] == '\u{00d7}') {
759 let mut m = k + 1;
760 while m < chars.len() && chars[m] == ' ' {
761 m += 1;
762 }
763 let rest: String = chars[m..].iter().collect();
764 for phrase in ["its own", "our own"] {
765 if rest.starts_with(phrase) {
766 let n = phrase.len();
767 let after_ok = n >= rest.len() || !is_word_char(rest[n..].chars().next().unwrap());
768 if after_ok {
769 return true;
770 }
771 }
772 }
773 }
774 i = j;
775 }
776 false
777 }
778
779 /// "faster than its own frozen starting point" and "20.3x its own baseline".
780 /// A word such as "frozen" may sit between "own" and the baseline noun.
781 fn is_self_baseline(lower: &str) -> bool {
782 for phrase in ["than its own", "than our own"] {
783 let mut from = 0;
784 while let Some(rel) = lower[from..].find(phrase) {
785 let i = from + rel;
786 let before_ok = i == 0 || !is_word_char(lower[..i].chars().next_back().unwrap());
787 let after = i + phrase.len();
788 let after_ok = after >= lower.len() || !is_word_char(lower[after..].chars().next().unwrap());
789 if before_ok && after_ok {
790 let end = (after + 80).min(lower.len());
791 let window = &lower[after..end];
792 if ["starting point", "baseline", "previous"].iter().any(|noun| boundary_phrase(window, noun)) {
793 return true;
794 }
795 }
796 from = i + phrase.len();
797 }
798 }
799 has_nx_own(lower)
800 }
801
802 /// A bare `20x`, `3 times`, or `20.3-fold` names a rival only when that rival
803 /// follows the number. "2x vLLM" and "20.3-fold vLLM" count. "Claude Max 20x plan"
804 /// does not: Claude is the product, and 20x is the plan name.
805 fn bare_multiplier_targets_rival(lower: &str) -> bool {
806 let chars: Vec = lower.chars().collect();
807 let mut i = 0;
808 while i < chars.len() {
809 let start_ok = chars[i].is_ascii_digit() && (i == 0 || !is_word_char(chars[i - 1]));
810 if !start_ok {
811 i += 1;
812 continue;
813 }
814 let mut j = i + 1;
815 while j < chars.len() && chars[j].is_ascii_digit() {
816 j += 1;
817 }
818 if j + 1 < chars.len() && chars[j] == '.' && chars[j + 1].is_ascii_digit() {
819 j += 2;
820 while j < chars.len() && chars[j].is_ascii_digit() {
821 j += 1;
822 }
823 }
824 let mut k = j;
825 while k < chars.len() && chars[k] == ' ' {
826 k += 1;
827 }
828 let mut tail_at: Option = None;
829 if chars.get(j) == Some(&'-') {
830 let rest: String = chars[j + 1..].iter().collect();
831 if rest.starts_with("fold") {
832 let after = "fold".len();
833 if after >= rest.len() || !is_word_char(rest[after..].chars().next().unwrap_or(' ')) {
834 tail_at = Some(j + 1 + "fold".chars().count());
835 }
836 }
837 }
838 if k < chars.len() && (chars[k] == 'x' || chars[k] == '\u{00d7}') {
839 let zero = chars[i..j].iter().all(|c| *c == '0' || *c == '.');
840 let hex = zero && chars[k] == 'x';
841 if !hex {
842 let after = k + 1;
843 if (after >= chars.len() || is_x_tail(chars[after])) && !is_clock_multiplier(&chars, i, after) {
844 tail_at = Some(after);
845 }
846 }
847 }
848 if k > j {
849 let rest: String = chars[k..].iter().collect();
850 if rest.starts_with("times") {
851 let after = "times".len();
852 if after >= rest.len() || !is_word_char(rest[after..].chars().next().unwrap_or(' ')) {
853 tail_at = Some(k + "times".chars().count());
854 }
855 }
856 }
857 if let Some(at) = tail_at {
858 let tail: String = chars[at..].iter().collect();
859 if names_rival(&tail) {
860 return true;
861 }
862 }
863 i = j;
864 }
865 false
866 }
867
868 fn has_tie(lower: &str) -> bool {
869 lower.split(|c: char| !is_word_char(c)).any(|word| TIE_WORDS.contains(&word))
870 || TIE_PHRASES.iter().any(|phrase| boundary_phrase(lower, phrase))
871 }
872
873 fn has_multiplier(lower: &str) -> bool {
874 let chars: Vec = lower.chars().collect();
875 let mut i = 0;
876 while i < chars.len() {
877 if !(chars[i].is_ascii_digit() && (i == 0 || !is_word_char(chars[i - 1]))) {
878 i += 1;
879 continue;
880 }
881 let mut j = i + 1;
882 while j < chars.len() && chars[j].is_ascii_digit() {
883 j += 1;
884 }
885 if j + 1 < chars.len() && chars[j] == '.' && chars[j + 1].is_ascii_digit() {
886 j += 2;
887 while j < chars.len() && chars[j].is_ascii_digit() {
888 j += 1;
889 }
890 }
891 let mut k = j;
892 while k < chars.len() && chars[k] == ' ' {
893 k += 1;
894 }
895 if k < chars.len() && (chars[k] == 'x' || chars[k] == '\u{00d7}') {
896 let after = k + 1;
897 if after >= chars.len() || is_x_tail(chars[after]) {
898 let zero = chars[i..j].iter().all(|c| *c == '0' || *c == '.');
899 if !(zero && chars[k] == 'x') && !is_clock_multiplier(&chars, i, after) {
900 return true;
901 }
902 }
903 }
904 if chars.get(j) == Some(&'-') {
905 let rest: String = chars[j + 1..].iter().collect();
906 if rest.starts_with("fold") {
907 let n = "fold".len();
908 if n >= rest.len() || !is_word_char(rest[n..].chars().next().unwrap_or(' ')) {
909 return true;
910 }
911 }
912 }
913 if k > j {
914 let rest: String = chars[k..].iter().collect();
915 if rest.starts_with("times") {
916 let n = "times".len();
917 if n >= rest.len() || !is_word_char(rest[n..].chars().next().unwrap_or(' ')) {
918 return true;
919 }
920 }
921 }
922 i = j;
923 }
924 false
925 }
926
927 /// `: Nx`, including `llama.cpp: 1.8x` and `speedup over vLLM: 2x`.
928 /// The rival sits before the colon. A colon that is not followed by a multiplier
929 /// is not this form, so "Game 2: Beat the memorizer" is not a multiplier claim.
930 fn colon_nx_targets_rival(lower: &str) -> bool {
931 let chars: Vec = lower.chars().collect();
932 let mut i = 0;
933 while i < chars.len() {
934 if chars[i] != ':' {
935 i += 1;
936 continue;
937 }
938 let mut k = i + 1;
939 while k < chars.len() && chars[k] == ' ' {
940 k += 1;
941 }
942 if k >= chars.len() || !chars[k].is_ascii_digit() {
943 i += 1;
944 continue;
945 }
946 let mut j = k + 1;
947 while j < chars.len() && chars[j].is_ascii_digit() {
948 j += 1;
949 }
950 if j + 1 < chars.len() && chars[j] == '.' && chars[j + 1].is_ascii_digit() {
951 j += 2;
952 while j < chars.len() && chars[j].is_ascii_digit() {
953 j += 1;
954 }
955 }
956 let mut m = j;
957 while m < chars.len() && chars[m] == ' ' {
958 m += 1;
959 }
960 let times = m < chars.len() && (chars[m] == 'x' || chars[m] == '\u{00d7}');
961 if !times || is_clock_multiplier(&chars, k, m + 1) {
962 i += 1;
963 continue;
964 }
965 let after = m + 1;
966 if after < chars.len() && !is_x_tail(chars[after]) {
967 i += 1;
968 continue;
969 }
970 let before: String = chars[..i].iter().collect();
971 if names_rival(&before) {
972 return true;
973 }
974 i += 1;
975 }
976 false
977 }
978
979 fn has_connector(lower: &str) -> bool {
980 CONNECTORS.iter().any(|phrase| boundary_phrase(lower, phrase)) && names_rival(lower)
981 }
982
983 fn context_is_claim(lower: &str) -> bool {
984 let tie = has_tie(lower);
985 let word_or_phrase = has_context_word(lower) || has_context_phrase(lower) || tie;
986 let attached = has_attached_comparative(lower);
987 let aimed = bare_multiplier_targets_rival(lower) || colon_nx_targets_rival(lower);
988 if !word_or_phrase && !attached && !aimed {
989 return false;
990 }
991 if is_self_baseline(lower) && !has_outside_system(lower) && !has_rival(lower) {
992 return false;
993 }
994 if attached {
995 return true;
996 }
997 let bar = lower.contains("best measured cuda number");
998 if word_or_phrase && (has_outside_system(lower) || has_rival(lower) || (tie && (bar || has_multiplier(lower)))) {
999 return true;
1000 }
1001 aimed
1002 }
1003
1004 fn is_comparison_claim(s: &str) -> bool {
1005 let scanned = without_urls(&s.to_ascii_lowercase());
1006 if phrase_claim(&scanned)
1007 || has_word_form(&scanned)
1008 || has_guarded_word(&scanned)
1009 || has_vs(&scanned)
1010 || has_connector(&scanned)
1011 || has_within_percent(&scanned)
1012 {
1013 return true;
1014 }
1015 context_is_claim(&scanned)
1016 }
1017
1018 /// One exact sentence the checker allows, with the source and the reason.
1019 /// A different wording is not on the list, so it is checked like any other sentence.
1020 struct FixedSentence {
1021 sentence: &'static str,
1022 source: &'static str,
1023 reason: &'static str,
1024 /// The omega page prints these bars as `Done when: {sentence}`.
1025 done_when_prefix: bool,
1026 /// Dist paths where this exact sentence is allowed. `public/` and a
1027 /// trailing slash are the same page. A llms.txt catalogue line is allowed
1028 /// only when its URL maps to one of these pages.
1029 pages: &'static [&'static str],
1030 }
1031
1032 /// Published chemistry results, scoped to the scholar page.
1033 /// Removed Omega performance, benchmark and letter comparisons are not allowances.
1034 /// The chemistry sentences match only as written. They are the scholar body in
1035 /// public/data/engineer.json; each source link follows its result.
1036 const FIXED_SENTENCES: &[FixedSentence] = &[
1037 FixedSentence {
1038 sentence: "Platinum deposited this way outperformed organic-solvent materials in photocatalytic dye degradation.",
1039 source: "https://doi.org/10.3762/bjnano.10.71",
1040 reason: "published chemistry result, sourced in the next paragraph",
1041 done_when_prefix: false,
1042 pages: &["engineer/scholar/index.html"],
1043 },
1044 FixedSentence {
1045 sentence: "Ionic-liquid synthesis outperformed organic-solvent routes in photocatalytic methylene blue degradation.",
1046 source: "https://digitalcommons.wku.edu/theses/2101/",
1047 reason: "published chemistry result, sourced in the next paragraph",
1048 done_when_prefix: false,
1049 pages: &["engineer/scholar/index.html"],
1050 },
1051 ];
1052
1053 /// Game title. It names a memorizer, not another project's system.
1054 const TURING_GAME_SENTENCE: &str = "Game 2: Beat the memorizer";
1055
1056 fn plain_sentence(s: &str) -> String {
1057 s.replace("'", "'")
1058 .replace("'", "'")
1059 .replace("'", "'")
1060 .split_whitespace()
1061 .collect::>()
1062 .join(" ")
1063 }
1064
1065 /// A dist path, a `public/` path, and a directory path are one page.
1066 fn normalize_page(path: &str) -> String {
1067 let path = path.trim().replace('\\', "/");
1068 let path = path.strip_prefix("./").unwrap_or(&path);
1069 let path = path.strip_prefix("public/").unwrap_or(path);
1070 let path = path.trim_start_matches('/');
1071 if path.is_empty() {
1072 return String::new();
1073 }
1074 if path.ends_with('/') {
1075 return format!("{path}index.html");
1076 }
1077 if !path.contains('.') {
1078 return format!("{path}/index.html");
1079 }
1080 path.to_string()
1081 }
1082
1083 fn page_is(page: &str, allowed: &str) -> bool {
1084 normalize_page(page) == normalize_page(allowed)
1085 }
1086
1087 /// `llms.txt` writes `- [Name](https://...): {sentence}`. Returns that sentence
1088 /// only when the URL maps to `page`. A different page's entry does not match.
1089 fn llms_catalogue_sentence<'a>(page: &str, prepared: &'a str) -> Option<&'a str> {
1090 let (target, body) = catalogue_parts(prepared)?;
1091 if page_is(page, &target) { Some(body) } else { None }
1092 }
1093
1094 /// The page an llms.txt catalogue line points at, and the sentence after it.
1095 fn catalogue_parts(prepared: &str) -> Option<(String, &str)> {
1096 let rest = prepared.strip_prefix("- [")?;
1097 let marker = rest.find("](https://")?;
1098 let after = &rest[marker + 2..];
1099 let split = after.find("): ")?;
1100 let url = &after[..split];
1101 if !url.starts_with("https://") || url.chars().any(char::is_whitespace) {
1102 return None;
1103 }
1104 let target = map_aienos_page(url)?;
1105 Some((target, &after[split + 3..]))
1106 }
1107
1108 fn sentence_page(file_page: &str, prepared: &str) -> String {
1109 if let Some((target, _)) = catalogue_parts(prepared) {
1110 return target;
1111 }
1112 normalize_page(file_page)
1113 }
1114
1115 fn is_fixed_sentence(page: &str, s: &str) -> bool {
1116 let n = plain_sentence(s);
1117 if n == TURING_GAME_SENTENCE {
1118 return true;
1119 }
1120 let here = normalize_page(page);
1121 if let Some(body) = llms_catalogue_sentence(&here, &n) {
1122 if FIXED_SENTENCES.iter().any(|row| {
1123 body == row.sentence && row.pages.iter().any(|allowed| page_is(&here, allowed))
1124 }) {
1125 return true;
1126 }
1127 }
1128 FIXED_SENTENCES.iter().any(|row| {
1129 let bare = n == row.sentence
1130 || (row.done_when_prefix && n == format!("Done when: {}", row.sentence));
1131 bare && row.pages.iter().any(|allowed| page_is(&here, allowed))
1132 })
1133 }
1134
1135 /// `None` when the text is not a comparison, or is one honest sentence
1136 /// with a real ISO date and a source link. Overclaims always return
1137 /// "overclaim". A comparison with no date or no link in this same text
1138 /// returns "unsourced comparison".
1139 fn decode_nbsp(s: &str) -> String {
1140 let lower = s.to_ascii_lowercase();
1141 let mut out = String::with_capacity(s.len());
1142 let mut i = 0;
1143 while i < s.len() {
1144 let ch = s[i..].chars().next().unwrap();
1145 if ch == '\u{00a0}' {
1146 out.push(' ');
1147 i += ch.len_utf8();
1148 continue;
1149 }
1150 let rest = &lower[i..];
1151 let entity = [" ", " ", " ", " "]
1152 .into_iter()
1153 .find(|entity| rest.starts_with(entity));
1154 if let Some(entity) = entity {
1155 out.push(' ');
1156 i += entity.len();
1157 continue;
1158 }
1159 out.push(ch);
1160 i += ch.len_utf8();
1161 }
1162 out
1163 }
1164
1165 fn strip_tags_to_space(s: &str) -> String {
1166 if !s.contains('<') {
1167 return s.to_string();
1168 }
1169 let mut out = String::with_capacity(s.len());
1170 let mut rest = s;
1171 while let Some(start) = rest.find('<') {
1172 out.push_str(&rest[..start]);
1173 if let Some(end) = rest[start..].find('>') {
1174 out.push(' ');
1175 rest = &rest[start + end + 1..];
1176 } else {
1177 out.push_str(&rest[start..]);
1178 return out;
1179 }
1180 }
1181 out.push_str(rest);
1182 out
1183 }
1184
1185 /// NBSP and ` ` become spaces, inline tags become spaces, and whitespace collapses.
1186 fn prepare_sentence(s: &str) -> String {
1187 decode_nbsp(&strip_tags_to_space(s))
1188 .split_whitespace()
1189 .collect::>()
1190 .join(" ")
1191 }
1192
1193 /// "replacement for" then a CUDA token within four words. A period, semicolon,
1194 /// colon, comma, parenthesis, em dash or en dash in that gap ends the search.
1195 /// "not a replacement" and "isn't a replacement" are not the claim.
1196 /// "replacement for the CUDA user stack" and "a replacement for CUDA" are
1197 /// the same overclaim. CUDA++ is this project's GPU half.
1198 fn replacement_for_cuda(lower: &str) -> bool {
1199 let phrase = "replacement for";
1200 let mut from = 0;
1201 while let Some(rel) = lower[from..].find(phrase) {
1202 let i = from + rel;
1203 let before_ok = i == 0 || !is_word_char(lower.as_bytes()[i - 1] as char);
1204 let after = i + phrase.len();
1205 let after_ok = after >= lower.len() || !is_word_char(lower.as_bytes()[after] as char);
1206 if before_ok && after_ok && !replacement_is_negated(lower, i) && cuda_within_four_words(&lower[after..]) {
1207 return true;
1208 }
1209 from = i + phrase.len().max(1);
1210 }
1211 false
1212 }
1213
1214 /// The word immediately before "replacement", skipping one "a", "an" or "the".
1215 fn replacement_is_negated(lower: &str, phrase_at: usize) -> bool {
1216 let Some((start, end)) = previous_word_span(lower, phrase_at) else {
1217 return false;
1218 };
1219 let mut word = &lower[start..end];
1220 if matches!(word, "a" | "an" | "the") {
1221 let Some((start, end)) = previous_word_span(lower, start) else {
1222 return false;
1223 };
1224 word = &lower[start..end];
1225 }
1226 matches!(word, "not" | "isn't" | "isnt")
1227 }
1228
1229 fn previous_word_span(lower: &str, at: usize) -> Option<(usize, usize)> {
1230 let mut i = at;
1231 while i > 0 {
1232 let ch = lower[..i].chars().next_back()?;
1233 if negation_word_char(ch) {
1234 break;
1235 }
1236 i -= ch.len_utf8();
1237 }
1238 if i == 0 {
1239 return None;
1240 }
1241 let end = i;
1242 while i > 0 {
1243 let ch = lower[..i].chars().next_back()?;
1244 if !negation_word_char(ch) {
1245 break;
1246 }
1247 i -= ch.len_utf8();
1248 }
1249 Some((i, end))
1250 }
1251
1252 fn negation_word_char(c: char) -> bool {
1253 is_word_char(c) || c == '\''
1254 }
1255
1256 /// At most four words between "for" and the CUDA token. Zero words counts:
1257 /// "replacement for CUDA" is the claim. A clause break stops the gap,
1258 /// including an en dash.
1259 fn cuda_within_four_words(tail: &str) -> bool {
1260 let mut words = 0u32;
1261 let mut i = 0;
1262 while i < tail.len() {
1263 let c = tail[i..].chars().next().unwrap();
1264 let clen = c.len_utf8();
1265 if c.is_whitespace() {
1266 i += clen;
1267 continue;
1268 }
1269 if matches!(c, '.' | ';' | ':' | ',' | '(' | ')') || c == '\u{2014}' || c == '\u{2013}' {
1270 return false;
1271 }
1272 if tail[i..].starts_with("cuda") {
1273 let after = i + "cuda".len();
1274 let before_ok = i == 0 || !is_word_char(tail[..i].chars().next_back().unwrap());
1275 let next = tail[after..].chars().next();
1276 let plus = tail[after..].starts_with("++");
1277 let after_ok = next.map(|ch| !is_word_char(ch)).unwrap_or(true);
1278 if before_ok && after_ok && !plus {
1279 return words <= 4;
1280 }
1281 }
1282 if is_word_char(c) {
1283 words += 1;
1284 if words > 4 {
1285 return false;
1286 }
1287 i += clen;
1288 while i < tail.len() {
1289 let n = tail[i..].chars().next().unwrap();
1290 if !is_word_char(n) {
1291 break;
1292 }
1293 i += n.len_utf8();
1294 }
1295 continue;
1296 }
1297 i += clen;
1298 }
1299 false
1300 }
1301
1302 /// "beating cuda" is an overclaim. "beating cuda++" is this project's GPU half, not that claim.
1303 fn has_overclaim(lower: &str) -> bool {
1304 for w in OVERCLAIMS {
1305 if w == "beating cuda" {
1306 let mut from = 0;
1307 while let Some(at) = lower[from..].find(w) {
1308 let i = from + at;
1309 let before_ok = i == 0 || !is_word_char(lower[..i].chars().next_back().unwrap());
1310 let after = i + w.len();
1311 let plus = lower[after..].starts_with("++");
1312 let after_ok = after >= lower.len() || !is_word_char(lower[after..].chars().next().unwrap());
1313 if before_ok && after_ok && !plus {
1314 return true;
1315 }
1316 from = i + w.len();
1317 }
1318 continue;
1319 }
1320 if w == "replacement for cuda" {
1321 if replacement_for_cuda(lower) {
1322 return true;
1323 }
1324 continue;
1325 }
1326 if lower.contains(w) {
1327 return true;
1328 }
1329 }
1330 false
1331 }
1332
1333 pub fn comparison_problem(s: &str) -> Option<&'static str> {
1334 comparison_problem_on("", s)
1335 }
1336
1337 /// Same check as `comparison_problem`, on one page. An exact fixed sentence
1338 /// is allowed only on a page named by that sentence. A llms.txt line uses the
1339 /// page its catalogue URL maps to. Any other wording stays banned.
1340 pub fn comparison_problem_on(page: &str, s: &str) -> Option<&'static str> {
1341 let prepared = prepare_sentence(s);
1342 let lower = prepared.to_ascii_lowercase();
1343 let page = sentence_page(page, &prepared);
1344 if is_owned_slower(&prepared) || is_fixed_sentence(&page, &prepared) {
1345 return None;
1346 }
1347 if has_overclaim(&lower) {
1348 return Some("overclaim");
1349 }
1350 if is_comparison_claim(&prepared) && !(has_real_iso_date(&prepared) && has_allowed_source(&prepared)) {
1351 return Some("unsourced comparison");
1352 }
1353 None
1354 }
1355
1356 fn href_in_tag(tag: &str) -> Option<&str> {
1357 let tag_l = tag.to_ascii_lowercase();
1358 for key in ["href=\"", "href='"] {
1359 if let Some(i) = tag_l.find(key) {
1360 let value = &tag[i + key.len()..];
1361 let quote = if key.ends_with('"') { '"' } else { '\'' };
1362 let end = value.find(quote)?;
1363 return Some(&value[..end]);
1364 }
1365 }
1366 None
1367 }
1368
1369 fn closes_block(tag_l: &str) -> bool {
1370 tag_l.starts_with("
bool {
1384 matches!(
1385 open_name(tag_l),
1386 Some(
1387 "a" | "abbr" | "b" | "bdi" | "bdo" | "br" | "cite" | "code" | "data" | "dfn" | "em" | "i"
1388 | "mark" | "q" | "s" | "small" | "span" | "strong" | "sub" | "sup" | "time" | "u"
1389 | "var" | "wbr"
1390 )
1391 )
1392 }
1393
1394 fn open_name(tag_l: &str) -> Option<&str> {
1395 let t = tag_l.strip_prefix('<')?;
1396 if t.starts_with('/') || t.starts_with('!') {
1397 return None;
1398 }
1399 let end = t.find(|c: char| !c.is_ascii_alphanumeric()).unwrap_or(t.len());
1400 if end == 0 {
1401 return None;
1402 }
1403 Some(&t[..end])
1404 }
1405
1406 /// Skip a balanced element. `rest` begins just after the opening tag.
1407 fn skip_balanced<'a>(rest: &'a str, name: &str) -> &'a str {
1408 let lower = rest.to_ascii_lowercase();
1409 let open = format!("<{name}");
1410 let close = format!("{name}");
1411 let mut depth = 1usize;
1412 let mut i = 0usize;
1413 while depth > 0 && i < lower.len() {
1414 let rel_open = lower[i..].find(&open);
1415 let rel_close = lower[i..].find(&close);
1416 match (rel_open, rel_close) {
1417 (Some(o), Some(c)) if o < c => {
1418 depth += 1;
1419 i += o + open.len();
1420 }
1421 (_, Some(c)) => {
1422 depth -= 1;
1423 i += c + close.len();
1424 if depth == 0 {
1425 let after = rest.get(i..).unwrap_or("");
1426 let gt = after.find('>').map(|n| n + 1).unwrap_or(0);
1427 return after.get(gt..).unwrap_or("");
1428 }
1429 }
1430 _ => return "",
1431 }
1432 }
1433 ""
1434 }
1435
1436 /// Ledger and roster classes. `data-verbatim` alone does not opt out.
1437 const VERBATIM_CLASSES: &[&str] = &[
1438 "now-item",
1439 "now-note",
1440 "now-done",
1441 "now-queue-item",
1442 "now-tl-item",
1443 "now-tl-evidence",
1444 "now-model-role",
1445 "agents-verbatim",
1446 ];
1447
1448 fn has_verbatim_class(tag: &str) -> bool {
1449 let lower = tag.to_ascii_lowercase();
1450 let Some(i) = lower.find("class=") else { return false };
1451 let rest = &tag[i + 6..];
1452 let Some(quote) = rest.chars().next() else { return false };
1453 if quote != '"' && quote != '\'' {
1454 return false;
1455 }
1456 let rest = &rest[1..];
1457 let end = rest.find(quote).unwrap_or(rest.len());
1458 rest[..end].split_whitespace().any(|c| VERBATIM_CLASSES.iter().any(|v| c.eq_ignore_ascii_case(v)))
1459 }
1460
1461 /// Program text in `pre` (and therefore `pre > code`) is not prose.
1462 /// A bare inline `` is prose. `data-verbatim` opts out only for the fixed class list.
1463 fn skip_whole_element(tag: &str, tag_l: &str) -> bool {
1464 matches!(
1465 open_name(tag_l),
1466 Some("script" | "style" | "pre" | "textarea" | "kbd" | "samp")
1467 ) || has_verbatim_class(tag)
1468 }
1469
1470 /// Keep link targets, drop tags, and break on block ends so a date in one
1471 /// element does not license a claim in the next. Script, style, comments,
1472 /// program text (`pre`, so `pre > code`, plus `textarea`, `kbd`, `samp`), and a
1473 /// fixed verbatim class are not page prose. Inline `code` is prose.
1474 fn readable_text(text: &str) -> String {
1475 if !text.contains('<') {
1476 return text.to_string();
1477 }
1478 let mut out = String::with_capacity(text.len());
1479 let mut rest = text;
1480 while let Some(start) = rest.find('<') {
1481 out.push_str(&rest[..start]);
1482 rest = &rest[start..];
1483 if rest.starts_with("").map(|end| &rest[end + 3..]).unwrap_or("");
1485 continue;
1486 }
1487 let Some(end) = rest.find('>') else {
1488 out.push_str(rest);
1489 return out;
1490 };
1491 let tag = &rest[..=end];
1492 let tag_l = tag.to_ascii_lowercase();
1493 if !tag_l.ends_with("/>") && skip_whole_element(tag, &tag_l) {
1494 if let Some(name) = open_name(&tag_l) {
1495 rest = skip_balanced(&rest[end + 1..], name);
1496 continue;
1497 }
1498 }
1499 if let Some(url) = href_in_tag(tag) {
1500 out.push(' ');
1501 out.push_str(url);
1502 out.push(' ');
1503 }
1504 if is_inline_join(&tag_l) {
1505 out.push(' ');
1506 }
1507 if closes_block(&tag_l) {
1508 out.push('\n');
1509 }
1510 rest = &rest[end + 1..];
1511 }
1512 out.push_str(rest);
1513 out
1514 }
1515
1516 fn is_closer(c: char) -> bool {
1517 matches!(c, ')' | ']' | '"' | '\'' | '\u{201d}' | '\u{2019}')
1518 }
1519
1520 /// A sentence ends at `.`, `!`, or `?` followed by whitespace, or at the
1521 /// end of the text. A closing `)` or quote may sit between the mark and
1522 /// the whitespace. The next sentence may start with a digit or a lowercase
1523 /// letter. A mark with no whitespace after it stays inside the sentence,
1524 /// so llama.cpp, URLs, and 21.95 stay whole.
1525 fn split_sentences(text: &str) -> Vec {
1526 let chars: Vec = text.chars().collect();
1527 let mut out = Vec::new();
1528 let mut cur = String::new();
1529 let mut i = 0;
1530 while i < chars.len() {
1531 let c = chars[i];
1532 if matches!(c, '.' | '!' | '?') {
1533 let mut j = i + 1;
1534 while j < chars.len() && is_closer(chars[j]) {
1535 j += 1;
1536 }
1537 if j >= chars.len() || chars[j].is_whitespace() {
1538 for ch in chars.iter().take(j).skip(i) {
1539 cur.push(*ch);
1540 }
1541 let sentence = cur.trim().to_string();
1542 if !sentence.is_empty() {
1543 out.push(sentence);
1544 }
1545 cur.clear();
1546 i = j;
1547 while i < chars.len() && chars[i].is_whitespace() {
1548 i += 1;
1549 }
1550 continue;
1551 }
1552 }
1553 cur.push(c);
1554 i += 1;
1555 }
1556 let sentence = cur.trim().to_string();
1557 if !sentence.is_empty() {
1558 out.push(sentence);
1559 }
1560 out
1561 }
1562
1563 /// Sentence-sized check. A date or a link in another sentence does not
1564 /// license a comparison in this one.
1565 pub fn comparison_errors(text: &str) -> Vec {
1566 comparison_errors_on("", text)
1567 }
1568
1569 fn comparison_errors_on(page: &str, text: &str) -> Vec {
1570 let mut errors = Vec::new();
1571 // Block ends already become newlines in `readable_text`. A newline ends a
1572 // sentence so a claim in the next block does not inherit the previous line.
1573 for line in readable_text(text).split('\n') {
1574 for sentence in split_sentences(line) {
1575 if let Some(kind) = comparison_problem_on(page, &sentence) {
1576 errors.push(format!("{kind} in {sentence:?}"));
1577 }
1578 }
1579 }
1580 errors
1581 }
1582
1583 /// Published papers and receipts, by exact repo path. Live pages are not on
1584 /// this list: `/omega/`, `omega.json`, and the `/engineer/` tree are scanned.
1585 /// A path matches only when the whole string equals an entry.
1586 pub const PROSE_EXEMPT_PATHS: &[&str] = &[
1587 "public/engineer/papers/the-continuation-test.md",
1588 "crates/site-builder/data/models.json",
1589 "public/research/aien-research-plan.md",
1590 "public/research/computing-machinery-and-understanding-emergence/index.html",
1591 "public/research/the-stapleton-doctrine/index.html",
1592 ];
1593
1594 pub fn is_prose_exempt(path: &str) -> bool {
1595 let norm = path.replace('\\', "/");
1596 PROSE_EXEMPT_PATHS.contains(&norm.as_str())
1597 }
1598
1599 /// Same check as `comparison_errors`, except a path on `PROSE_EXEMPT_PATHS` is skipped.
1600 pub fn comparison_errors_at(path: &str, text: &str) -> Vec {
1601 if is_prose_exempt(path) {
1602 Vec::new()
1603 } else {
1604 comparison_errors_on(path, text)
1605 }
1606 }
1607
1608 fn section_is_exempt(rel: &str) -> bool {
1609 is_prose_exempt(&format!("public/{rel}")) || is_prose_exempt(rel)
1610 }
1611
1612 /// `https://www.aienos.com/now/` becomes `now/index.html`. Anything else is unmapped.
1613 fn map_aienos_page(url: &str) -> Option {
1614 let url = url.trim().trim_end_matches(|c: char| c == '.' || c == ')');
1615 let rest = url
1616 .strip_prefix("https://www.aienos.com")
1617 .or_else(|| url.strip_prefix("http://www.aienos.com"))
1618 .or_else(|| url.strip_prefix("https://aienos.com"))
1619 .or_else(|| url.strip_prefix("http://aienos.com"))?;
1620 let path = rest.split(['?', '#', ' ']).next().unwrap_or("");
1621 if !path.is_empty() && !path.starts_with('/') {
1622 return None;
1623 }
1624 let rel = path.trim_matches('/');
1625 if rel.is_empty() {
1626 Some("index.html".to_string())
1627 } else if rel.ends_with(".html") || rel.ends_with(".md") || rel.ends_with(".json") || rel.ends_with(".tsv") {
1628 Some(rel.to_string())
1629 } else {
1630 Some(format!("{rel}/index.html"))
1631 }
1632 }
1633
1634 fn norm_ws(s: &str) -> String {
1635 s.split_whitespace().collect::>().join(" ").to_ascii_lowercase()
1636 }
1637
1638 /// Fields from the public ledger long enough to identify a row. A sentence that
1639 /// contains one of these is that row, not a new claim on the page.
1640 fn ledger_fields(ledger: &str) -> Vec {
1641 let mut out = Vec::new();
1642 for line in ledger.lines() {
1643 for field in line.split('\t') {
1644 let n = norm_ws(field);
1645 if n.chars().count() >= 40 {
1646 out.push(n);
1647 }
1648 }
1649 }
1650 out
1651 }
1652
1653 fn is_ledger_excerpt(sentence: &str, fields: &[String]) -> bool {
1654 let s = norm_ws(sentence);
1655 let n = s.chars().count();
1656 if n < 40 {
1657 return false;
1658 }
1659 fields.iter().any(|field| s.contains(field.as_str()) || field.contains(s.as_str()))
1660 }
1661
1662 /// `llms-full.txt` is one file with one section per page. Each section is
1663 /// checked under its own source path. An exempt paper, receipt or ledger
1664 /// section is skipped. A sentence copied from the public ledger stays with
1665 /// the ledger. A section with no mappable source fails closed. A second
1666 /// `Source:` line stays on the first path and is an error. `Published:` is
1667 /// skipped only when it is the header line directly after `Source:`. The
1668 /// file as a whole is not exempt.
1669 fn push_line_problems(problems: &mut Vec, n: usize, label: &str, line: &str, fields: &[String]) {
1670 if is_ledger_excerpt(line, fields) {
1671 return;
1672 }
1673 for sentence in split_sentences(line) {
1674 if is_ledger_excerpt(&sentence, fields) {
1675 continue;
1676 }
1677 if let Some(kind) = comparison_problem_on(label, &sentence) {
1678 problems.push(format!("llms-full.txt:{n} ({label}): {kind} in {sentence:?}"));
1679 }
1680 }
1681 }
1682
1683 /// `Published: YYYY-MM-DD. Last changed: .` as `seo::llms_full` writes it.
1684 /// The timestamp is `YYYY-MM-DDTHH:MM:SSZ` or the same clock with a numeric offset.
1685 fn is_published_header(line: &str) -> bool {
1686 let Some(rest) = line.strip_prefix("Published: ") else {
1687 return false;
1688 };
1689 let Some((date, changed)) = rest.split_once(". Last changed: ") else {
1690 return false;
1691 };
1692 let Some(stamp) = changed.strip_suffix('.') else {
1693 return false;
1694 };
1695 is_exact_iso_date(date) && is_exact_timestamp(stamp)
1696 }
1697
1698 fn is_exact_iso_date(s: &str) -> bool {
1699 let b = s.as_bytes();
1700 if b.len() != 10 || b[4] != b'-' || b[7] != b'-' {
1701 return false;
1702 }
1703 if !b[..4].iter().all(u8::is_ascii_digit)
1704 || !b[5..7].iter().all(u8::is_ascii_digit)
1705 || !b[8..10].iter().all(u8::is_ascii_digit)
1706 {
1707 return false;
1708 }
1709 let Ok(year) = s[..4].parse::() else {
1710 return false;
1711 };
1712 let Ok(month) = s[5..7].parse::() else {
1713 return false;
1714 };
1715 let Ok(day) = s[8..10].parse::() else {
1716 return false;
1717 };
1718 is_real_date(year, month, day)
1719 }
1720
1721 fn is_exact_timestamp(s: &str) -> bool {
1722 let b = s.as_bytes();
1723 if b.len() != 20 && b.len() != 25 {
1724 return false;
1725 }
1726 if !is_exact_iso_date(&s[..10]) || b[10] != b'T' || !is_hh_mm_ss(&b[11..19]) {
1727 return false;
1728 }
1729 if b.len() == 20 {
1730 return b[19] == b'Z';
1731 }
1732 (b[19] == b'+' || b[19] == b'-')
1733 && b[22] == b':'
1734 && is_two_digits(&b[20..22], 23)
1735 && is_two_digits(&b[23..25], 59)
1736 }
1737
1738 fn is_hh_mm_ss(b: &[u8]) -> bool {
1739 b.len() == 8
1740 && b[2] == b':'
1741 && b[5] == b':'
1742 && is_two_digits(&b[0..2], 23)
1743 && is_two_digits(&b[3..5], 59)
1744 && is_two_digits(&b[6..8], 59)
1745 }
1746
1747 fn is_two_digits(b: &[u8], max: u32) -> bool {
1748 if b.len() != 2 || !b.iter().all(u8::is_ascii_digit) {
1749 return false;
1750 }
1751 let Ok(n) = std::str::from_utf8(b).unwrap_or("").parse::() else {
1752 return false;
1753 };
1754 n <= max
1755 }
1756
1757 pub fn llms_full_problems(text: &str, ledger: &str) -> Vec {
1758 let fields = ledger_fields(ledger);
1759 let mut problems = Vec::new();
1760 // None: file banner, before the first section. Some(None): section not yet
1761 // mapped. Some(Some(path)): mapped page.
1762 let mut section: Option