lemma/documentation/
mod.rs1pub const LLMS_TXT: &str = include_str!("llms.txt");
4pub const EVALUATE_GUIDE: &str = include_str!("evaluate_guide.txt");
5
6const METHOD: &str = include_str!("guide/05_method.txt");
7const SYNTAX: &str = include_str!("guide/10_syntax.txt");
8const COMPOSITION: &str = include_str!("guide/20_composition.txt");
9const NATURAL_LANGUAGE: &str = include_str!("guide/25_natural_language.txt");
10const DATA: &str = include_str!("guide/30_data.txt");
11const UNITS: &str = include_str!("guide/40_units.txt");
12const RULES: &str = include_str!("guide/50_rules.txt");
13const VETO: &str = include_str!("guide/60_veto.txt");
14const ANTI_PATTERNS: &str = include_str!("guide/70_anti_patterns.txt");
15
16pub const EXAMPLE_01_COFFEE_ORDER: &str = include_str!("examples/01_coffee_order.lemma");
17pub const EXAMPLE_02_LIBRARY_FEES: &str = include_str!("examples/02_library_fees.lemma");
18pub const EXAMPLE_03_RECIPE_SCALING: &str = include_str!("examples/03_recipe_scaling.lemma");
19pub const EXAMPLE_04_MEMBERSHIP_BENEFITS: &str =
20 include_str!("examples/04_membership_benefits.lemma");
21pub const EXAMPLE_05_WEATHER_CLOTHING: &str = include_str!("examples/05_weather_clothing.lemma");
22pub const EXAMPLE_NL_TAX_NET_SALARY: &str = include_str!("examples/nl/tax/net_salary.lemma");
23
24#[derive(Debug, Clone, Copy, PartialEq, Eq)]
27pub enum GuideTopic {
28 Method,
29 Syntax,
30 Data,
31 Rules,
32 Units,
33 Veto,
34 Composition,
35 NaturalLanguage,
36 AntiPatterns,
37 Evaluate,
38 Full,
39}
40
41impl GuideTopic {
42 pub const ALL: &[GuideTopic] = &[
43 GuideTopic::Method,
44 GuideTopic::Syntax,
45 GuideTopic::Data,
46 GuideTopic::Rules,
47 GuideTopic::Units,
48 GuideTopic::Veto,
49 GuideTopic::Composition,
50 GuideTopic::NaturalLanguage,
51 GuideTopic::AntiPatterns,
52 GuideTopic::Evaluate,
53 GuideTopic::Full,
54 ];
55
56 pub const VALID_LIST: &str = "method, syntax, data, rules, units, veto, composition, natural_language, anti_patterns, evaluate, full";
57
58 pub fn as_str(self) -> &'static str {
59 match self {
60 GuideTopic::Method => "method",
61 GuideTopic::Syntax => "syntax",
62 GuideTopic::Data => "data",
63 GuideTopic::Rules => "rules",
64 GuideTopic::Units => "units",
65 GuideTopic::Veto => "veto",
66 GuideTopic::Composition => "composition",
67 GuideTopic::NaturalLanguage => "natural_language",
68 GuideTopic::AntiPatterns => "anti_patterns",
69 GuideTopic::Evaluate => "evaluate",
70 GuideTopic::Full => "full",
71 }
72 }
73
74 pub fn parse(name: &str) -> Option<Self> {
75 Self::ALL.iter().copied().find(|t| t.as_str() == name)
76 }
77
78 pub fn section_text(self) -> &'static str {
80 match self {
81 GuideTopic::Method => METHOD,
82 GuideTopic::Syntax => SYNTAX,
83 GuideTopic::Data => DATA,
84 GuideTopic::Rules => RULES,
85 GuideTopic::Units => UNITS,
86 GuideTopic::Veto => VETO,
87 GuideTopic::Composition => COMPOSITION,
88 GuideTopic::NaturalLanguage => NATURAL_LANGUAGE,
89 GuideTopic::AntiPatterns => ANTI_PATTERNS,
90 GuideTopic::Evaluate => EVALUATE_GUIDE,
91 GuideTopic::Full => LLMS_TXT,
92 }
93 }
94}
95
96pub struct ExampleResource {
98 pub path: &'static str,
99 pub body: &'static str,
100}
101
102pub const EXAMPLE_RESOURCES: &[ExampleResource] = &[
103 ExampleResource {
104 path: "01_coffee_order.lemma",
105 body: EXAMPLE_01_COFFEE_ORDER,
106 },
107 ExampleResource {
108 path: "02_library_fees.lemma",
109 body: EXAMPLE_02_LIBRARY_FEES,
110 },
111 ExampleResource {
112 path: "03_recipe_scaling.lemma",
113 body: EXAMPLE_03_RECIPE_SCALING,
114 },
115 ExampleResource {
116 path: "04_membership_benefits.lemma",
117 body: EXAMPLE_04_MEMBERSHIP_BENEFITS,
118 },
119 ExampleResource {
120 path: "05_weather_clothing.lemma",
121 body: EXAMPLE_05_WEATHER_CLOTHING,
122 },
123 ExampleResource {
124 path: "nl/tax/net_salary.lemma",
125 body: EXAMPLE_NL_TAX_NET_SALARY,
126 },
127];
128
129pub fn example_by_path(path: &str) -> Option<&'static str> {
130 EXAMPLE_RESOURCES
131 .iter()
132 .find(|e| e.path == path)
133 .map(|e| e.body)
134}
135
136#[cfg(test)]
137mod tests {
138 use super::*;
139
140 #[test]
141 fn guide_topic_parse_round_trip() {
142 for topic in GuideTopic::ALL {
143 assert_eq!(GuideTopic::parse(topic.as_str()), Some(*topic));
144 }
145 assert!(GuideTopic::parse("temporal").is_none());
146 assert!(GuideTopic::parse("").is_none());
147 }
148}