Ë
    jË5j´  ã                  ó<   — d Z ddlmZ ddlZddlmZ  G d„ d«      Zy)z!Utilities to measure OCR quality.é    )ÚannotationsN)ÚIterablec                  ó    — e Zd ZdZdd„Zdd„Zy)ÚOcrQualityDictionaryz3Manages a dictionary for simple OCR quality checks.c               ó$   — t        |«      | _        y)zÜConstruct a dictionary from a list of words.

        Words for which capitalization is important should be capitalized in the
        dictionary. Words that contain spaces or other punctuation will never match.
        N)ÚsetÚ
dictionary)ÚselfÚwordlists     úF/var/www/html/qr/venv/lib/python3.12/site-packages/ocrmypdf/quality.pyÚ__init__zOcrQualityDictionary.__init__   s   € ô ˜h›-ˆó    c                óœ  — t        j                  dd|«      }t        j                  dd|«      }t        j                  d|«      }|D ch c]  }t        |«      dk\  sŒ|’Œ }}d}|D ]F  }|| j                  v s1||j                  «       k7  sŒ%|j                  «       | j                  v sŒB|dz  }ŒH |dkD  r|t        |«      z  }|S d}|S c c}w )	a  Check how many unique words in the OCR text match a dictionary.

        Words with mixed capitalized are only considered a match if the test word
        matches that capitalization.

        Returns:
            number of words that match / number
        z[0-9_]+ú z\W+z\s+é   r   é   g        )ÚreÚsubÚsplitÚlenr	   Úlower)r
   Úocr_textÚtextÚtext_words_listÚwÚ
text_wordsÚmatchesÚ	hit_ratios           r   Úmeasure_words_matchedz*OcrQualityDictionary.measure_words_matched   sÍ   € ô v‰vj # xÓ0ˆÜv‰vf˜c 4Ó(ˆÜŸ(™( 6¨4Ó0ˆØ!0Ö@˜A´C¸³F¸a³K’aÐ@ˆ
Ð@àˆØò 	ˆAØD—O‘OÑ#ØQ—W‘W“Y“ 1§7¡7£9°·±Ò#?à˜1‘‘ð		ð
 29¸1²Gœc *›oÑ-ˆ	ØÐð CFˆ	ØÐùò As   Á	C	ÁC	N)r   zIterable[str])r   ÚstrÚreturnÚfloat)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   © r   r   r   r      s   „ Ù=ó(ôr   r   )r&   Ú
__future__r   r   Úcollections.abcr   r   r'   r   r   ú<module>r*      s   ðñ (å "ã 	Ý $÷ ò  r   