OCR

This script OCRs images using the Google Vision API.

corppa.ocr.gvision_ocr.ocr_image_via_gvision(gvision_client: google_vision.ImageAnnotatorClient, input_image: Path, out_txt: Path, out_json: Path) None

Perform OCR for input image using the Google Cloud Vision API via the provided client. The plaintext output and json response of the OCR call are written to out_txt and out_json paths respectively.

corppa.ocr.gvision_ocr.ocr_images(in_dir: Path, out_dir: Path, exts: Iterable[str], ocr_limit: int = 0, show_progress: bool = True) dict[str, int]

OCR images in in_dir with extension exts to out_dir. If ocr_limit > 0, stop after OCRing ocr_limit images.

Returns a map structure reporting the number of images OCR’d and skipped.

corppa.ocr.gvision_ocr.ocr_volumes(vol_ids: list[str], in_dir: Path, out_dir: Path, exts: Iterable[str], ocr_limit: int = 0, show_progress: bool = True) None

OCR images for volumes vol_ids with extension exts to out_dir. Assumes in_dir follows the PPA directory conventions (see corppa.utils.path_utils for more details). If ocr_limit > 0, stop after OCRing ocr_limit images.

Collate Texts

Script to turn directories containing multiple text files into a single JSON file containing text contents of all files with page numbers based on text filenames. (Page number logic is currently Gale-specific).

Note: This was used to create work-level text corpora files after running OCR.

Example usage:

python collate_txt.py top-level-input-dir top-level-output-dir