This commit is contained in:
parent
ab21651a87
commit
32533a2d17
@ -168,7 +168,7 @@ impl LawBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new law builder. Adds classifier for known law texts.
|
/// Creates a new law builder. Adds classifier for known law texts.
|
||||||
pub(crate) fn new(name: &str) -> Law {
|
pub(crate) fn new(name: &str) -> Self {
|
||||||
let mut classifiers = Vec::new();
|
let mut classifiers = Vec::new();
|
||||||
|
|
||||||
let mut law_id = None;
|
let mut law_id = None;
|
||||||
@ -288,7 +288,7 @@ impl LawBuilder {
|
|||||||
|
|
||||||
let responsible_class = self
|
let responsible_class = self
|
||||||
.responsible_classifier(name)
|
.responsible_classifier(name)
|
||||||
.expect(&format!("No classifier for '{name}'"));
|
.unwrap_or_else(|| panic!("No classifier for '{name}'"));
|
||||||
|
|
||||||
let mut heading: ClassifierInstance = name.into();
|
let mut heading: ClassifierInstance = name.into();
|
||||||
|
|
||||||
@ -457,10 +457,12 @@ impl From<&str> for ClassifierInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ClassifierApplicable = Arc<dyn Fn(&str, &str) -> bool>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct Classifier {
|
pub(crate) struct Classifier {
|
||||||
pub(crate) name: String, // Hauptstück, Theil, Abschnitt, ol
|
pub(crate) name: String, // Hauptstück, Theil, Abschnitt, ol
|
||||||
pub(crate) used_for_fn: Arc<dyn Fn(&str, &str) -> bool>,
|
pub(crate) used_for_fn: ClassifierApplicable,
|
||||||
pub(crate) instances: Vec<ClassifierInstance>,
|
pub(crate) instances: Vec<ClassifierInstance>,
|
||||||
pub(crate) child: Vec<Rc<RefCell<Classifier>>>,
|
pub(crate) child: Vec<Rc<RefCell<Classifier>>>,
|
||||||
pub(crate) root: bool,
|
pub(crate) root: bool,
|
||||||
@ -473,7 +475,7 @@ impl PartialEq for Classifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Classifier {
|
impl Classifier {
|
||||||
fn new(name: &str, used_for_fn: Arc<dyn Fn(&str, &str) -> bool>) -> Self {
|
fn new(name: &str, used_for_fn: ClassifierApplicable) -> Self {
|
||||||
Self {
|
Self {
|
||||||
name: name.into(),
|
name: name.into(),
|
||||||
used_for_fn,
|
used_for_fn,
|
||||||
@ -554,7 +556,7 @@ mod tests {
|
|||||||
#[ignore]
|
#[ignore]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_with_live_data() {
|
fn test_with_live_data() {
|
||||||
let law = LawBuilder::new("UrhG");
|
let law: Law = LawBuilder::new("UrhG").into();
|
||||||
|
|
||||||
let path = Path::new("./data/urhg/builder.result");
|
let path = Path::new("./data/urhg/builder.result");
|
||||||
let mut file = File::open(path).unwrap();
|
let mut file = File::open(path).unwrap();
|
||||||
@ -569,7 +571,7 @@ mod tests {
|
|||||||
#[ignore]
|
#[ignore]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stgb_with_live_data() {
|
fn test_stgb_with_live_data() {
|
||||||
let law = LawBuilder::new("StGB");
|
let law: Law = LawBuilder::new("StGB").into();
|
||||||
|
|
||||||
let path = Path::new("./data/stgb/builder.result");
|
let path = Path::new("./data/stgb/builder.result");
|
||||||
let mut file = File::open(path).unwrap();
|
let mut file = File::open(path).unwrap();
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use law::LawBuilder;
|
use law::{Law, LawBuilder};
|
||||||
|
|
||||||
mod law;
|
mod law;
|
||||||
mod par;
|
mod par;
|
||||||
@ -6,6 +6,6 @@ mod par;
|
|||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let law = LawBuilder::new("StGB");
|
let law: Law = LawBuilder::new("StGB").into();
|
||||||
law.to_md();
|
law.to_md();
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ use std::io;
|
|||||||
use time::{format_description, OffsetDateTime};
|
use time::{format_description, OffsetDateTime};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub struct Error {
|
pub struct Error {
|
||||||
msg: String,
|
msg: String,
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,11 @@ use crate::misc::{current_date, Error};
|
|||||||
|
|
||||||
use super::parser::OgdSearchResult;
|
use super::parser::OgdSearchResult;
|
||||||
|
|
||||||
|
/// # Parameters
|
||||||
|
/// - `law_id`: Id from RIS of a law
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// Error, or a list of Xml file links of the given law text
|
||||||
pub fn parse(law_id: usize) -> Result<Vec<String>, Error> {
|
pub fn parse(law_id: usize) -> Result<Vec<String>, Error> {
|
||||||
let mut page = 1;
|
let mut page = 1;
|
||||||
let mut skip = true;
|
let mut skip = true;
|
||||||
@ -34,6 +39,7 @@ struct Overview {
|
|||||||
ogd_search_result: OgdSearchResult,
|
ogd_search_result: OgdSearchResult,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Remove, as we don't want to test internals?
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn parse_from_str_test(
|
pub(crate) fn parse_from_str_test(
|
||||||
content: &str,
|
content: &str,
|
||||||
|
@ -12,6 +12,7 @@ where
|
|||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) struct OgdSearchResult {
|
pub(crate) struct OgdSearchResult {
|
||||||
ogd_document_results: OgdDocumentResults,
|
ogd_document_results: OgdDocumentResults,
|
||||||
}
|
}
|
||||||
@ -49,12 +50,14 @@ impl OgdSearchResult {
|
|||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) struct OgdDocumentResults {
|
pub(crate) struct OgdDocumentResults {
|
||||||
hits: Hits,
|
hits: Hits,
|
||||||
ogd_document_reference: Vec<OgdDocumentReference>,
|
ogd_document_reference: Vec<OgdDocumentReference>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) struct Hits {
|
pub(crate) struct Hits {
|
||||||
#[serde(
|
#[serde(
|
||||||
rename = "@pageNumber",
|
rename = "@pageNumber",
|
||||||
@ -68,12 +71,14 @@ pub(crate) struct Hits {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub(crate) struct OgdDocumentReference {
|
pub(crate) struct OgdDocumentReference {
|
||||||
data: Data,
|
data: Data,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) struct Data {
|
pub(crate) struct Data {
|
||||||
#[serde(rename = "Metadaten")]
|
#[serde(rename = "Metadaten")]
|
||||||
metadata: Metadata,
|
metadata: Metadata,
|
||||||
@ -82,6 +87,7 @@ pub(crate) struct Data {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) struct Metadata {
|
pub(crate) struct Metadata {
|
||||||
#[serde(rename = "Technisch")]
|
#[serde(rename = "Technisch")]
|
||||||
technical: TechnicalMetadata,
|
technical: TechnicalMetadata,
|
||||||
@ -94,6 +100,7 @@ pub(crate) struct Metadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub(crate) struct TechnicalMetadata {
|
pub(crate) struct TechnicalMetadata {
|
||||||
#[serde(rename = "ID")]
|
#[serde(rename = "ID")]
|
||||||
@ -108,6 +115,7 @@ pub(crate) struct TechnicalMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) struct ImportTimestamp {
|
pub(crate) struct ImportTimestamp {
|
||||||
#[serde(rename = "@xsi:nil")]
|
#[serde(rename = "@xsi:nil")]
|
||||||
xsi_nil: String, //TODO: switch to bool
|
xsi_nil: String, //TODO: switch to bool
|
||||||
@ -117,6 +125,7 @@ pub(crate) struct ImportTimestamp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) struct GeneralMetadata {
|
pub(crate) struct GeneralMetadata {
|
||||||
#[serde(rename = "Geaendert")]
|
#[serde(rename = "Geaendert")]
|
||||||
changed: String, //TODO: switch to YYYY-MM-DD string
|
changed: String, //TODO: switch to YYYY-MM-DD string
|
||||||
@ -126,6 +135,7 @@ pub(crate) struct GeneralMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub(crate) struct FedMetadata {
|
pub(crate) struct FedMetadata {
|
||||||
#[serde(rename = "Kurztitel")]
|
#[serde(rename = "Kurztitel")]
|
||||||
@ -140,6 +150,7 @@ pub(crate) struct FedMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub(crate) struct BrKons {
|
pub(crate) struct BrKons {
|
||||||
kundmachungsorgan: String,
|
kundmachungsorgan: String,
|
||||||
@ -164,12 +175,14 @@ pub(crate) struct BrKons {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub(crate) struct DocumentList {
|
pub(crate) struct DocumentList {
|
||||||
content_reference: ContentReference,
|
content_reference: ContentReference,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub(crate) struct ContentReference {
|
pub(crate) struct ContentReference {
|
||||||
content_type: String,
|
content_type: String,
|
||||||
@ -178,12 +191,14 @@ pub(crate) struct ContentReference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub(crate) struct ContentUrl {
|
pub(crate) struct ContentUrl {
|
||||||
content_url: Vec<ContentUrlItem>,
|
content_url: Vec<ContentUrlItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub(crate) struct ContentUrlItem {
|
pub(crate) struct ContentUrlItem {
|
||||||
data_type: String,
|
data_type: String,
|
||||||
@ -213,7 +228,9 @@ mod tests {
|
|||||||
buf_reader.lines().collect()
|
buf_reader.lines().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: remove, as we don't want to test interal stuff?
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
#[serde(rename_all = "PascalCase")]
|
#[serde(rename_all = "PascalCase")]
|
||||||
pub(crate) struct Wrapper {
|
pub(crate) struct Wrapper {
|
||||||
ogd_search_result: OgdSearchResult,
|
ogd_search_result: OgdSearchResult,
|
||||||
|
Loading…
Reference in New Issue
Block a user