interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / crates / allen-reflex-kernel / src / pool.rs

59 lines · 2239 bytes Raw Blame History
1//! The training pool compiled into the image: the exam train split plus ALLEN's own contract cases,
2//! the same pool `crates/allen-reflex/examples/common::pool()` builds (train first, then extra, file
3//! order). Dev and held-out cases are never part of it.
4
5use allen_reflex::Action;
6
7/// `docs/native/pi5-8/orchestrator-exam/cases-train.psv` (id|category|action|text|turns).
8pub const TRAIN_PSV: &str =
9 include_str!("../../../docs/native/pi5-8/orchestrator-exam/cases-train.psv");
10/// `docs/native/pi5-8/orchestrator-exam/cases-reflex-extra.psv` (id|family|category|action|text|turns|source).
11pub const EXTRA_PSV: &str =
12 include_str!("../../../docs/native/pi5-8/orchestrator-exam/cases-reflex-extra.psv");
13
14/// One labelled training example (borrowed from the compiled-in text).
15#[derive(Clone, Copy, Debug)]
16pub struct Example {
17 /// label
18 pub action: Action,
19 /// expected argument text, empty when none
20 pub text: &'static str,
21 /// the exam's turns field
22 pub turns: &'static str,
23}
24
25/// Call `f` on every pool example in training order. `Err` names a malformed line.
26pub fn for_each(mut f: impl FnMut(Example)) -> Result<usize, &'static str> {
27 let mut n = 0;
28 for (src, fields) in [(TRAIN_PSV, 5usize), (EXTRA_PSV, 7usize)] {
29 for line in src.lines() {
30 if line.starts_with('#') || line.trim().is_empty() {
31 continue;
32 }
33 let mut it = line.splitn(fields, '|');
34 let mut col = [""; 7];
35 let mut k = 0;
36 for c in it.by_ref() {
37 col[k] = c;
38 k += 1;
39 }
40 if k != fields {
41 return Err("pool line has the wrong number of fields");
42 }
43 // train: id cat act text turns; extra: id fam cat act text turns src
44 let (act, text, turns) = if fields == 5 {
45 (col[2], col[3], col[4])
46 } else {
47 (col[3], col[4], col[5])
48 };
49 let action = Action::from_name(act).ok_or("pool line has an unknown action")?;
50 f(Example {
51 action,
52 text,
53 turns,
54 });
55 n += 1;
56 }
57 }
58 Ok(n)
59}