
    11i[              	           S r SSKrSSKJr  SSKJr  SSKJrJrJ	r	J
r
  SSKrS\
\   S\\   4S jrS	\\\\   4   S\\   4S
 jrS	\\\\   4   S\4S jrS	\\\\   4   S\S\	\\\      \\   4   4S jrS\S\4S jrS\S\	\S4   4S jrg)z-Provides utility functions for the phonemizer    N)Number)Path)UnionListTupleIterableiterablereturnc                 J    / nSnU  H  nX#-  nUR                  U5        M     U$ )z6Returns the cumulative sum of the `iterable` as a listr   )append)r	   res
cumulativevalues       J/home/james-whalen/.local/lib/python3.13/site-packages/phonemizer/utils.pycumsumr      s1    
CJ


:  J    textc                     [        U [        5      (       a<  U R                  [        R                  5      R                  [        R                  5      $ U $ )z8Returns the string `text` as a list of lines, split by 
)
isinstancestrstriposlinesepsplitr   s    r   str2listr   #   s6    $zz"**%++BJJ77Kr   c                 n    [        U [        5      (       a  U $ [        R                  R	                  U 5      $ )zBReturns the list of lines `text` as a single string separated by 
)r   r   r   r   joinr   s    r   list2strr   *   s'    $::??4  r   numc                 Z   [        U 5      n [        [        S[        U 5      U-  5      5      n[	        U[        U 5      5      n[        US-
  5       Vs/ s H  o@XB-  US-   U-   PM     nnXS-
  U-  S nU(       a  UR                  U5        S/[        S USS  5       5      -   nXW4$ s  snf )a  Return a maximum of `num` equally sized chunks of a `text`

    This method is usefull when phonemizing a single text on multiple jobs.

    The exact number of chunks returned is `m = min(num, len(str2list(text)))`.
    Only the m-1 first chunks have equal size. The last chunk can be longer.
    The input `text` can be a list or a string. Return a list of `m` strings.

    Parameters
    ----------
    text (str or list) : The text to divide in chunks

    num (int) : The number of chunks to build, must be a strictly positive
    integer.

    Returns
    -------
    chunks (list of list of str) : The chunked text with utterances separated
        by '
'.

    offsets (list of int) : offset used below to recover the line numbers in
        the input text wrt the chunks

       Nr   c              3   8   #    U  H  n[        U5      v   M     g 7fN)len).0cs     r   	<genexpr>chunks.<locals>.<genexpr>V   s     =,<qCFF,<   )r   intmaxr%   minranger   r   )r   r    sizenchunksitext_chunkslastoffsetss           r   chunksr6   1   s    4 tnDs1c$i#o&'D#s4y!G 05Wq[/AC/A!QXq1un%/A  C 1$%&D4 cF=K,<=>>GCs   B(pathc                 T    [         R                  R                  S5      S-  U -  n U R                  5       (       d  [        SU  35      eU R                  5       $ ! [         aC    [         R                  R	                  SS5       nX-  n SSS5         Mm  ! , (       d  f        N|= ff = f)a  Returns the absolute path to a phonemizer resource file or directory

The packages resource are stored within the source tree in the
'phonemizer/share' directory and, once the package is installed, are moved
to another system directory (e.g. /share/phonemizer).

Parameters
----------
path (str) : the file or directory to get, must be relative to
    'phonemizer/share'.

Raises
------
ValueError if the required `path` is not found

Returns
-------
The absolute path to the required resource as a `pathlib.Path`


phonemizershareNz'the requested resource does not exist: )	importlib	resourcesfilesAttributeErrorr7   exists
ValueErrorresolve)r7   r:   s     r   get_package_resourcerB   Z   s    * ""((6@4G
 ;;==B4&IJJ<<>     %%lG<<D =<<< s)   %A *B'B	B'
B#	B'#B'version.c                 d    [        S U R                  SS5      R                  S5       5       5      $ )zReturns a tuple of integers from a version string

Any '-dev' in version string is ignored. For instance, returns (1, 2, 3)
from '1.2.3' or (0, 2) from '0.2-dev'

c              3   8   #    U  H  n[        U5      v   M     g 7fr$   )r,   )r&   vs     r   r(   #version_as_tuple.<locals>.<genexpr>   s     H!GAQ!Gr*   z-dev .)tuplereplacer   )rC   s    r   version_as_tuplerL   |   s+     H!<!B!B3!GHHHr   )__doc__r   numbersr   pathlibr   typingr   r   r   r   r;   r   r   r   r   r,   r6   rB   rL    r   r   <module>rR      s    4 	   / / Xf% $v, 5d3i( T#Y !5d3i( !S !& sDI~& & S & d3i$s)+,& Rs t DIc IeCHo Ir   