Compare commits
No commits in common. "42f6b637157ff46763290e159133ae35fe6ead13" and "868be4bdda3a786253d95980c2d5aa0834af7aa6" have entirely different histories.
42f6b63715
...
868be4bdda
1 changed files with 1 additions and 20 deletions
|
|
@ -8,30 +8,11 @@ function getWorker() {
|
|||
return workerPromise;
|
||||
}
|
||||
|
||||
// OCR breaks lines wherever the photographed page did, so the raw text has a
|
||||
// newline after nearly every few words. Join those into flowing text, but keep
|
||||
// blank lines as paragraph breaks.
|
||||
function joinLines(paragraph: string): string {
|
||||
return (
|
||||
paragraph
|
||||
// Re-join words hyphenated across a line break ("Verwal-\ntung" -> "Verwaltung").
|
||||
.replace(/(\p{L})-\n(\p{Ll})/gu, "$1$2")
|
||||
// Keep real hyphens in compounds split across lines ("Nord-\nSüd" -> "Nord-Süd").
|
||||
.replace(/(\p{L}-)\n(\p{Lu})/gu, "$1$2")
|
||||
.replace(/\s*\n\s*/g, " ")
|
||||
);
|
||||
}
|
||||
|
||||
function cleanUpText(raw: string): string {
|
||||
return raw
|
||||
.normalize("NFC")
|
||||
.replace(/\r\n?/g, "\n")
|
||||
.replace(/[ \t]+\n/g, "\n")
|
||||
.split(/\n\s*\n/)
|
||||
.map((paragraph) => joinLines(paragraph.trim()))
|
||||
.filter(Boolean)
|
||||
.join("\n\n")
|
||||
.replace(/[ \t]{2,}/g, " ")
|
||||
.replace(/\n{3,}/g, "\n\n")
|
||||
.trim();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue