o
    gi(                     @   s:   d Z ddlZddlZddlZddlmZ G dd dZdS )a6  
Syllabification or syllabication, also known as hyphenation, is the separation of a word into syllables, whether spoken, written or signed.
A hyphenation algorithm is a set of rules, especially one codified for implementation in a computer program,
that decides at which points a word can be broken over two lines with a hyphen.
For example, a hyphenation algorithm might decide that impeachment can be broken as impeach-ment or im-peachment but not impe-achment.
One of the reasons for the complexity of the rules of word-breaking is that different "dialects" of English tend to differ on hyphenation[citation needed]:
American English tends to work on sound,
but British English tends to look to the origins of the word and then to sound.
There are also a large number of exceptions, which further complicates matters.
    N)Triec                   @   sV   e Zd ZU dZdZeed< dZeed< defddZ	e
d	fd
ededefddZdS )HyphenationaZ  
    Syllabification or syllabication, also known as hyphenation, is the separation of a word into syllables, whether spoken, written or signed.
    A hyphenation algorithm is a set of rules, especially one codified for implementation in a computer program,
    that decides at which points a word can be broken over two lines with a hyphen.
    For example, a hyphenation algorithm might decide that impeachment can be broken as impeach-ment or im-peachment but not impe-achment.
    One of the reasons for the complexity of the rules of word-breaking is that different "dialects" of English tend to differ on hyphenation[citation needed]:
    American English tends to work on sound,
    but British English tends to look to the origins of the word and then to sound.
    There are also a large number of exceptions, which further complicates matters.
       DO_NOT_HYPHENATE_BEFOREDO_NOT_HYPHENATE_AFTERiso_language_codec              	   C   s  t  | _d| _d| _d| _d| _g | _tt	j
d }|d|  }| s+J d| t|d}t| }|d D ]i}t|tsEJ tdt|D ]X}||  sUqLdd	d
 |d| D }ddd
 ||d  D }	t| jt|| _t| jt|| _t| jt|	| _t| jt|	| _t|| }
|
| j|d |	 < qLq<d|v r|d D ]}| j| qW d    d S W d    d S 1 sw   Y  d S )N   r   	resourcesz%s.jsonzNo hyphenation file for %srpatterns c                 S      g | ]}|  s|qS  isdigit.0cr   r   b/home/ubuntu/.local/lib/python3.10/site-packages/borb/pdf/canvas/layout/hyphenation/hyphenation.py
<listcomp>A       z(Hyphenation.__init__.<locals>.<listcomp>c                 S   r   r   r   r   r   r   r   r   B   r   0
exceptions)r   	_patterns_min_prefix_length_max_prefix_length_min_suffix_length_max_suffix_length_exceptionspathlibPath__file__parentexistsopenjsonloadsread
isinstancestrrangelenr   joinmaxminintappend)selfr   resources_dirhyphenation_pattern_filejson_file_handledatapiprefixsuffixdigiter   r   r   __init__(   sH   
"zHyphenation.__init__   shyphenation_characterreturnc                    s  t  dks
J dt |dkr|S | jD ]}ddd |D }||kr3d fdd|D   S qd| d }d	d td
t |D }tdt |D ]W}t| j| jd D ]K}|| d
k raqX||| | }	t| j| jd D ]0}
|d
kr}|
d
kr}qr||
 t |krqr||||
  }| j|	d |  }|rt	|| |||< qrqXqMd}tdt |d D ]9}|d t
jkr||| 7 }q|d t |t
j kr||| 7 }q|| d dkr| ||  7 }q||| 7 }q|S )a  
        This function hyphenates the input word, inserting the hyphenation_character wherever the word *can* be split
        in syllables. This function returns the word with hyphenation_character inserted.
        :param s:                       the str to be hyphenated
        :param hyphenation_character:   the character to insert to mark hyphenation
        :return:                        the hyphenated str
           z9The hyphenation_character must be a single character str.   r   c                 S   s   g | ]}|  r|qS r   isalphar   r   r   r   r   k   r   z)Hyphenation.hyphenate.<locals>.<listcomp>c                    s   g | ]
}|  r
|n qS r   rD   r   r@   r   r   r   m   s    .c                 S   s   g | ]}d qS )r   r   )r   _r   r   r   r   q   s    r   r   r   )r,   r   r-   r+   r   r   r   r   r   r.   r   r   r   )r2   r?   r@   r<   	e_raw_strs2hyphenation_infor8   jr9   kr:   values3r   rF   r   	hyphenateZ   sN   

zHyphenation.hyphenateN)__name__
__module____qualname____doc__r   r0   __annotations__r   r*   r=   chrrP   r   r   r   r   r      s   
 "2r   )rT   r&   typingr    borb.datastructure.str_trier   r   r   r   r   r   <module>   s   
