o
    ii                     @   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rddl0Z0e01  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ipsum	wordlistsr   r   r   r   r   uuid)
anvnmipadjnnvbuuuc                 C   s   t t d | ot|  S N)strr   uuid4int)r
    r   M/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/randomname/util.pyuuid_)   s   r   c                    s   dd fdd
}|S )zSet 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#   )zLoad 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   r1   J   s   r1      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.r0   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   )striprA   r   r   r   r<   ]   s    )split
WORD_FUNCS	functoolspartialopenas_valid_path	readlines)r7   partsr'   r   r   r   r3   T   s   
.$r3   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.r0   r9   c                    s   g | ]
}t  | r|qS r   )fnmatchr&   r'   r6   r   r   r)   i       z*get_matched_categories.<locals>.<listcomp>r>   c                    s.   g | ]}t  | d  rd| d fqS )r   r0   r>   )rL   joinrM   )rK   r   r   r)   n   s   . zNo matching wordlist '{}'. {}zDid you mean {}?zNo close matches found.)	doaliasendswithALL_CATEGORIESrD   rE   close_matches
ValueErrorformat_or_fmt)r7   r	   kwmatchesr   )r7   rK   r   r5   a   s    
r5   ?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 )r0   r>   rD   )r&   catr6   r   r   r)   }   s   $ z!close_matches.<locals>.<listcomp>c                 S   s   g | ]
}| d dd qS )r0   r>   rZ   )r&   cr   r   r   r)   ~   rN   r0   r>   r9   )cutoffc                 S      g | ]}t |r|qS r   rI   rM   r   r   r   r)          c                 3   s    | ]	}d   |V  qdS {}/{}NrU   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)      rN   c                 S   r_   r   r`   rM   r   r   r   r)      ra   c                 3   s    | ]	}d  | V  qdS rb   rd   re   rl   r   r   r<      r=   c                    s   g | ]}d  | qS rc   rd   re   rl   r   r   r)      ra   c                 S   s&   g | ]}t |D ]}d ||qqS rn   )find_parts_of_speechrU   )r&   r[   posr   r   r   r)      s    
)	rP   rR   rD   WORD_CLASSES_get_matchesri   listrE   _ordered_unique)r7   r^   rX   all_sub_categories_msr   )r7   rg   rm   r   rS   y   s,   ""	rS   c                    s&   t j |fi | fdd|D  S )Nc                    s&   g | ]}|  st| r|qS r   )
startswithrL   re   patternr   r   r)         & z _get_matches.<locals>.<listcomp>)difflibget_close_matches)ry   	availablerW   r   rx   r   rr      s   rr   c                 C   s   d dd | D S )Nz or c                 s   s    | ]}d  |V  qdS )z'{}'Nrd   rM   r   r   r   r<      s    z_or_fmt.<locals>.<genexpr>)rO   r-   r   r   r   rV      s   rV   c                 C   s$   g }| D ]}||vr| | q|S r   append)xsuniquer(   r   r   r   rt      s   
rt   c                 C   s8   i }| D ]}||}||vrg ||< ||  | q|S r   r~   )itemsfuncgroupsr(   rk   r   r   r   _groupby   s   r   c                    s:   |  d}t D ]\  fdd|D }q	d|S )z6Replace aliases in string.

    Examples:
    >>>
    r0   c                    s   g | ]
}| kr
n|qS r   r   r&   r(   rk   r   r   r   r)      rN   zdoalias.<locals>.<listcomp>)rD   ALIASESr   rO   )r2   rK   r   r   r   rP      s   

rP   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relpathrO   	WORD_PATHisfileOSError)r7   r?   r   r   r   r   rI      s   rI   c                    s    fddt |D S )z$Prefix all items with a path prefix.c                    s&   g | ]}  d  d |d  qS r0   )rstriplstripr   prer   r   r)      rz   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)rk   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
isinstancers   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   rW   r   r   r)          z!sample_unique.<locals>.<listcomp>)rangesetaddlen)	r   r
   r   r   r	   rW   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   rD   )r&   ssir   r   r   r)      s   2 zas_multiple.<locals>.<listcomp>)r   rs   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&   rk   r   r6   r   r   	<setcomp>   rN   z'find_parts_of_speech.<locals>.<setcomp>)ri   r   r6   r   r6   r   ro      r   ro    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   splitextrM   dr   r   r)     s    z$getallcategories.<locals>.<listcomp>z**/*.txtT)	recursivec                 S   s   g | ]	}| tjd qS r   )replacer   r   r:   r   r   r   r)   
  r   )r   r   rO   r   glob)r   path_to_all_categoriesr   r   r   getallcategories   s
   
r   c                 C   s   i | ]}|t |qS r   )r   rj   r   r   r   
<dictcomp>  s    r   c                 C   s   g | ]}t | qS r   rh   rj   r   r   r   r)     s    r)   __main__r   )rY   )F)r   )2__doc__r   r   rL   rF   randomr{   rq   r   rO   dirname__file__r   r   r   r   rE   Randomr   r   r"   r/   r%   r1   	lru_cacher3   r5   rS   rr   rV   rt   r   rP   rI   r   r   r   r,   ro   r   ri   rR   
ADJECTIVESNOUNSVERBSNAMESIPSUM__name__fireFirer   r   r   r   <module>   sr    


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