hyprstream_bench/gen/
syllogism.rs1use hyprstream_decision::Entry;
12
13use crate::family::{Family, Stratum};
14use crate::gen::stream;
15use crate::item::Item;
16
17const FAMILY: Family = Family::Syllogism;
18
19const NAMES: [&str; 12] = [
20 "glorps", "wibbles", "snarfs", "krendels", "plughs", "zorbs", "mippels", "tarns", "quells",
21 "droves", "fims", "jastrels",
22];
23
24struct Chain {
25 text: String,
26 a: &'static str,
28 c: &'static str,
30 all_ac: bool,
32}
33
34fn chain(seed: u64, stratum: Stratum) -> Chain {
35 let mut rng = stream(seed);
36 let base = rng.below(NAMES.len() as u64) as usize;
37 let a = NAMES[base];
38 let b = NAMES[(base + 1) % NAMES.len()];
39 let c = NAMES[(base + 2) % NAMES.len()];
40 let valid = match stratum {
46 Stratum::NearMiss => rng.below(4) == 0,
47 _ => rng.below(4) != 0,
48 };
49 let text = if valid {
50 format!("All {a} are {b}. All {b} are {c}.")
51 } else {
52 format!("All {a} are {b}. All {c} are {b}.")
53 };
54 Chain {
55 text,
56 a,
57 c,
58 all_ac: valid,
59 }
60}
61
62pub fn noul(seed: u64, stratum: Stratum) -> Item {
63 let chain = chain(seed, stratum);
64 Item::noul(
65 FAMILY,
66 stratum,
67 seed,
68 Entry::Str(chain.text),
69 format!("Does it follow that all {} are {}?", chain.a, chain.c),
70 chain.all_ac,
71 )
72}
73
74pub fn choice(seed: u64, stratum: Stratum) -> Item {
75 let mut rng = stream(seed ^ 0xC0);
76 let chain = chain(seed, stratum);
77 let options = [
78 format!("All {} are {}", chain.a, chain.c),
79 format!("No {} are {}", chain.a, chain.c),
80 format!("Some {} are not {}", chain.a, chain.c),
81 "None of these follow".to_owned(),
82 ];
83 let correct = if chain.all_ac { 0 } else { 3 };
84 let order = rng.permutation(options.len());
85 let shuffled: Vec<String> = order.iter().map(|&i| options[i].clone()).collect();
86 let new_correct = order
87 .iter()
88 .position(|&i| i == correct)
89 .unwrap_or_else(|| unreachable!("permutation contains every index"));
90 Item::choice(
91 FAMILY,
92 stratum,
93 seed,
94 Entry::Str(chain.text),
95 "Which conclusion follows from the premises?",
96 shuffled,
97 new_correct,
98 )
99}
100
101pub fn score(seed: u64, stratum: Stratum) -> Item {
102 let chain = chain(seed, stratum);
103 Item::score(
104 FAMILY,
105 stratum,
106 seed,
107 Entry::Str(chain.text),
108 "How strong is the inference from the premises to \"all of the first category are the third category\"? Levels: 0 = does not follow, 1 = follows necessarily.",
109 2,
110 usize::from(chain.all_ac),
111 )
112}