This commit is contained in:
parent
172d295532
commit
241fbf1f37
@ -101,22 +101,27 @@ 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 {
|
||||||
let to_add = law::Classifier::new(
|
for classifier in &classifiers {
|
||||||
&classifier.name,
|
let to_add = law::Classifier::new(
|
||||||
create_classifier(&classifier.match_function)?,
|
&classifier.name,
|
||||||
);
|
create_classifier(&classifier.match_function)?,
|
||||||
if classifier.is_root {
|
);
|
||||||
builder.add_classifier(to_add.root());
|
if classifier.is_root {
|
||||||
} else {
|
builder.add_classifier(to_add.root());
|
||||||
builder.add_classifier(to_add);
|
} 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();
|
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)]
|
||||||
|
@ -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}"));
|
||||||
|
Loading…
Reference in New Issue
Block a user