output similar to how ris does it (for verification if everything has been properly parsed)
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m7s
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m7s
This commit is contained in:
parent
7e88257df6
commit
f984e3ad61
14
clean_verification_txt.sh
Executable file
14
clean_verification_txt.sh
Executable file
@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
sed -i '/^$/d' ~/ris.txt
|
||||
sed -i '/^Text$/d' ~/ris.txt
|
||||
sed -i 's/^[ \t]*//;s/[ \t]*$//' ~/ris.txt
|
||||
sed -i -E ':a;N;$!ba;s/\n(\([0-9]+\))\n/\n\1 /g' ~/ris.txt
|
||||
sed -i -E ':a;N;$!ba;s/(\n[0-9]+\.)\n/\1 /g' ~/ris.txt
|
||||
sed -i -E ':a;N;$!ba;s/(\n[0-9]+\))\n/\1 /g' ~/ris.txt
|
||||
sed -i -E ':a;N;$!ba;s/(\n[a-z]+\))\n/\1 /g' ~/ris.txt
|
||||
awk '!seen[$0] { lines[$0]=NR } seen[$0] && (NR-lines[$0] <= 5) { delete lines[$0]; lines[$0]=NR } { seen[$0]=1; all[NR]=$0 } END { for (i = 1; i <= NR; i++) if (lines[all[i]] == i) print all[i] }' ~/ris.txt > temp && mv temp ~/ris.txt
|
||||
|
||||
|
||||
|
||||
awk 'NR==FNR {if (/\.$/) {sub(/\..*$/, "", $0); seen[$0]=1} next} !seen[$0]' ~/ris.txt ~/ris.txt > temp && mv temp ~/ris.txt
|
@ -89,6 +89,25 @@ impl Law {
|
||||
Ok(builder.into())
|
||||
}
|
||||
|
||||
pub fn to_text(&self) {
|
||||
for header in &self.header {
|
||||
Self::print_text(header, 2);
|
||||
}
|
||||
}
|
||||
fn print_text(header: &Heading, level: usize) {
|
||||
println!("{}", header.to_text());
|
||||
for content in &header.content {
|
||||
match content {
|
||||
HeadingContent::Heading(h) => {
|
||||
Self::print_text(h, level + 1);
|
||||
}
|
||||
HeadingContent::Paragraph(p) => {
|
||||
println!("{}", p.to_text());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: add test
|
||||
pub fn to_md(&self) {
|
||||
for header in &self.header {
|
||||
@ -147,6 +166,18 @@ impl Display for Heading {
|
||||
}
|
||||
}
|
||||
|
||||
impl Heading {
|
||||
pub fn to_text(&self) -> String {
|
||||
let mut ret = format!("{}", self.name);
|
||||
|
||||
if let Some(desc) = &self.desc {
|
||||
ret.push_str(&format!("\n{desc}"));
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub enum HeadingContent {
|
||||
Paragraph(Section),
|
||||
@ -545,7 +576,7 @@ impl fmt::Debug for Section {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Section {
|
||||
impl Display for Section {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut to_write = if let Some(header) = &self.par_header {
|
||||
format!("{} ({})\n{}", self.symb, header, self.content)
|
||||
@ -560,6 +591,20 @@ impl fmt::Display for Section {
|
||||
}
|
||||
}
|
||||
|
||||
impl Section {
|
||||
pub fn to_text(&self) -> String {
|
||||
let mut ret = format!("{}\n", self.symb);
|
||||
|
||||
if let Some(par_header) = &self.par_header {
|
||||
ret.push_str(&format!("{}\n", par_header));
|
||||
}
|
||||
|
||||
ret.push_str(&format!("{}", self.content.to_text()));
|
||||
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
struct ClassifierInstance {
|
||||
name: String, //e.g. 1 Theilstück
|
||||
@ -721,6 +766,24 @@ impl Display for Content {
|
||||
}
|
||||
}
|
||||
|
||||
impl Content {
|
||||
pub fn to_text(&self) -> String {
|
||||
let mut ret = String::new();
|
||||
match self {
|
||||
Self::Text(a) => ret.push_str(&format!("{a}\n")),
|
||||
Self::List(a) | Self::Multi(a) => {
|
||||
let mut tmp = String::new();
|
||||
for aa in a {
|
||||
tmp.push_str(&format!("{}\n", aa.to_text()));
|
||||
}
|
||||
ret.push_str(&tmp);
|
||||
}
|
||||
}
|
||||
let ret = ret.trim();
|
||||
ret.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs;
|
||||
|
@ -40,6 +40,9 @@ struct Args {
|
||||
/// Clears the cache (downloaded laws + paragraphs)
|
||||
#[arg(long)]
|
||||
clear_cache: bool,
|
||||
|
||||
#[arg(long)]
|
||||
text: bool,
|
||||
}
|
||||
use tracing_subscriber::prelude::*;
|
||||
fn main() {
|
||||
@ -62,6 +65,9 @@ fn main() {
|
||||
parser.parse(par_url, &mut builder).unwrap();
|
||||
let law: Law = builder.into();
|
||||
println!("{law:?}");
|
||||
} else if args.text {
|
||||
let law = Law::from_config(&args.config).unwrap();
|
||||
law.to_text();
|
||||
} else {
|
||||
let law = Law::from_config(&args.config).unwrap();
|
||||
law.to_md();
|
||||
|
Loading…
Reference in New Issue
Block a user