mirror of
https://git.pumpin.online/funkpower/catena.git
synced 2026-10-23 03:07:13 +00:00
recipes: the ocr flag depends on which verdict it was
This commit is contained in:
+29
-7
@@ -63,18 +63,40 @@ done
|
|||||||
carries good text needs none; one whose text layer is mojibake needs it badly,
|
carries good text needs none; one whose text layer is mojibake needs it badly,
|
||||||
and the mojibake is invisible until you read a retrieved passage.
|
and the mojibake is invisible until you read a retrieved passage.
|
||||||
|
|
||||||
|
`pdftriage` exits `0` when the layer is fine, `1` when it needs work, and `2`
|
||||||
|
when it could not tell — treat `2` as needing a human, not as a `1`.
|
||||||
|
|
||||||
|
But "needs work" is four different situations, and OCR is the wrong answer to
|
||||||
|
one of them. `--json` says which:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
for f in flat/*.pdf; do
|
for f in flat/*.pdf; do
|
||||||
if pdftriage --quiet "$f"; then
|
case "$(pdftriage --json "$f" | jq -r .text_layer)" in
|
||||||
pdftotext -layout "$f" "text/$(basename "$f" .pdf).txt"
|
healthy)
|
||||||
else
|
pdftotext -layout "$f" "text/$(basename "$f" .pdf).txt" ;;
|
||||||
ocrmypdf --redo-ocr "$f" "ocr/$(basename "$f")" # not part of this suite
|
reflected_font)
|
||||||
fi
|
# The one verdict where OCR is the wrong answer: every character is
|
||||||
|
# already in the file, permuted by a non-standard font encoding, and
|
||||||
|
# undoing the permutation recovers the text exactly. `pdftriage`'s
|
||||||
|
# `reflect::undo` does that in process; from a shell today it is still
|
||||||
|
# an OCR, which is an hour of GPU time to recover text the file holds.
|
||||||
|
ocrmypdf --force-ocr "$f" "ocr/$(basename "$f")" ;;
|
||||||
|
absent)
|
||||||
|
# A scan, with nothing to preserve. The default refuses a file that
|
||||||
|
# already has text, which is what you want here.
|
||||||
|
ocrmypdf "$f" "ocr/$(basename "$f")" ;;
|
||||||
|
garbled|sparse)
|
||||||
|
# --force-ocr, not --redo-ocr. The text layer looks fine to a machine
|
||||||
|
# and is mojibake, so anything that "keeps the text it judges good"
|
||||||
|
# keeps precisely the text that is wrong.
|
||||||
|
ocrmypdf --force-ocr "$f" "ocr/$(basename "$f")" ;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
```
|
```
|
||||||
|
|
||||||
`pdftriage` exits `0` when the layer is fine, `1` when it needs OCR, and `2`
|
`ocrmypdf` and `tesseract` are not part of this suite and will not be. A
|
||||||
when it could not tell — treat `2` as needing a human, not as a `1`.
|
trained OCR model and a PDF rebuilt around an invisible text layer are not a
|
||||||
|
filter's work; deciding *whether* to call one, and with which flag, is.
|
||||||
|
|
||||||
**3. Convert to markdown.** Whatever you like: `pandoc`, `marker`, `pdftotext`
|
**3. Convert to markdown.** Whatever you like: `pandoc`, `marker`, `pdftotext`
|
||||||
and a script. Nothing here cares, as long as what comes out is markdown with
|
and a script. Nothing here cares, as long as what comes out is markdown with
|
||||||
|
|||||||
Reference in New Issue
Block a user