add docs for paragraph::parse()
All checks were successful
CI/CD Pipeline / test (push) Successful in 5m50s
All checks were successful
CI/CD Pipeline / test (push) Successful in 5m50s
This commit is contained in:
parent
8d3ec82416
commit
1dbd60f711
@ -626,6 +626,7 @@ impl Classifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn root(self) -> Self {
|
pub fn root(self) -> Self {
|
||||||
Self { root: true, ..self }
|
Self { root: true, ..self }
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,15 @@ use ris_structure::OgdSearchResult;
|
|||||||
/// - `Ok(Vec<String>)`: A vector of XML file links representing paragraphs from the given law text.
|
/// - `Ok(Vec<String>)`: A vector of XML file links representing paragraphs from the given law text.
|
||||||
/// - `Err(Error)`: An error if there was an issue fetching or parsing the law text.
|
/// - `Err(Error)`: An error if there was an issue fetching or parsing the law text.
|
||||||
///
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function may return an error in several cases:
|
||||||
|
/// - Network issues that prevent fetching the law text from the RIS.
|
||||||
|
/// - Parsing errors if the fetched data from RIS does not conform to the expected format.
|
||||||
|
/// - Issues with iterating over the pages of the law text, such as an unexpected end of data.
|
||||||
|
///
|
||||||
|
/// These errors are encapsulated in the `Error` type, which provides details about what went wrong during the execution of the function.
|
||||||
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// use risp::overview::parse;
|
/// use risp::overview::parse;
|
||||||
|
@ -47,6 +47,7 @@ impl Default for Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Parser {
|
impl Parser {
|
||||||
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
remove: Vec::new(),
|
remove: Vec::new(),
|
||||||
@ -67,7 +68,63 @@ impl Parser {
|
|||||||
self.replace.push((search.into(), replace.into()));
|
self.replace.push((search.into(), replace.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses the content available in `url`. Calls appropriate functions in supplied `Builder`.
|
/// Parses the content available at the specified `url` and processes it using the provided
|
||||||
|
/// `law::Builder`.
|
||||||
|
///
|
||||||
|
/// This function is responsible for downloading the content from the given `url`,
|
||||||
|
/// pre-processing the text (such as removing unwanted characters and performing specified
|
||||||
|
/// replacements), and then parsing the pre-processed XML content.
|
||||||
|
///
|
||||||
|
/// This method also handles caching of the downloaded content to avoid repeated downloads of
|
||||||
|
/// the same resource, improving efficiency and reducing network load.
|
||||||
|
///
|
||||||
|
/// # Parameters
|
||||||
|
///
|
||||||
|
/// - `url`: The URL from which to fetch the law text. - `builder`: A mutable reference to a
|
||||||
|
/// `law::Builder` instance, which is used to construct the law structure based on the parsed
|
||||||
|
/// content.
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
///
|
||||||
|
/// - `Ok(bool)`: Returns `true` if parsing was successful, `false` otherwise.
|
||||||
|
/// - `Err(Error)`: An error occurred during the fetching or parsing process.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// Errors can occur due to several reasons:
|
||||||
|
/// - Network issues preventing the download of content from the given `url`.
|
||||||
|
/// - I/O errors related to file system operations, such as problems with reading from or
|
||||||
|
/// writing to the cache.
|
||||||
|
/// - Parsing errors if the downloaded content cannot be properly processed or interpreted as
|
||||||
|
/// expected.
|
||||||
|
///
|
||||||
|
/// # Example Usage
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use risp::{config::Config, law::{Law, Heading, Content, Section, HeadingContent}};
|
||||||
|
/// use std::path::Path;
|
||||||
|
///
|
||||||
|
/// let (_, mut builder, parser) = Config::load(Path::new("data/configs/abgb.toml")).unwrap();
|
||||||
|
/// let result = parser.parse("https://www.ris.bka.gv.at/Dokumente/Bundesnormen/NOR12017691/NOR12017691.xml", &mut builder).unwrap();
|
||||||
|
///
|
||||||
|
/// let law: Law = builder.into();
|
||||||
|
/// assert_eq!(
|
||||||
|
/// law,
|
||||||
|
/// Law {
|
||||||
|
/// name: "ABGB".into(),
|
||||||
|
/// header: vec![Heading {
|
||||||
|
/// name: "Nullter Theil. Einleitung".into(),
|
||||||
|
/// desc: Some("Von den bürgerlichen Gesetzen überhaupt.".into()),
|
||||||
|
/// content: vec![HeadingContent::Paragraph(Section {
|
||||||
|
/// symb: "§ 1.".into(),
|
||||||
|
/// par_header: Some("Begriff des bürgerlichen Rechtes.".into()),
|
||||||
|
/// par_note: None,
|
||||||
|
/// content: Content::Text("Der Inbegriff der Gesetze, wodurch die Privat-Rechte und Pflichten der Einwohner des Staates unter sich bestimmt werden, macht das bürgerliche Recht in demselben aus.".into())
|
||||||
|
/// })]
|
||||||
|
/// }]
|
||||||
|
/// }
|
||||||
|
/// );
|
||||||
|
/// ```
|
||||||
pub fn parse(&self, url: &str, builder: &mut law::Builder) -> Result<bool, Error> {
|
pub fn parse(&self, url: &str, builder: &mut law::Builder) -> Result<bool, Error> {
|
||||||
info!("Parsing {url}");
|
info!("Parsing {url}");
|
||||||
let xml = fetch(url)?;
|
let xml = fetch(url)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user