restructre lib
All checks were successful
CI/CD Pipeline / test (push) Successful in 5m29s

This commit is contained in:
philipp 2024-02-27 10:33:07 +01:00
parent 1dbd60f711
commit b3b17561a8
5 changed files with 56 additions and 12 deletions

View File

@ -85,7 +85,7 @@ impl Config {
/// # Examples
///
/// ```
/// use risp::config::Config;
/// use risp::Config;
/// use std::path::Path;
///
/// let (law_id, builder, parser) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();

View File

@ -14,6 +14,8 @@
// See the Licence for the specific language governing permissions and
// limitations under the Licence.
//! Represents a parsed law text.
use log::{debug, info};
use serde::{Deserialize, Serialize};
use std::{
@ -168,7 +170,12 @@ impl From<ClassifierInstance> for Vec<HeadingContent> {
}
}
/// Is used to generate a law struct. It's organized mainly by classifier.
/// A `Builder` struct for constructing a `Law` structure.
///
/// This struct is designed to facilitate the building of a `Law`'s structure, primarily organized by
/// a set of classifiers. Each classifier represents a hierarchical level within the law, such as
/// chapters, sections, or articles. The builder pattern is used to incrementally construct the
/// law, allowing for the addition of headers, paragraphs, and notes in a structured manner.
#[derive(Debug)]
pub struct Builder {
name: String,
@ -281,7 +288,7 @@ impl Builder {
/// # Examples
///
/// ```
/// use risp::{config::Config, law::{Law, Heading}};
/// use risp::{Config, law::{Law, Heading}};
/// use std::path::Path;
///
/// let (_, mut builder, _) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
@ -374,7 +381,7 @@ impl Builder {
///
/// # Examples
/// ```
/// use risp::{config::Config, law::{Law, Heading}};
/// use risp::{Config, law::{Law, Heading}};
/// use std::path::Path;
///
/// let (_, mut builder, _) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
@ -434,7 +441,7 @@ impl Builder {
/// Assuming `law` is a mutable reference to an instance of a law struct:
///
/// ```
/// use risp::{config::Config, law::{Law, Heading, Content, HeadingContent, Section}};
/// use risp::{Config, law::{Law, Heading, Content, HeadingContent, Section}};
/// use std::path::Path;
///
/// let (_, mut builder, _) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
@ -601,11 +608,42 @@ impl From<&str> for ClassifierInstance {
pub(crate) type ClassifierApplicable = Arc<dyn Fn(&str, &str) -> bool>;
#[derive(Clone)]
/// Represents a structural element within a legal document, such as a chapter, section, or
/// article.
///
/// A `Classifier` is used to categorize parts of a legal document into hierarchical levels, aiding
/// in the organization and navigation of the content. It can represent various structural elements
/// like chapters, sections, articles, etc., depending on the specific needs of the legal document
/// being processed.
///
/// # Examples
///
/// ```
/// use std::{sync::Arc, rc::Rc, cell::RefCell};
/// use risp::law::Classifier;
///
/// fn starts_with(classifier_name: &str, title: &str) -> bool {
/// title.starts_with(classifier_name)
/// }
///
/// let chapter_classifier = Classifier::new("Chapter", Arc::new(starts_with));
///
/// let chapter_classifier = chapter_classifier.root();
/// ```
pub struct Classifier {
pub name: String, // Hauptstück, Theil, Abschnitt, ol
/// The name or title of the classifier (e.g., "Hauptstück", "Theil", "Abschnitt").
pub name: String,
pub(crate) used_for_fn: ClassifierApplicable,
instances: Vec<ClassifierInstance>,
/// Child classifiers. This enables a hierarchical structure where classifiers can contain
/// nested levels of other classifiers.
pub child: Vec<Rc<RefCell<Classifier>>>,
/// Specifies whether this classifier is a root element of the document structure. Root
/// classifiers are typically top-level elements like major divisions or parts of a document.
pub root: bool,
}
@ -616,6 +654,7 @@ impl PartialEq for Classifier {
}
impl Classifier {
/// Constructs a new `Classifier` with the specified name and applicability function.
pub fn new(name: &str, used_for_fn: ClassifierApplicable) -> Self {
Self {
name: name.into(),
@ -627,6 +666,7 @@ impl Classifier {
}
#[must_use]
/// Marks the classifier as a root element, returning a modified instance of the classifier.
pub fn root(self) -> Self {
Self { root: true, ..self }
}

View File

@ -14,8 +14,12 @@
// See the Licence for the specific language governing permissions and
// limitations under the Licence.
pub mod config;
pub mod misc;
mod config;
pub use config::Config;
mod misc;
pub use misc::clear_cache;
pub use misc::Error;
pub mod law;
pub mod overview;

View File

@ -18,9 +18,9 @@ use std::sync::Arc;
use clap::{command, Parser};
use risp::{
config::Config,
clear_cache,
law::{responsible::always_true, Classifier, Law},
misc::clear_cache,
Config,
};
#[derive(Parser, Debug)]

View File

@ -14,7 +14,7 @@
// See the Licence for the specific language governing permissions and
// limitations under the Licence.
//! Deals with getting all paragraphs for a given law text
//! Deals with getting the content of a single paragraph.
mod parser;
@ -101,7 +101,7 @@ impl Parser {
/// # Example Usage
///
/// ```
/// use risp::{config::Config, law::{Law, Heading, Content, Section, HeadingContent}};
/// use risp::{Config, law::{Law, Heading, Content, Section, HeadingContent}};
/// use std::path::Path;
///
/// let (_, mut builder, parser) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();