|
|
|
@ -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 }
|
|
|
|
|
}
|
|
|
|
|