allow laws with no headers
Some checks failed
CI/CD Pipeline / test (push) Has been cancelled

This commit is contained in:
philipp 2024-03-21 10:08:03 +01:00
parent 172d295532
commit 241fbf1f37
2 changed files with 34 additions and 15 deletions

View File

@ -101,7 +101,8 @@ impl Config {
let config: Config = toml::from_str(&config_str)?; let config: Config = toml::from_str(&config_str)?;
let mut builder = law::Builder::new(config.law.name); let mut builder = law::Builder::new(config.law.name);
for classifier in &config.law.classifiers { if let Some(classifiers) = config.law.classifiers {
for classifier in &classifiers {
let to_add = law::Classifier::new( let to_add = law::Classifier::new(
&classifier.name, &classifier.name,
create_classifier(&classifier.match_function)?, create_classifier(&classifier.match_function)?,
@ -115,8 +116,12 @@ impl Config {
event!( event!(
Level::INFO, Level::INFO,
"Added {} classifiers from config", "Added {} classifiers from config",
&config.law.classifiers.len() &classifiers.len()
); );
} else {
builder.no_headers();
event!(Level::INFO, "Assuming law text does not contain headers");
}
let mut parser = Parser::new(); let mut parser = Parser::new();
@ -153,7 +158,7 @@ impl Config {
struct Law { struct Law {
id: usize, id: usize,
name: String, name: String,
classifiers: Vec<Classifier>, classifiers: Option<Vec<Classifier>>,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]

View File

@ -183,6 +183,8 @@ impl From<ClassifierInstance> for Vec<HeadingContent> {
pub struct Builder { pub struct Builder {
name: String, name: String,
no_headers: bool,
/// Structure of the law text /// Structure of the law text
classifiers: Vec<Classifier>, classifiers: Vec<Classifier>,
@ -225,11 +227,19 @@ impl Builder {
next_para_header: None, next_para_header: None,
last_instance: None, last_instance: None,
next_para_note: None, next_para_note: None,
no_headers: false,
#[cfg(test)] #[cfg(test)]
history: Vec::new(), 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) { pub fn add_classifier(&mut self, classifier: Classifier) {
self.classifiers.push(classifier); self.classifiers.push(classifier);
} }
@ -312,6 +322,10 @@ impl Builder {
/// ); /// );
/// ``` /// ```
pub fn new_header(&mut self, name: &str) { pub fn new_header(&mut self, name: &str) {
if self.no_headers {
panic!("Set no_headers, but received header {name}");
}
let name = name.trim(); let name = name.trim();
#[cfg(test)] #[cfg(test)]
self.history.push(format!("New_header: {name}")); self.history.push(format!("New_header: {name}"));