diff --git a/src/config.rs b/src/config.rs index 18fc4a2..26a08ad 100644 --- a/src/config.rs +++ b/src/config.rs @@ -14,10 +14,10 @@ // See the Licence for the specific language governing permissions and // limitations under the Licence. +use crate::law::ClassifierApplicable; #[allow(clippy::wildcard_imports)] // I use *-operator on purpose: I want to receive a compiler // warning if I've not updated my `create_classifier` function use crate::law::{self, responsible::*}; -use crate::law::{ClassifierApplicable, LawBuilder}; use crate::misc::Error; use crate::paragraph::Parser; use serde::Deserialize; @@ -92,11 +92,11 @@ impl Config { /// /// assert_eq!(law_id, 10001622); /// ``` - pub fn load>(path: P) -> Result<(usize, LawBuilder, Parser), Error> { + pub fn load>(path: P) -> Result<(usize, law::Builder, Parser), Error> { let config_str = fs::read_to_string(path)?; let config: Config = toml::from_str(&config_str)?; - let mut builder = LawBuilder::new(config.law.name); + let mut builder = law::Builder::new(config.law.name); for classifier in config.law.classifiers { let to_add = law::Classifier::new( &classifier.name, diff --git a/src/law/mod.rs b/src/law/mod.rs index 33d3126..4f85a50 100644 --- a/src/law/mod.rs +++ b/src/law/mod.rs @@ -106,8 +106,8 @@ impl Law { } } -impl From for Law { - fn from(builder: LawBuilder) -> Self { +impl From for Law { + fn from(builder: Builder) -> Self { let mut ret = Vec::new(); for header in builder.header { @@ -170,7 +170,7 @@ impl From for Vec { /// Is used to generate a law struct. It's organized mainly by classifier. #[derive(Debug)] -pub struct LawBuilder { +pub struct Builder { name: String, /// Structure of the law text @@ -190,7 +190,7 @@ pub struct LawBuilder { pub history: Vec, } -impl PartialEq for LawBuilder { +impl PartialEq for Builder { fn eq(&self, other: &Self) -> bool { self.classifiers == other.classifiers && self.header == other.header @@ -198,13 +198,13 @@ impl PartialEq for LawBuilder { } } -impl Default for LawBuilder { +impl Default for Builder { fn default() -> Self { Self::new(String::new()) } } -impl LawBuilder { +impl Builder { /// Creates a new law builder. Adds classifier for known law texts. pub fn new(name: String) -> Self { Self { diff --git a/src/paragraph/mod.rs b/src/paragraph/mod.rs index 9d86e66..f282c50 100644 --- a/src/paragraph/mod.rs +++ b/src/paragraph/mod.rs @@ -28,7 +28,7 @@ use std::{ use log::info; use crate::{ - law::LawBuilder, + law, misc::{fetch_with_retries, get_cache_dir, Error}, }; @@ -67,8 +67,8 @@ impl Parser { self.replace.push((search.into(), replace.into())); } - /// Parses the content available in `url`. Calls appropriate functions in supplied `LawBuilder`. - pub fn parse(&self, url: &str, builder: &mut LawBuilder) -> Result { + /// Parses the content available in `url`. Calls appropriate functions in supplied `Builder`. + pub fn parse(&self, url: &str, builder: &mut law::Builder) -> Result { info!("Parsing {url}"); let xml = fetch(url)?; @@ -77,7 +77,7 @@ impl Parser { self.parse_from_str(&xml, builder) } - fn parse_from_str(&self, xml: &str, builder: &mut LawBuilder) -> Result { + fn parse_from_str(&self, xml: &str, builder: &mut law::Builder) -> Result { let mut xml = String::from(xml); for r in &self.remove { xml = xml.replace(r, ""); diff --git a/src/paragraph/parser/abschnitt.rs b/src/paragraph/parser/abschnitt.rs index 3a762ed..a0f58f2 100644 --- a/src/paragraph/parser/abschnitt.rs +++ b/src/paragraph/parser/abschnitt.rs @@ -20,7 +20,7 @@ use std::iter::Peekable; use log::{debug, trace}; use roxmltree::{Children, Node}; -use crate::law::LawBuilder; +use crate::law; use crate::paragraph::parser::absatz::Absatz; use crate::paragraph::parser::{AbsatzAbs, Content, Fzinhalt, Kzinhalt, Ueberschrift}; @@ -31,7 +31,7 @@ pub(crate) struct Abschnitt { } impl Abschnitt { - pub(crate) fn parse(n: Node, builder: &mut LawBuilder) -> Abschnitt { + pub(crate) fn parse(n: Node, builder: &mut law::Builder) -> Abschnitt { assert!(n.tag_name().name() == "abschnitt"); let mut ret = Abschnitt::default(); @@ -97,7 +97,7 @@ impl Abschnitt { // There are paragraph-specific meta-data at the top and bottom of each xml file. We parse // those. When we encounter the title "Text" the real content starts, we stop parsing meta // data. - fn handle_metadata(&mut self, c: &mut Peekable, builder: &mut LawBuilder) { + fn handle_metadata(&mut self, c: &mut Peekable, builder: &mut law::Builder) { while c.peek().is_some() { let key = Ueberschrift::parse(c.next().unwrap(), "titel").content; @@ -146,7 +146,7 @@ impl Abschnitt { // we have optionally headers. Such as "Einleitung", "Von den bürgerlichen Gesetzen üerhaupt," // etc. If we have headers which indicate that we are done and we want to stop parsing // ("anlage" + "Artikel" we indicate this wish by returning false. - fn handle_headers(c: &mut Peekable, builder: &mut LawBuilder) -> bool { + fn handle_headers(c: &mut Peekable, builder: &mut law::Builder) -> bool { while let Some(child) = c.peek() { // Schiffahrtsgesetz: stop @ anlagen (for now) if Ueberschrift::test(child, "anlage") { diff --git a/src/paragraph/parser/mod.rs b/src/paragraph/parser/mod.rs index 2b5a783..ad81c63 100644 --- a/src/paragraph/parser/mod.rs +++ b/src/paragraph/parser/mod.rs @@ -26,7 +26,7 @@ use log::trace; use roxmltree::{Children, Node}; use crate::{ - law::{Content, LawBuilder}, + law::{self, Content}, misc::Error, paragraph::parser::absatz::Absatz, }; @@ -57,7 +57,7 @@ impl<'a> Expect<'a> { pub(crate) struct Risdok {} impl Risdok { - pub(crate) fn parse(n: Node, builder: &mut LawBuilder) -> bool { + pub(crate) fn parse(n: Node, builder: &mut law::Builder) -> bool { assert!(n.tag_name().name() == "risdok"); let mut c = n.children(); @@ -74,7 +74,7 @@ impl Risdok { true } - pub(crate) fn from_str(xml: &str, builder: &mut LawBuilder) -> Result { + pub(crate) fn from_str(xml: &str, builder: &mut law::Builder) -> Result { let doc = roxmltree::Document::parse(xml)?; trace!("{doc:?}"); let root = doc.root(); @@ -98,7 +98,7 @@ impl Metadaten { #[derive(Debug, PartialEq)] pub(crate) struct Nutzdaten {} impl Nutzdaten { - pub(crate) fn parse(n: Node, builder: &mut LawBuilder) -> bool { + pub(crate) fn parse(n: Node, builder: &mut law::Builder) -> bool { assert!(n.tag_name().name() == "nutzdaten"); let mut c = n.children();