This commit is contained in:
parent
1dbd60f711
commit
b3b17561a8
@ -85,7 +85,7 @@ impl Config {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use risp::config::Config;
|
/// use risp::Config;
|
||||||
/// use std::path::Path;
|
/// use std::path::Path;
|
||||||
///
|
///
|
||||||
/// let (law_id, builder, parser) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
|
/// let (law_id, builder, parser) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
// See the Licence for the specific language governing permissions and
|
// See the Licence for the specific language governing permissions and
|
||||||
// limitations under the Licence.
|
// limitations under the Licence.
|
||||||
|
|
||||||
|
//! Represents a parsed law text.
|
||||||
|
|
||||||
use log::{debug, info};
|
use log::{debug, info};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
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)]
|
#[derive(Debug)]
|
||||||
pub struct Builder {
|
pub struct Builder {
|
||||||
name: String,
|
name: String,
|
||||||
@ -281,7 +288,7 @@ impl Builder {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use risp::{config::Config, law::{Law, Heading}};
|
/// use risp::{Config, law::{Law, Heading}};
|
||||||
/// use std::path::Path;
|
/// use std::path::Path;
|
||||||
///
|
///
|
||||||
/// let (_, mut builder, _) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
|
/// let (_, mut builder, _) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
|
||||||
@ -374,7 +381,7 @@ impl Builder {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// use risp::{config::Config, law::{Law, Heading}};
|
/// use risp::{Config, law::{Law, Heading}};
|
||||||
/// use std::path::Path;
|
/// use std::path::Path;
|
||||||
///
|
///
|
||||||
/// let (_, mut builder, _) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
|
/// 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:
|
/// 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;
|
/// use std::path::Path;
|
||||||
///
|
///
|
||||||
/// let (_, mut builder, _) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
|
/// 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>;
|
pub(crate) type ClassifierApplicable = Arc<dyn Fn(&str, &str) -> bool>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[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 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,
|
pub(crate) used_for_fn: ClassifierApplicable,
|
||||||
|
|
||||||
instances: Vec<ClassifierInstance>,
|
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>>>,
|
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,
|
pub root: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -616,6 +654,7 @@ impl PartialEq for Classifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Classifier {
|
impl Classifier {
|
||||||
|
/// Constructs a new `Classifier` with the specified name and applicability function.
|
||||||
pub fn new(name: &str, used_for_fn: ClassifierApplicable) -> Self {
|
pub fn new(name: &str, used_for_fn: ClassifierApplicable) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
@ -627,6 +666,7 @@ impl Classifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
|
/// Marks the classifier as a root element, returning a modified instance of the classifier.
|
||||||
pub fn root(self) -> Self {
|
pub fn root(self) -> Self {
|
||||||
Self { root: true, ..self }
|
Self { root: true, ..self }
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,12 @@
|
|||||||
// See the Licence for the specific language governing permissions and
|
// See the Licence for the specific language governing permissions and
|
||||||
// limitations under the Licence.
|
// limitations under the Licence.
|
||||||
|
|
||||||
pub mod config;
|
mod config;
|
||||||
pub mod misc;
|
pub use config::Config;
|
||||||
|
|
||||||
|
mod misc;
|
||||||
|
pub use misc::clear_cache;
|
||||||
|
pub use misc::Error;
|
||||||
|
|
||||||
pub mod law;
|
pub mod law;
|
||||||
pub mod overview;
|
pub mod overview;
|
||||||
|
@ -18,9 +18,9 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use clap::{command, Parser};
|
use clap::{command, Parser};
|
||||||
use risp::{
|
use risp::{
|
||||||
config::Config,
|
clear_cache,
|
||||||
law::{responsible::always_true, Classifier, Law},
|
law::{responsible::always_true, Classifier, Law},
|
||||||
misc::clear_cache,
|
Config,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// See the Licence for the specific language governing permissions and
|
// See the Licence for the specific language governing permissions and
|
||||||
// limitations under the Licence.
|
// 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;
|
mod parser;
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ impl Parser {
|
|||||||
/// # Example Usage
|
/// # 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;
|
/// use std::path::Path;
|
||||||
///
|
///
|
||||||
/// let (_, mut builder, parser) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
|
/// let (_, mut builder, parser) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user