o
    Pôj»  ã                   @   s   d Z ddlZddlZddlZddlZddlZddlZg d¢Zej 	ej 
e¡d¡Zddddd	dddd
d
dœ
ZddlZd@dd„Zd
eiZe ¡ Ze ¡  dd„ Zdd„ Zdd„ Zdd„ Ze d¡dd„ ƒZe d¡dd„ ƒZdAdd„Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Z	 d&d'„ Z dBd)d*„Z!d+d,„ Z"d@d-d.„Z#d/d0d1œd2d3„Z$d4d5„ Z%d6d7„ Z&dCd9d:„Z'd;d<„ eD ƒZ(e'ƒ Z)d=d>„ eD ƒ\Z*Z+Z,Z-Z.e/d?krÎddl0Z0e0 1¡  dS dS )DzÙ
get_groups_list
    resolve_fname
        load
            load_file
                as_valid_path
            get_matched_categories
                close_matches
                    as_valid_path
getallcategories

é    N)Ú
adjectivesÚnounsÚverbsÚnamesÚipsumZ	wordlistsr   r   r   r   r   Úuuid)
ÚaÚnÚvÚnmÚipÚadjÚnnZvbÚuÚuuc                 C   s   t t ¡ ƒd | ot| ƒ… S ©N)Ústrr   Úuuid4Úint)r	   © r   ú`/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/randomname/util.pyÚuuid_)   s   r   c                    s   ddœ‡ fdd„
}|S )z˜Set randomname (pseudo-)random number generator seed to ensure reproducibility 
        before executing the method. 
        Does nothing if seed=None.N)Úseedc                    s$   | d ur	t  | ¡ ˆ |i |¤Ž}|S r   )Úrngr   )r   ÚargsÚkwargsÚresult©Úmethodr   r   Údecorated_method7   s   
z2run_with_set_random_seed.<locals>.decorated_methodr   )r   r   r   r   r   Úrun_with_set_random_seed3   s   r    c                 C   ó   dd„ t | ƒD ƒS )z)Get word lists from multiple word groups.c                 S   ó   g | ]}t |ƒD ]}|‘qqS r   )Úresolve_fname)Ú.0ÚfÚxr   r   r   Ú
<listcomp>A   ó    z#get_groups_list.<locals>.<listcomp>©Úas_multiple©Úfnamesr   r   r   Úget_groups_list?   s   r-   c                 C   s   d| v rt | ƒS | gS )zODetect if fname is a path or is a literal word. Replace any path
    shortcuts.ú/)Úload)Úfnamer   r   r   r#   D   s   r#   c                 C   r!   )z­Load a list of words from file. Can use glob matching to load
    multiple files.

    Examples:
    >>> load('n/music') == ['arrange', 'carol', 'compose', ... 'yodel']
    c                 S   r"   r   )Ú	load_file)r$   r%   Úwr   r   r   r'   Q   r(   zload.<locals>.<listcomp>)Úget_matched_categories©Únamer   r   r   r/   J   s   r/   é€   c                 C   s–   |   d¡}|d tv r"tjt|d  gdd„ |dd… D ƒ¢R Ž gS tt| dd�d	ƒ�}d
d„ dd„ | ¡ D ƒD ƒW  d  ƒ S 1 sDw   Y  dS )z1Load a wordlist. Does not do any name conversion.r.   r   c                 s   s   � | ]	}|d kr|V  qdS )Ú*Nr   ©r$   Úpr   r   r   Ú	<genexpr>Y   ó   € zload_file.<locals>.<genexpr>é   NT)ÚrequiredÚrc                 S   s    g | ]}|r|d  dvr|‘qS )r   z;#r   ©r$   Úlr   r   r   r'   \   s    þÿzload_file.<locals>.<listcomp>c                 s   s   � | ]}|  ¡ V  qd S r   )Ústripr?   r   r   r   r:   ]   s   € )ÚsplitÚ
WORD_FUNCSÚ	functoolsÚpartialÚopenÚas_valid_pathÚ	readlines)r5   Úpartsr%   r   r   r   r1   T   s   
.ÿ$ÿr1   c                    s–   t ˆ ƒ‰ ˆ  d¡rˆ d7 ‰ ‡ fdd„tD ƒ}|r|S ˆ  dd¡‰‡fdd„tD ƒ}|r-|S tˆ g|¢R i |¤Ž}td ˆ |rGd t|ƒ¡¡ƒ‚d	¡ƒ‚)
zRResolve a fuzzy-matched category. Throw an error if it doesn't
    match anything.r.   r7   c                    s   g | ]
}t   |ˆ ¡r|‘qS r   )Úfnmatch©r$   r%   r4   r   r   r'   i   ó    z*get_matched_categories.<locals>.<listcomp>r<   c                    s.   g | ]}t   |ˆ d  ¡rd |ˆ d f¡‘qS )r   r.   r<   )rJ   ÚjoinrK   )rI   r   r   r'   n   s   . zNo matching wordlist '{}'. {}zDid you mean {}?zNo close matches found.)	ÚdoaliasÚendswithÚALL_CATEGORIESrB   rC   Úclose_matchesÚ
ValueErrorÚformatÚ_or_fmt)r5   r   ÚkwÚmatchesr   )r5   rI   r   r3   a   s    
ÿþr3   çÍÌÌÌÌÌä?c                    s4  t ˆ ƒ‰ ‡ fdd„tD ƒ}dd„ tD ƒ}dˆ v r†ˆ  dd¡\‰‰ˆs$d‰ˆtv rBtˆtˆ |d�}|dd„ ‡fd	d
„|D ƒD ƒ7 }n,ˆ|v retˆ‡fdd„tD ƒ|d�}|dd„ ‡fdd
„|D ƒD ƒ7 }n	|tˆ t|d�7 }tˆttƒ|d�}|‡fdd„|D ƒ7 }t|ƒS tˆ ||d�}|dd„ |D ƒ7 }t|ƒS )z#Find close matching wordlist names.c                    s$   g | ]}ˆ |  d d¡d kr|‘qS )r.   r<   ©rB   )r$   Úcatr4   r   r   r'   }   s   $ z!close_matches.<locals>.<listcomp>c                 S   s   g | ]
}|  d d¡d ‘qS )r.   r<   éÿÿÿÿrX   )r$   Úcr   r   r   r'   ~   rL   r.   r<   r7   )Úcutoffc                 S   ó   g | ]}t |ƒr|‘qS r   ©rG   rK   r   r   r   r'   ‡   ó    c                 3   s   � | ]	}d   ˆ |¡V  qdS ©ú{}/{}N©rS   ©r$   Úm)Úpart0r   r   r:   ‡   r;   z close_matches.<locals>.<genexpr>c                    s   g | ]
}ˆ t | v r|‘qS r   ©Ú	AVAILABLE©r$   Úk©Úpart1r   r   r'   Š   rL   c                 S   r]   r   r^   rK   r   r   r   r'   ‹   r_   c                 3   s   � | ]	}d   |ˆ ¡V  qdS r`   rb   rc   rj   r   r   r:   ‹   r;   c                    s   g | ]}d   |ˆ ¡‘qS ©ra   rb   rc   rj   r   r   r'   �   r_   c                 S   s&   g | ]}t |ƒD ]}d  ||¡‘qqS rl   )Úfind_parts_of_speechrS   )r$   rY   Úposr   r   r   r'   ”   s    þ
ÿÿ)	rN   rP   rB   ÚWORD_CLASSESÚ_get_matchesrg   ÚlistrC   Ú_ordered_unique)r5   r\   rV   Zall_sub_categoriesZ_msr   )r5   re   rk   r   rQ   y   s,   ""	úþrQ   c                    s&   t jˆ |fi |¤Ž‡ fdd„|D ƒ S )Nc                    s&   g | ]}|  ˆ ¡st |ˆ ¡r|‘qS r   )Ú
startswithrJ   rc   ©Úpatternr   r   r'   Ÿ   ó   & z _get_matches.<locals>.<listcomp>)ÚdifflibÚget_close_matches)ru   Ú	availablerU   r   rt   r   rp   œ   s   ÿÿrp   c                 C   s   d  dd„ | D ƒ¡S )Nz or c                 s   s   � | ]}d   |¡V  qdS )z'{}'Nrb   rK   r   r   r   r:   ¤   s   € z_or_fmt.<locals>.<genexpr>)rM   r+   r   r   r   rT   £   s   rT   c                 C   s$   g }| D ]}||vr|  |¡ q|S r   ©Úappend)ÚxsÚuniquer&   r   r   r   rr   §   s   
€rr   c                 C   s8   i }| D ]}||ƒ}||vrg ||< ||   |¡ q|S r   rz   )ÚitemsÚfuncÚgroupsr&   ri   r   r   r   Ú_groupby¯   s   r�   c                    s:   |   d¡}t ¡ D ]\‰ ‰‡ ‡fdd„|D ƒ}q	d |¡S )z6Replace aliases in string.

    Examples:
    >>>
    r.   c                    s   g | ]
}|ˆ kr
ˆn|‘qS r   r   ©r$   r&   ©ri   r
   r   r   r'   È   rL   zdoalias.<locals>.<listcomp>)rB   ÚALIASESr~   rM   )r0   rI   r   rƒ   r   rN   À   s   

