rename lawbuilder to builder to not have law twice in law::LawBuilder
All checks were successful
CI/CD Pipeline / test (push) Successful in 4m44s
All checks were successful
CI/CD Pipeline / test (push) Successful in 4m44s
This commit is contained in:
parent
d25785984d
commit
b8a6cccf0b
@ -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<P: AsRef<Path>>(path: P) -> Result<(usize, LawBuilder, Parser), Error> {
|
||||
pub fn load<P: AsRef<Path>>(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,
|
||||
|
@ -106,8 +106,8 @@ impl Law {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LawBuilder> for Law {
|
||||
fn from(builder: LawBuilder) -> Self {
|
||||
impl From<Builder> for Law {
|
||||
fn from(builder: Builder) -> Self {
|
||||
let mut ret = Vec::new();
|
||||
|
||||
for header in builder.header {
|
||||
@ -170,7 +170,7 @@ impl From<ClassifierInstance> for Vec<HeadingContent> {
|
||||
|
||||
/// 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<String>,
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -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<bool, Error> {
|
||||
/// Parses the content available in `url`. Calls appropriate functions in supplied `Builder`.
|
||||
pub fn parse(&self, url: &str, builder: &mut law::Builder) -> Result<bool, Error> {
|
||||
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<bool, Error> {
|
||||
fn parse_from_str(&self, xml: &str, builder: &mut law::Builder) -> Result<bool, Error> {
|
||||
let mut xml = String::from(xml);
|
||||
for r in &self.remove {
|
||||
xml = xml.replace(r, "");
|
||||
|
@ -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<Children>, builder: &mut LawBuilder) {
|
||||
fn handle_metadata(&mut self, c: &mut Peekable<Children>, 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<Children>, builder: &mut LawBuilder) -> bool {
|
||||
fn handle_headers(c: &mut Peekable<Children>, builder: &mut law::Builder) -> bool {
|
||||
while let Some(child) = c.peek() {
|
||||
// Schiffahrtsgesetz: stop @ anlagen (for now)
|
||||
if Ueberschrift::test(child, "anlage") {
|
||||
|
@ -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<bool, Error> {
|
||||
pub(crate) fn from_str(xml: &str, builder: &mut law::Builder) -> Result<bool, Error> {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user