diff options
| author | WriterV2 <primary-v2@protonmail.com> | 2023-02-12 12:07:16 +0100 |
|---|---|---|
| committer | WriterV2 <primary-v2@protonmail.com> | 2023-02-12 12:07:16 +0100 |
| commit | 7d9665520e3461c43e3cc1b4f585ed5bbfd13a32 (patch) | |
| tree | 6e21e9131617b7b2b4f15c4b733b9693667beefd /src | |
| parent | 4ebeca021392865a540f81a25680a70eba323907 (diff) | |
Fix text extracting regex to an extent + add linebreaks before quotes
Diffstat (limited to 'src')
| -rw-r--r-- | src/works/stories.rs | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/src/works/stories.rs b/src/works/stories.rs index 4bd492b..8f0cb53 100644 --- a/src/works/stories.rs +++ b/src/works/stories.rs @@ -70,21 +70,27 @@ impl Story { // extract text from pdf document fn get_text(&self) -> anyhow::Result<String> { // TODO: - // - Clean and optimise - // - Find a solution where you can use 1-2 digit numbers in the texts - // - You should add linebreaks between paragraphs + // - 1-2 digit number with linebreak e.g. "Es ist 10\n geworden" not usable in texts + // - currently only linebreaks before quotes, but not after paragraphs let mut text = pdf_extract::extract_text(format!("docs/stories/{}", &self.path_to_document))?; - let re = regex::Regex::new(r"\d{1,2}")?; - let re2 = regex::Regex::new(r"-\d{1,2}\n+ ?")?; - let re3 = regex::Regex::new(r"-\n+")?; - let re4 = regex::Regex::new(r"\n\n")?; - let re5 = regex::Regex::new(r"\n")?; - text = re2.replace_all(&text, "").to_string(); - text = re.replace_all(&text, "").to_string(); - text = re3.replace_all(&text, "").to_string(); - text = re4.replace_all(&text, " ").to_string(); - text = re5.replace_all(&text, "").to_string(); + + text = regex::Regex::new(r"\n\n»")? + .replace_all(&text, "<br>»") + .to_string(); + text = regex::Regex::new(r"\d{1,2}?\n \d")? + .replace_all(&text, "") + .to_string(); + text = regex::Regex::new(r"-?\d{1,2}\n")? + .replace_all(&text, "") + .to_string(); + text = regex::Regex::new(r"-\n\n")? + .replace_all(&text, "") + .to_string(); + text = regex::Regex::new("\n\n")? + .replace_all(&text, " ") + .to_string(); + Ok(text) } } |
