Compare commits
1 Commits
main
...
output-as-
Author | SHA1 | Date | |
---|---|---|---|
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())
|
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
|
//TODO: add test
|
||||||
pub fn to_md(&self) {
|
pub fn to_md(&self) {
|
||||||
for header in &self.header {
|
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)]
|
#[derive(Debug, Serialize, Deserialize, PartialEq)]
|
||||||
pub enum HeadingContent {
|
pub enum HeadingContent {
|
||||||
Paragraph(Section),
|
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 {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut to_write = if let Some(header) = &self.par_header {
|
let mut to_write = if let Some(header) = &self.par_header {
|
||||||
format!("{} ({})\n{}", self.symb, header, self.content)
|
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)]
|
#[derive(Clone, PartialEq)]
|
||||||
struct ClassifierInstance {
|
struct ClassifierInstance {
|
||||||
name: String, //e.g. 1 Theilstück
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -40,6 +40,9 @@ struct Args {
|
|||||||
/// Clears the cache (downloaded laws + paragraphs)
|
/// Clears the cache (downloaded laws + paragraphs)
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
clear_cache: bool,
|
clear_cache: bool,
|
||||||
|
|
||||||
|
#[arg(long)]
|
||||||
|
text: bool,
|
||||||
}
|
}
|
||||||
use tracing_subscriber::prelude::*;
|
use tracing_subscriber::prelude::*;
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -62,6 +65,9 @@ fn main() {
|
|||||||
parser.parse(par_url, &mut builder).unwrap();
|
parser.parse(par_url, &mut builder).unwrap();
|
||||||
let law: Law = builder.into();
|
let law: Law = builder.into();
|
||||||
println!("{law:?}");
|
println!("{law:?}");
|
||||||
|
} else if args.text {
|
||||||
|
let law = Law::from_config(&args.config).unwrap();
|
||||||
|
law.to_text();
|
||||||
} else {
|
} else {
|
||||||
let law = Law::from_config(&args.config).unwrap();
|
let law = Law::from_config(&args.config).unwrap();
|
||||||
law.to_md();
|
law.to_md();
|
||||||
|
Loading…
Reference in New Issue
Block a user