diff --git a/src/config.rs b/src/config.rs index 7826958..47746f8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -101,22 +101,27 @@ impl Config { let config: Config = toml::from_str(&config_str)?; let mut builder = law::Builder::new(config.law.name); - for classifier in &config.law.classifiers { - let to_add = law::Classifier::new( - &classifier.name, - create_classifier(&classifier.match_function)?, - ); - if classifier.is_root { - builder.add_classifier(to_add.root()); - } else { - builder.add_classifier(to_add); + if let Some(classifiers) = config.law.classifiers { + for classifier in &classifiers { + let to_add = law::Classifier::new( + &classifier.name, + create_classifier(&classifier.match_function)?, + ); + if classifier.is_root { + builder.add_classifier(to_add.root()); + } else { + builder.add_classifier(to_add); + } } + event!( + Level::INFO, + "Added {} classifiers from config", + &classifiers.len() + ); + } else { + builder.no_headers(); + event!(Level::INFO, "Assuming law text does not contain headers"); } - event!( - Level::INFO, - "Added {} classifiers from config", - &config.law.classifiers.len() - ); let mut parser = Parser::new(); @@ -153,7 +158,7 @@ impl Config { struct Law { id: usize, name: String, - classifiers: Vec, + classifiers: Option>, } #[derive(Debug, Deserialize)] diff --git a/src/law/mod.rs b/src/law/mod.rs index a90035d..3e4db1e 100644 --- a/src/law/mod.rs +++ b/src/law/mod.rs @@ -183,6 +183,8 @@ impl From for Vec { pub struct Builder { name: String, + no_headers: bool, + /// Structure of the law text classifiers: Vec, @@ -225,11 +227,19 @@ impl Builder { next_para_header: None, last_instance: None, next_para_note: None, + no_headers: false, #[cfg(test)] history: Vec::new(), } } + pub fn no_headers(&mut self) { + self.classifiers + .push(Classifier::new("", Arc::new(responsible::contains))); + self.new_header(""); + self.no_headers = true; + } + pub fn add_classifier(&mut self, classifier: Classifier) { self.classifiers.push(classifier); } @@ -312,6 +322,10 @@ impl Builder { /// ); /// ``` pub fn new_header(&mut self, name: &str) { + if self.no_headers { + panic!("Set no_headers, but received header {name}"); + } + let name = name.trim(); #[cfg(test)] self.history.push(format!("New_header: {name}"));