
    Q/Ph.#                        d Z ddlmZ ddlZddlZedk    r ej         ej        d                     ddlZddl	Z	ddl
Z
ddlZddlZddlmZ ddlmZ  G d	 d
e          Z G d de
j                  Zd Zd Zd ZdS )z5Command-line tool interface to generate word clouds.
    )absolute_importN__main__z
        To execute the CLI, instead consider running:

          wordcloud_cli --help

        or

          python -m wordcloud --help
        )Image   )__version__c                   &    e Zd ZdZddZd Zd ZdS )	FileTypea  Factory for creating file object types.

    Port from argparse so we can support unicode file reading in Python2

    Instances of FileType are typically passed as type= arguments to the
    ArgumentParser add_argument() method.

    Keyword Arguments:
        - mode -- A string indicating how the file is to be opened. Accepts the
            same values as the builtin open() function.
        - bufsize -- The file's desired buffer size. Accepts the same values as
            the builtin open() function.

    rc                 "    || _         || _        d S N)_mode_bufsize)selfmodebufsizes      W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/wordcloud/wordcloud_cli.py__init__zFileType.__init__/   s    
    c                    |dk    r]d| j         v rt          j        S d| j         v r&d| j         v rt          j        j        nt          j        S d| j         z  }t          |          	 d| j         v rd nd}t          j        || j         | j        |          S # t          $ r }d}t          j        |||fz            d }~ww xY w)	N-r
   wbzargument "-" with mode %rzUTF-8)encodingzcan't open '%s': %s)r   sysstdinstdoutbuffer
ValueErrorioopenr   IOErrorargparseArgumentTypeError)r   stringmsgr   emessages         r   __call__zFileType.__call__3   s    S==dj  y 
"",/4:,=,=sz((3:M1DJ> oo%	D"dj00ttgH764:t}xPPPP 	D 	D 	D+G,W{-BCCC	Ds   %.B 
B>B99B>c                     | j         | j        f}d                    d |D                       }t          |           j        d|dS )Nz, c              3   @   K   | ]}|d k    t          |          V  dS )r   N)repr).0args     r   	<genexpr>z$FileType.__repr__.<locals>.<genexpr>H   s,      DD3#))T#YY))))DDr   ())r   r   jointype__name__)r   argsargs_strs      r   __repr__zFileType.__repr__F   sN    z4=(99DD$DDDDD::...99r   N)r
   r   )r4   
__module____qualname____doc__r   r)   r7    r   r   r	   r	      sS                D D D&: : : : :r   r	   c                   &     e Zd Z fdZddZ xZS )RegExpActionc                 L     t          t          |           j        ||fi | d S r   )superr=   r   )r   option_stringsdestkwargs	__class__s       r   r   zRegExpAction.__init__M   s0    *lD!!*>4JJ6JJJJJr   Nc                     	 t          j        |           n<# t           j        $ r*}t          j        | dt          |          z             d }~ww xY wt          || j        |           d S )NzInvalid regular expression: )recompileerrorr#   ArgumentErrorstrsetattrrA   )r   parser	namespacevaluesoption_stringr'   s         r   r)   zRegExpAction.__call__P   s}    	XJvx 	X 	X 	X(/MPSTUPVPV/VWWW	X	49f-----s    A%AAr   )r4   r8   r9   r   r)   __classcell__)rC   s   @r   r=   r=   L   sQ        K K K K K. . . . . . . .r   r=   c                     t          j        di | }|                    |           |                                }|5  |                    |dd           d d d            d S # 1 swxY w Y   d S )NpngT)formatoptimizer;   )wc	WordCloudgenerateto_imagesave)r5   text	imagefile	wordcloudimages        r   mainr]   X   s    $$t$$It  E	 ; ;