rN   Fc                 C   sj   t j t j|  ¡}t j |t j t j¡¡}t j t|d ¡}t j |¡s3|r1td| › d|› d�ƒ‚d S |S )Nz.txtz
Wordlist 'z' does not exist at location 'z'.)	ÚosÚpathÚabspathÚsepÚrelpathrM   Ú	WORD_PATHÚisfileÚOSError)r5   r=   r†   r   r   r   rG   Ì   s   rG   c                    s   ‡ fdd„t |ƒD ƒS )z$Prefix all items with a path prefix.c                    s&   g | ]}ˆ   d ¡› d | d ¡› �‘qS ©r.   )ÚrstripÚlstripr‚   ©Úprer   r   r'   Ù   rv   zprefix.<locals>.<listcomp>r)   )r‘   r|   r   r�   r   Úprefix×   ó   r’   c                 C   sV   t | ƒ} |du rt | ¡ntj| |d�}t|tƒr"dd„ |D ƒ}|S t|ƒr)|ƒ }|S )zChoose one item from a list.N)ri   c                 S   s   g | ]}t |ƒr|ƒ n|‘qS r   )Úcallable)r$   Úxir   r   r   r'   â   r(   zchoose.<locals>.<listcomp>)r*   r   ÚchoiceÚchoicesÚ
isinstancerq   r”   )r~   r	   r&   r   r   r   ÚchooseÜ   s    
þr™   é2   T)Ún_failsr}   c          	         sn   |s‡ ‡‡fdd„t |ƒD ƒS tƒ }t |ƒD ]}t |ƒD ]}| ˆˆ i ˆ¤Ž¡ t|ƒ|kr0 nq |S q|S )Nc                    s   g | ]	}ˆˆ i ˆ¤Ž‘qS r   r   )r$   Ú_©r   r   rU   r   r   r'   é   ó    z!sample_unique.<locals>.<listcomp>)ÚrangeÚsetÚaddÚlen)	r   r	   r›   r}   r   rU   ÚwordsÚiÚjr   r�   r   Úsample_uniqueç   s   ÿýr¦   c                 C   s&   t | ttfƒr	| n| g} dd„ | D ƒS )zEnsure a list or tuple.c                 S   s2   g | ]}t |ƒr|gnt|ƒ d ¡D ]}|‘qqS )ú,)r”   r   rB   )r$   ÚsÚsir   r   r   r'   ø   s   2 zas_multiple.<locals>.<listcomp>)r˜   rq   Útuple)r&   r   r   r   r*   õ   s   r*   c                    s   ‡ fdd„t  ¡ D ƒS )z5Given a name, find all the groups that it belongs to.c                    s   h | ]
\}}ˆ |v r|’qS r   r   )r$   ri   r
   r4   r   r   Ú	<setcomp>ý   rL   z'find_parts_of_speech.<locals>.<setcomp>)rg   r~   r4   r   r4   r   rm   û   r“   rm   Ú c                    sB   t j tˆ ¡‰ ‡ fdd„tjt j ˆ d¡dd�D ƒ}dd„ |D ƒS )zSGet all categories (subdirectories) from a word class (adjectives,
    nouns, etc.)c                    s&   g | ]}t j t j |¡d  ˆ ¡‘qS )r   )r…   r†   r‰   ÚsplitextrK   ©Údr   r   r'     s    ÿÿz$getallcategories.<locals>.<listcomp>z**/*.txtT)Ú	recursivec                 S   s   g | ]	}|  tjd ¡‘qS r�   )Úreplacer…   rˆ   r8   r   r   r   r'   
  rž   )r…   r†   rM   rŠ   Úglob)r¯   Zpath_to_all_categoriesr   r®   r   Úgetallcategories   s
   
þr³   c                 C   s   i | ]}|t |ƒ“qS r   )r³   rh   r   r   r   Ú
<dictcomp>  s    r´   c                 C   s   g | ]}t | ‘qS r   rf   rh   r   r   r   r'     s    ÿr'   Ú__main__r   )rW   )F)r¬   )2Ú__doc__r…   r²   rJ   rD   Úrandomrw   ro   r†   rM   ÚdirnameÚ__file__rŠ   r„   r   r   rC   ÚRandomr   r   r    r-   r#   r/   Ú	lru_cacher1   r3   rQ   rp   rT   rr   r�   rN   rG   r’   r™   r¦   r*   rm   r³   rg   rP   Ú
ADJECTIVESÚNOUNSÚVERBSÚNAMESÚIPSUMÚ__name__ÚfireÚFirer   r   r   r   Ú<module>   sr    õ
ÿ



#



ÿþ