This commit is contained in:
parent
172d295532
commit
241fbf1f37
@ -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<Classifier>,
|
||||
classifiers: Option<Vec<Classifier>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
|
@ -183,6 +183,8 @@ impl From<ClassifierInstance> for Vec<HeadingContent> {
|
||||
pub struct Builder {
|
||||
name: String,
|
||||
|
||||
no_headers: bool,
|
||||
|
||||
/// Structure of the law text
|
||||
classifiers: Vec<Classifier>,
|
||||
|
||||
@ -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}"));
|
||||
|
Loading…
Reference in New Issue
Block a user