9UT
:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;s   A##A'*A'c                     d} t          j        |           }|                    ddt                      dd           |                    dd	d t          d
           |                    ddt                      d           |                    ddt          d          dd           |                    dddd           |                    ddt          j        d          d           |                    ddt          j        d          d           |                    dddt
          dd !           |                    d"d#d$t          d%d&!           |                    d't
          dd(d)*           |                    d+t          d,dd-*           |                    d.t          d/dd0*           |                    d1t          d2d3d4*           |                    d5d#d67           |                    d8d#d$t          d9d:!           |                    d;d<d=d>?           |                    d@dAdBdC?           |                    dDt          ddEdEdFG           |                    dHt
          dIdJdK*           |                    dLt
          dMdNdO*           |                    dPt          dQdRdS*           |                    dTt          dUdVdW*           |                    dXt          d2dYdZ*           |                    d[t          d\d]d^*           |                    d_t          d d]d`*           |                    dat          dMdbdc*           |                    ddt          d dedf*           |                    dgd<dhdi?           |                    djdAdkdl?           |                    dmdndo                    t          p          q           |S )rNz5A simple command line interface for wordcloud module.)descriptionz--textfiler   z>specify file of words to build the word cloud (default: stdin))metavarr3   defaulthelpz--regexpregexpz@override the regular expression defining what constitutes a word)ra   rb   actionrc   z--stopwordszdspecify file of stopwords (containing one word per line) to remove from the given text after parsing)ra   r3   rc   z--imagefilewbzCfile the completed PNG image should be written to (default: stdout)z
--fontfilepath	font_pathz:path to font file you wish to use (default: DroidSansMono))ra   rA   rc   z--maskrbzmask to use for the image formz--colormaskz$color mask to use for image coloringz--contour_widthwidthr   contour_widthz1if greater than 0, draw mask contour (default: 0))ra   rb   r3   rA   rc   z--contour_colorcolorblackcontour_colorzVuse given color as mask contour color - accepts any value from PIL.ImageColor.getcolorz--relative_scalingrsz& scaling of words by frequency (0 - 1))r3   rb   ra   rc   z--margin   zspacing to leave around wordsz--widthi  zdefine output image widthz--height   heightzdefine output image heightz--colorzZuse given color as coloring for the image - accepts any value from PIL.ImageColor.getcolor)ra   rc   z--backgroundbackground_colorzbuse given color as background color for the image - accepts any value from PIL.ImageColor.getcolorz--no_collocationsstore_falsecollocationszSdo not add collocations (bigrams) to word cloud (default: add unigrams and bigrams))re   rA   rc   z--include_numbers
store_trueinclude_numberszinclude numbers in wordcloud?z--min_word_lengthmin_word_lengthz+only include words with more than X letters)r3   rb   ra   rA   rc   z--prefer_horizontalg?ratioz?ratio of times to try horizontal fitting as opposed to verticalz--scaler   scalez'scaling between computation and drawingz
--colormapviridismapzmatplotlib colormap namez--modeRGBr   z*use RGB or RGBA for transparent backgroundz--max_wordsNzmaximum number of wordsz--min_font_size   sizezsmallest font size to usez--max_font_sizez&maximum font size for the largest wordz--font_stepstepzstep size for the fontz--random_stateseedzrandom seedz--no_normalize_pluralsnormalize_pluralsz)whether to remove trailing 's' from wordsz--repeatrepeatz#whether to repeat words and phrasesz	--versionversionz%(prog)s {version})r   )re   r   )
r#   ArgumentParseradd_argumentr	   r=   floatrI   intrR   r   )r_   rK   s     r   make_parserr   a   s   IK$===F
&xzz3M  O O O Hd<O  Q Q Q vHJJ<  = = = vHTNN"  # # #
 f;I  K K K &x'8'>'>-  / / / vH,=d,C,C3  5 5 5 7AE@  B B B 7G#?  @ @ @
 5!C  E E E a=  ? ? ? S9  ; ; ; c;  = = = 7?  @ @ @ s?  @ @ @
 M3  4 4 4 ,	  . . .
 !:  < < < BN  P P P Aw6  8 8 8 )U'  ) ) ) %9  ; ; ; #s&  ( ( ( !V(  * * * $5  7 7 7 !V%  ' ' ' $       :	  < < <
 2	  4 4 4
 I$++K+@@  B B B Mr   c                    t                      }|                    |           }|j        dk    rd |_        |j        r|j        rt          d          t          |          }|                    d          5 }|                                }d d d            n# 1 swxY w Y   |d         r`|                    d          5 }t          t          d |                                                    |d<   d d d            n# 1 swxY w Y   |d         r>|                    d          }t          j        t          j        |                    |d<   t           j        }|                    d          }|                    d          }|r:t          j        t          j        |                    }	t!          j        |	          }|rt!          j        |          }||d	<   |                    d
          }
|||
fS )NNonez/specify either a color mask or a color functionrY   	stopwordsc                 *    |                                  S r   )strip)ls    r   <lambda>zparse_args.<locals>.<lambda>   s    !'')) r   mask	colormaskrl   
color_funcrZ   )r   
parse_argsrs   r   rl   r   varspopreadsetr|   	readlinesnparrayr   r!   rT   random_color_funcImageColorGeneratorget_single_color_func)	argumentsrK   r5   frY   r   r   r   rl   r\   rZ   s              r   r   r      sW   ]]FY''D&& $~ L$* LJKKK::D	&		 Qvvxx               K MXXk"" 	Ma #C(;(;Q[[]]$K$K L LD	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M 	M F| 2xxx
4 0 011V%J%%IHHWE 3I..//+E22
 5-e44
#D%%Iy  s$   7BBB 4D  DD)r:   
__future__r   r   textwrapr4   exitdedentr    rE   r#   r[   rT   numpyr   PILr    r   objectr	   Actionr=   r]   r   r   r;   r   r   <module>r      sT    & & & & & & 



 zCH_X_		 	 	 	 	 
			 				                     *: *: *: *: *:v *: *: *:Z	. 	. 	. 	. 	.8? 	. 	. 	.; ; ;z z zz#! #! #! #! #!r   