add config for law texts, fixes #3
All checks were successful
CI/CD Pipeline / test (push) Successful in 9m17s

This commit is contained in:
2024-02-06 10:17:14 +01:00
parent 54a8c7a0fe
commit 15e0e485c4
9 changed files with 185 additions and 23 deletions

View File

@ -7,20 +7,33 @@ use std::{
sync::Arc,
};
use crate::{config::Config, misc::Error, risparser::overview::parse};
pub mod responsible;
/// That's our struct, holding all the information of the law text.
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct Law {
pub name: String, //ABGB, UrhG
pub header: Vec<Heading>,
}
impl Law {
pub fn from_config(path: &str) -> Result<Law, Error> {
let (law_id, mut builder, parser) = Config::load(path)?;
let pars = parse(law_id).unwrap();
for par in pars {
let cont = parser.parse(&par, &mut builder).unwrap();
if !cont {
break;
}
}
Ok(builder.into())
}
//TODO: add test
pub fn to_md(&self) {
println!("# {}", self.name);
for header in &self.header {
Self::print_md(header, 2);
}
@ -55,10 +68,7 @@ impl From<LawBuilder> for Law {
});
}
Self {
name: builder.name,
header: ret,
}
Self { header: ret }
}
}
@ -107,9 +117,6 @@ impl From<ClassifierInstance> for HeadingContent {
/// Is used to generate a law struct. It's organized mainly by classifier.
#[derive(Debug)]
pub struct LawBuilder {
/// Name of the law
name: String, //ABGB, UrhG
/// Structure of the law text
classifiers: Vec<Classifier>,
@ -127,8 +134,7 @@ pub struct LawBuilder {
impl PartialEq for LawBuilder {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
&& self.classifiers == other.classifiers
self.classifiers == other.classifiers
&& self.header == other.header
&& self.next_para_header == other.next_para_header
}
@ -136,9 +142,8 @@ impl PartialEq for LawBuilder {
impl LawBuilder {
/// Creates a new law builder. Adds classifier for known law texts.
pub fn new(name: &str) -> Self {
pub fn new() -> Self {
Self {
name: name.into(),
classifiers: Vec::new(),
header: Vec::new(),
next_para_header: None,
@ -357,7 +362,7 @@ impl From<&str> for ClassifierInstance {
}
}
type ClassifierApplicable = Arc<dyn Fn(&str, &str) -> bool>;
pub(crate) type ClassifierApplicable = Arc<dyn Fn(&str, &str) -> bool>;
#[derive(Clone)]
pub struct Classifier {