<commit_before>#!/bin/bash
set -o errexit -o nounset

if [ $# != 2 -a $# != 3 ]; then
    echo "usage: $0 image_pdf_filename output_text_filename [tesseract_language_code(s)]"
    exit 1
fi

temp_dir_name=$(mktemp -d)
trap 'rm -rf "${temp_dir_name}"' EXIT

rm -f "$2"
pdfimages "$1" "${temp_dir_name}/out"
for image in "${temp_dir_name}/out"*; do
    if [ $# == 2 ]; then
	tesseract "$image" stdout >> "$2"
    else
	tesseract "$image" stdout -l "$3" >> "$2"
    fi
done

exit 0<commit_msg>Now we clean-up our temporary directory when we get a SIGTERM.<commit_after>#!/bin/bash
set -o errexit -o nounset

if [ $# != 2 -a $# != 3 ]; then
    echo "usage: $0 image_pdf_filename output_text_filename [tesseract_language_code(s)]"
    exit 1
fi

temp_dir_name=$(mktemp -d)
trap 'rm -rf "${temp_dir_name}"' SIGTERM

rm -f "$2"
pdfimages "$1" "${temp_dir_name}/out"
for image in "${temp_dir_name}/out"*; do
    if [ $# == 2 ]; then
	tesseract "$image" stdout >> "$2"
    else
	tesseract "$image" stdout -l "$3" >> "$2"
    fi
done

rm -rf "${temp_dir_name}"

exit 0
{'fraction_non_alphanumeric': 0.17752596789423986, 'fraction_numerical': 0.02077431539187913, 'mean_word_length': 3.690265486725664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5798874', 'n_tokens_mistral': 442, 'n_tokens_neox': 431, 'n_words': 124}