mirror of
https://git.pumpin.online/funkpower/catena.git
synced 2026-11-24 19:32:56 +00:00
bibclean: repair mojibake, word-processor prefixes, extensions and "- Unknown"
textkit gains mojibake::repair, which reads UTF-8 that was decoded as Windows-1252 back into what it was. It is certain rather than guessed: every character has to turn back into a byte and the bytes have to be valid UTF-8, which real Latin-1 text almost never is. bibclean names two new faults, mojibake_title/mojibake_author and placeholder_suffix, and now repairs four it only named before: - mojibake in the title or author; - "Microsoft Word - " and the like on the front of a title (junk_title); - a document extension on the end (filename_title); - a placeholder author on the end, "Title - Unknown" (placeholder_suffix). A wrapper is taken off only when what is left is still a title, so "Microsoft Word - Document2" and "0195152972.pdf" stay flagged. "Document1", "Document2" and so on now count as placeholder titles. Run over a 6,022-record catalogue: 120 records repaired by the new rules (67 suffixes, 28 extensions, 21 prefixes, 4 mojibake), none of them wrong.
This commit is contained in:
7 files changed
+359
-1
No files matched your search
@@ -115,6 +115,24 @@ fires on one side and not the other:
|
||||
The boundary forms are lookarounds, so a pattern using them needs an engine
|
||||
that has them.
|
||||
|
||||
## Mojibake
|
||||
|
||||
UTF-8 text that something decoded as Windows-1252 on the way, put back:
|
||||
|
||||
```rust
|
||||
assert_eq!(
|
||||
textkit::mojibake::repair("L'impérialisme américain").as_deref(),
|
||||
Some("L'impérialisme américain"),
|
||||
);
|
||||
assert_eq!(textkit::mojibake::repair("café"), None);
|
||||
```
|
||||
|
||||
The repair turns each character back into the byte it was decoded from and
|
||||
reads the bytes as UTF-8. Real text almost never survives that trip — a
|
||||
genuine "café" becomes a lone `0xe9`, which is not UTF-8 — so a string that
|
||||
does was misread, and the answer is certain rather than guessed. Text misread
|
||||
twice is unwound twice; text that is only partly repairable is left alone.
|
||||
|
||||
## See also
|
||||
|
||||
- [`corpus-core`](../corpus-core/README.md) — the records these help produce.
|
||||
|
||||
Reference in new issue
Block a user