Ë
    S^(hŒi  ã            	       óP  — d Z ddlZddlZddlZddlmZ ddlmZmZm	Z	 ddl
Z
ddlmZ ddlmZ  ej                  e«      Zdd	d
œZd„ Z G d„ de«      Z	 dZdZededdddddf	Z e
j0                  ddj3                  e«      z  e
j4                  e
j6                  z  e
j8                  z  «      Z e
j0                  d«      Z e
j0                  ee
j4                  e
j6                  z  e
j8                  z  «      Z e
j0                  d«      Z d"d„Z!d#d„Z" G d„ d«      Z#d„ Z$d „ Z%d$d!„Z&dgZ'y)%z!Tokenization classes for BERTweeté    N)Úcopyfile)ÚListÚOptionalÚTupleé   )ÚPreTrainedTokenizer)Úloggingz	vocab.txtz	bpe.codes)Ú
vocab_fileÚmerges_filec                 óx   — t        «       }| d   }| dd D ]  }|j                  ||f«       |}Œ t        |«      }|S )z…
    Return set of symbol pairs in a word.

    Word is represented as tuple of symbols (symbols being variable-length strings).
    r   é   N)ÚsetÚadd)ÚwordÚpairsÚ	prev_charÚchars       úp/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/models/bertweet/tokenization_bertweet.pyÚ	get_pairsr   &   sO   € ô ‹E€EØ�Q‘€IØ�Q�R�ò ˆØ�	‰	�9˜dÐ#Ô$Ø‰	ðô �‹J€EØ€Ló    c            
       ó8  ‡ — e Zd ZdZeZ	 	 	 	 	 	 	 	 dˆ fd„	Z	 ddee   de	ee      dee   fd„Z
	 ddee   de	ee      dedee   fˆ fd„Z	 ddee   de	ee      dee   fd	„Zed
„ «       Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zddede	e   dee   fd„Zd„ Zˆ xZS )ÚBertweetTokenizeraÐ	  
    Constructs a BERTweet tokenizer, using Byte-Pair-Encoding.

    This tokenizer inherits from [`PreTrainedTokenizer`] which contains most of the main methods. Users should refer to
    this superclass for more information regarding those methods.

    Args:
        vocab_file (`str`):
            Path to the vocabulary file.
        merges_file (`str`):
            Path to the merges file.
        normalization (`bool`, *optional*, defaults to `False`):
            Whether or not to apply a normalization preprocess.
        bos_token (`str`, *optional*, defaults to `"<s>"`):
            The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.

            <Tip>

            When building a sequence using special tokens, this is not the token that is used for the beginning of
            sequence. The token used is the `cls_token`.

            </Tip>

        eos_token (`str`, *optional*, defaults to `"</s>"`):
            The end of sequence token.

            <Tip>

            When building a sequence using special tokens, this is not the token that is used for the end of sequence.
            The token used is the `sep_token`.

            </Tip>

        sep_token (`str`, *optional*, defaults to `"</s>"`):
            The separator token, which is used when building a sequence from multiple sequences, e.g. two sequences for
            sequence classification or for a text and a question for question answering. It is also used as the last
            token of a sequence built with special tokens.
        cls_token (`str`, *optional*, defaults to `"<s>"`):
            The classifier token which is used when doing sequence classification (classification of the whole sequence
            instead of per-token classification). It is the first token of the sequence when built with special tokens.
        unk_token (`str`, *optional*, defaults to `"<unk>"`):
            The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
            token instead.
        pad_token (`str`, *optional*, defaults to `"<pad>"`):
            The token used for padding, for example when batching sequences of different lengths.
        mask_token (`str`, *optional*, defaults to `"<mask>"`):
            The token used for masking values. This is the token used when training this model with masked language
            modeling. This is the token which the model will try to predict.
    c                 ó²  •— 	 ddl m} || _        || _        || _        i | _        d| j                  t        |«      <   d| j                  t        |	«      <   d| j                  t        |«      <   d| j                  t        |«      <   | j                  |«       | j                  j                  «       D ��ci c]  \  }}||“Œ
 c}}| _        t        |d¬«      5 }|j                  «       j                  d	«      d d
 }d d d «       D �cg c]  }t!        |j                  «       d d
 «      ‘Œ  }}t#        t%        |t'        t)        |«      «      «      «      | _        i | _        || _        t1        «       | _        dddœ| _        t7        ‰| �p  d|||||||	|
dœ|¤Ž y # t        $ r  t        j                  d«       d | _        Y �Œ®w xY wc c}}w # 1 sw Y   ŒÐxY wc c}w )Nr   )Údemojizezsemoji is not installed, thus not converting emoticons or emojis into text. Install emoji: pip3 install emoji==0.6.0r   é   r   úutf-8©Úencodingú
éÿÿÿÿú'z...)u   â€™u   â€¦)ÚnormalizationÚ	bos_tokenÚ	eos_tokenÚ	sep_tokenÚ	cls_tokenÚ	unk_tokenÚ	pad_tokenÚ
mask_token© )Úemojir   Ú	demojizerÚImportErrorÚloggerÚwarningr
   r   ÚencoderÚstrÚadd_from_fileÚitemsÚdecoderÚopenÚreadÚsplitÚtupleÚdictÚzipÚrangeÚlenÚ	bpe_ranksÚcacher"   ÚTweetTokenizerÚtweetPreprocessorÚspecial_punctsÚsuperÚ__init__)Úselfr
   r   r"   r#   r$   r%   r&   r'   r(   r)   Úkwargsr   ÚkÚvÚmerges_handleÚmergesÚmergeÚ	__class__s                     €r   rC   zBertweetTokenizer.__init__k   sµ  ø€ ð		"Ý&à%ˆDŒNð %ˆŒØ&ˆÔàˆŒØ'(ˆ�‰”S˜“^Ñ$Ø'(ˆ�‰”S˜“^Ñ$Ø'(ˆ�‰”S˜“^Ñ$Ø'(ˆ�‰”S˜“^Ñ$à×Ñ˜:Ô&à)-¯©×);Ñ);Ó)=×>¡  A˜˜1™Ó>ˆŒä�+¨Ô0ð 	;°MØ"×'Ñ'Ó)×/Ñ/°Ó5°c°rÐ:ˆF÷	;à9?Ö@°”%˜Ÿ™› c rÐ*Õ+Ð@ˆÐ@Üœc &¬%´°F³Ó*<Ó=Ó>ˆŒØˆŒ
à*ˆÔÜ!/Ó!1ˆÔØ&)°%Ñ8ˆÔä‰Ñð 
	
Ø'ØØØØØØØ!ñ
	
ð ó
	
øô= ò 	"Ü�N‰Nð(ôð "ˆD�Nð	"üó$ ?÷	;ð 	;üâ@s)   ƒF Â3GÃ#GÄ#GÆ%F?Æ>F?ÇGÚtoken_ids_0Útoken_ids_1Úreturnc                 ó˜   — |€| j                   g|z   | j                  gz   S | j                   g}| j                  g}||z   |z   |z   |z   |z   S )a—  
        Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
        adding special tokens. A BERTweet sequence has the following format:

        - single sequence: `<s> X </s>`
        - pair of sequences: `<s> A </s></s> B </s>`

        Args:
            token_ids_0 (`List[int]`):
                List of IDs to which the special tokens will be added.
            token_ids_1 (`List[int]`, *optional*):
                Optional second list of IDs for sequence pairs.

        Returns:
            `List[int]`: List of [input IDs](../glossary#input-ids) with the appropriate special tokens.
        )Úcls_token_idÚsep_token_id)rD   rL   rM   ÚclsÚseps        r   Ú build_inputs_with_special_tokensz2BertweetTokenizer.build_inputs_with_special_tokens§   sg   € ð( ÐØ×%Ñ%Ð&¨Ñ4¸×8IÑ8IÐ7JÑJÐJØ× Ñ Ð!ˆØ× Ñ Ð!ˆØ�[Ñ  3Ñ&¨Ñ,¨{Ñ:¸SÑ@Ð@r   Úalready_has_special_tokensc                 ó¶   •— |rt         ‰| �  ||d¬«      S |€dgdgt        |«      z  z   dgz   S dgdgt        |«      z  z   ddgz   dgt        |«      z  z   dgz   S )aÄ  
        Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
        special tokens using the tokenizer `prepare_for_model` method.

        Args:
            token_ids_0 (`List[int]`):
                List of IDs.
            token_ids_1 (`List[int]`, *optional*):
                Optional second list of IDs for sequence pairs.
            already_has_special_tokens (`bool`, *optional*, defaults to `False`):
                Whether or not the token list is already formatted with special tokens for the model.

        Returns:
            `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
        T)rL   rM   rU   r   r   )rB   Úget_special_tokens_maskr<   )rD   rL   rM   rU   rK   s       €r   rW   z)BertweetTokenizer.get_special_tokens_maskÁ   s‹   ø€ ñ& &Ü‘7Ñ2Ø'°[Ð]að 3ó ð ð ÐØ�3˜1˜#¤ KÓ 0Ñ0Ñ1°Q°CÑ7Ð7Øˆs�q�cœC Ó,Ñ,Ñ-°°A°Ñ6¸1¸#ÄÀKÓ@PÑ:PÑQÐUVÐTWÑWÐWr   c                 ó    — | j                   g}| j                  g}|€t        ||z   |z   «      dgz  S t        ||z   |z   |z   |z   |z   «      dgz  S )aÍ  
        Create a mask from the two sequences passed to be used in a sequence-pair classification task. BERTweet does
        not make use of token type ids, therefore a list of zeros is returned.

        Args:
            token_ids_0 (`List[int]`):
                List of IDs.
            token_ids_1 (`List[int]`, *optional*):
                Optional second list of IDs for sequence pairs.

        Returns:
            `List[int]`: List of zeros.
        r   )rQ   rP   r<   )rD   rL   rM   rS   rR   s        r   Ú$create_token_type_ids_from_sequencesz6BertweetTokenizer.create_token_type_ids_from_sequencesÝ   sm   € ð" × Ñ Ð!ˆØ× Ñ Ð!ˆàÐÜ�s˜[Ñ(¨3Ñ.Ó/°1°#Ñ5Ð5Ü�3˜Ñ$ sÑ*¨SÑ0°;Ñ>ÀÑDÓEÈÈÑKÐKr   c                 ó,   — t        | j                  «      S ©N)r<   r0   ©rD   s    r   Ú
vocab_sizezBertweetTokenizer.vocab_sizeõ   s   € ä�4—<‘<Ó Ð r   c                 óB   — t        | j                  fi | j                  ¤ŽS r[   )r9   r0   Úadded_tokens_encoderr\   s    r   Ú	get_vocabzBertweetTokenizer.get_vocabù   s   € Ü�D—L‘LÑ> D×$=Ñ$=Ñ>Ð>r   c                 ó$  ‡ — |‰ j                   v r‰ j                   |   S t        |«      }t        t        |d d «      |d   dz   gz   «      }t        |«      }|s|S 	 t	        |ˆ fd„¬«      }|‰ j
                  vrnÎ|\  }}g }d}|t        |«      k  r�	 |j                  ||«      }	|j                  |||	 «       |	}||   |k(  r6|t        |«      dz
  k  r%||dz      |k(  r|j                  ||z   «       |dz  }n|j                  ||   «       |dz  }|t        |«      k  rŒ�t        |«      }|}t        |«      dk(  rnt        |«      }Œídj                  |«      }|d d	 }|‰ j                   |<   |S # t        $ r |j                  ||d  «       Y Œnw xY w)
Nr    z</w>c                 óN   •— ‰j                   j                  | t        d«      «      S )NÚinf)r=   ÚgetÚfloat)ÚpairrD   s    €r   ú<lambda>z'BertweetTokenizer.bpe.<locals>.<lambda>  s   ø€ °·±×1CÑ1CÀDÌ%ÐPUË,Ó1W€ r   )Úkeyr   r   r   ú@@ éüÿÿÿ)r>   r8   Úlistr   Úminr=   r<   ÚindexÚextendÚ
ValueErrorÚappendÚjoin)
rD   Útokenr   r   ÚbigramÚfirstÚsecondÚnew_wordÚiÚjs
   `         r   ÚbpezBertweetTokenizer.bpeü   s±  ø€ Ø�D—J‘JÑØ—:‘:˜eÑ$Ð$Ü�U‹|ˆÜ”T˜$˜s ˜)“_¨¨R©°6Ñ(9Ð':Ñ:Ó;ˆÜ˜$“ˆáØˆLàÜ˜Ó$WÔXˆFØ˜TŸ^™^Ñ+ØØ"‰MˆE�6ØˆHØˆAØ”c˜$“i’-ðØŸ
™
 5¨!Ó,�Að
 —O‘O D¨¨1 IÔ.Ø�Aà˜‘7˜eÒ#¨¬C°«I¸©MÒ(9¸dÀ1ÀqÁ5¹kÈVÒ>SØ—O‘O E¨F¡NÔ3Ø˜‘F‘Aà—O‘O D¨¡GÔ,Ø˜‘F�Að ”c˜$“i“-ô  ˜X“ˆHØˆDÜ�4‹y˜AŠ~Øä! $›�ð9 ð: �z‰z˜$ÓˆØ�C�RˆyˆØ ˆ�
‰
�5ÑØˆøô- "ò Ø—O‘O D¨¨ HÔ-Ùðús   ÂE/ Å/FÆFc                 óî   — | j                   r| j                  |«      }g }t        j                  d|«      }|D ]:  }|j	                  t        | j                  |«      j                  d«      «      «       Œ< |S )zTokenize a string.z\S+\n?ú )r"   ÚnormalizeTweetÚreÚfindallrn   rk   ry   r7   )rD   ÚtextÚsplit_tokensÚwordsrr   s        r   Ú	_tokenizezBertweetTokenizer._tokenize(  sm   € à×ÒØ×&Ñ& tÓ,ˆDàˆÜ—
‘
˜9 dÓ+ˆØò 	BˆEØ×Ñ¤ T§X¡X¨e£_×%:Ñ%:¸3Ó%?Ó @ÕAð	BàÐr   c                 ó(  — | j                   D ]!  }|j                  || j                   |   «      }Œ# | j                  j                  |«      }dj	                  |D �cg c]  }| j                  |«      ‘Œ c}«      }|j                  dd«      j                  dd«      j                  dd«      j                  dd«      j                  d	d
«      }|j                  dd«      j                  dd«      j                  dd«      j                  dd«      j                  dd«      j                  dd«      }|j                  dd«      j                  dd«      j                  dd«      j                  dd«      }dj	                  |j                  «       «      S c c}w )z'
        Normalize a raw Tweet
        r{   zcannot zcan not zn't z n't zn 't zca n'tzcan'tzai n'tzain'tz'm z 'm z're z 're z's z 's z'll z 'll z'd z 'd z've z 've z p . m .z  p.m.z p . m z p.m z a . m .z a.m.z a . m z a.m )rA   Úreplacer@   Útokenizerq   ÚnormalizeTokenr7   )rD   ÚtweetÚpunctÚtokensrr   Ú	normTweets         r   r|   z BertweetTokenizer.normalizeTweet3  se  € ð ×(Ñ(ò 	EˆEØ—M‘M %¨×)<Ñ)<¸UÑ)CÓD‰Eð	Eð ×'Ñ'×0Ñ0°Ó7ˆØ—H‘HÀfÖM¸U˜d×1Ñ1°%Õ8ÒMÓNˆ	ð ×Ñ˜i¨Ó4ß‰W�V˜WÓ%ß‰W�W˜gÓ&ß‰W�X˜wÓ'ß‰W�X˜wÓ'ð 	ð ×Ñ˜e VÓ,ß‰W�V˜WÓ%ß‰W�U˜FÓ#ß‰W�V˜WÓ%ß‰W�U˜FÓ#ß‰W�V˜WÓ%ð 	ð ×Ñ˜j¨(Ó3ß‰W�Y Ó(ß‰W�Z Ó)ß‰W�Y Ó(ð	 	ð �x‰x˜	Ÿ™Ó)Ó*Ð*ùò1 Ns   ÁFc                 ó$  — |j                  «       }|j                  d«      ry|j                  d«      s|j                  d«      ryt        |«      dk(  r<|| j                  v r| j                  |   S | j                  �| j	                  |«      S |S |S )z-
        Normalize tokens in a Tweet
        ú@z@USERÚhttpÚwwwÚHTTPURLr   )ÚlowerÚ
startswithr<   rA   r,   )rD   rr   Úlowercased_tokens      r   r†   z BertweetTokenizer.normalizeTokenU  sŽ   € ð !Ÿ;™;›=ÐØ×Ñ˜CÔ ØØ×(Ñ(¨Ô0Ð4D×4OÑ4OÐPUÔ4VØÜ�‹Z˜1Š_Ø˜×+Ñ+Ñ+Ø×*Ñ*¨5Ñ1Ð1Ø�~‰~Ð)Ø—~‘~ eÓ,Ð,à�àˆLr   c                 ó€   — | j                   j                  || j                   j                  | j                  «      «      S )z0Converts a token (str) in an id using the vocab.)r0   rd   r'   )rD   rr   s     r   Ú_convert_token_to_idz&BertweetTokenizer._convert_token_to_idh  s,   € à�|‰|×Ñ  t§|¡|×'7Ñ'7¸¿¹Ó'GÓHÐHr   c                 óN   — | j                   j                  || j                  «      S )z=Converts an index (integer) in a token (str) using the vocab.)r4   rd   r'   )rD   rm   s     r   Ú_convert_id_to_tokenz&BertweetTokenizer._convert_id_to_tokenl  s   € à�|‰|×Ñ  t§~¡~Ó6Ð6r   c                 ód   — dj                  |«      j                  dd«      j                  «       }|S )z:Converts a sequence of tokens (string) in a single string.r{   ri   Ú )rq   r„   Ústrip)rD   r‰   Ú
out_strings      r   Úconvert_tokens_to_stringz*BertweetTokenizer.convert_tokens_to_stringp  s,   € à—X‘X˜fÓ%×-Ñ-¨e°RÓ8×>Ñ>Ó@ˆ
ØÐr   Úsave_directoryÚfilename_prefixc                 óú  — t         j                  j                  |«      st        j	                  d|› d�«       y t         j                  j                  ||r|dz   ndt        d   z   «      }t         j                  j                  ||r|dz   ndt        d   z   «      }t         j                  j                  | j                  «      t         j                  j                  |«      k7  r@t         j                  j                  | j                  «      rt        | j                  |«       nit         j                  j                  | j                  «      s@t        |d«      5 }| j                  j                  «       }|j                  |«       d d d «       t         j                  j                  | j                  «      t         j                  j                  |«      k7  rt        | j                  |«       ||fS # 1 sw Y   ŒlxY w)NzVocabulary path (z) should be a directoryú-r˜   r
   r   Úwb)ÚosÚpathÚisdirr.   Úerrorrq   ÚVOCAB_FILES_NAMESÚabspathr
   Úisfiler   r5   Úsp_modelÚserialized_model_protoÚwriter   )rD   rœ   r�   Úout_vocab_fileÚout_merge_fileÚfiÚcontent_spiece_models          r   Úsave_vocabularyz!BertweetTokenizer.save_vocabularyu  sr  € Ü�w‰w�}‰}˜^Ô,Ü�L‰LÐ,¨^Ð,<Ð<SÐTÔUØÜŸ™Ÿ™Ø±o˜_¨sÒ2È2ÔQbÐcoÑQpÑpó
ˆô Ÿ™Ÿ™Ø±o˜_¨sÒ2È2ÔQbÐcpÑQqÑqó
ˆô �7‰7�?‰?˜4Ÿ?™?Ó+¬r¯w©w¯©¸~Ó/NÒNÔSU×SZÑSZ×SaÑSaÐbf×bqÑbqÔSrÜ�T—_‘_ nÕ5Ü—‘—‘ §¡Ô0Ü�n dÓ+ð /¨rØ'+§}¡}×'KÑ'KÓ'MÐ$Ø—‘Ð-Ô.÷/ô �7‰7�?‰?˜4×+Ñ+Ó,´·±·±ÀÓ0OÒOÜ�T×%Ñ% ~Ô6à˜~Ð-Ð-÷/ð /ús   Å,G1Ç1G:c                 óÂ  — t        |t        «      r*	 t        |dd¬«      5 }| j                  |«       ddd«       y|j                  «       }|D ]Z  }|j                  «       }|j                  d«      }|dk(  rt        d	«      ‚|d| }t        | j                  «      | j                  |<   Œ\ y# 1 sw Y   yxY w# t        $ r}|‚d}~wt
        $ r t        d|› d�«      ‚w xY w)
zi
        Loads a pre-existing dictionary from a text file and adds its symbols to this instance.
        Úrr   r   NzIncorrect encoding detected in z, please rebuild the datasetr{   r    z5Incorrect dictionary format, expected '<token> <cnt>')Ú
isinstancer1   r5   r2   ÚFileNotFoundErrorÚUnicodeErrorÚ	ExceptionÚ	readlinesr™   Úrfindro   r<   r0   )	rD   ÚfÚfdÚfnfeÚlinesÚlineTmpÚlineÚidxr   s	            r   r2   zBertweetTokenizer.add_from_file’  sç   € ô �aœÔðcÜ˜!˜S¨7Ô3ð +°rØ×&Ñ& rÔ*÷+ð à—‘“ˆØò 	3ˆGØ—=‘=“?ˆDØ—*‘*˜S“/ˆCØ�bŠyÜ Ð!XÓYÐYØ˜˜�:ˆDÜ!$ T§\¡\Ó!2ˆD�L‰L˜Òñ	3÷+ð ûô	 %ò Ø�
ûÜò cÜÐ"AÀ!ÀÐD`Ð aÓbÐbðcús3   ’B7  B+²B7 Â+B4Â0B7 Â4B7 Â7	CÃ CÃC)Fú<s>ú</s>rÀ   r¿   z<unk>z<pad>z<mask>r[   )NF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r¥   Úvocab_files_namesrC   r   Úintr   rT   ÚboolrW   rY   Úpropertyr]   r`   ry   r‚   r|   r†   r”   r–   r›   r1   r   r¯   r2   Ú__classcell__)rK   s   @r   r   r   6   sN  ø„ ñ0ðd *Ðð ØØØØØØØõ:
ðz JNñAØ ™9ðAØ3;¸DÀ¹IÑ3FðAà	ˆc‰óAð6 sxñXØ ™9ðXØ3;¸DÀ¹IÑ3FðXØkoðXà	ˆc‰õXð: JNñLØ ™9ðLØ3;¸DÀ¹IÑ3FðLà	ˆc‰óLð0 ñ!ó ð!ò?ò*òX	ò +òDò&Iò7òñ
.¨cð .ÀHÈSÁMð .Ð]bÐcfÑ]gó .ö:3r   r   ac  
    (?:
      [<>]?
      [:;=8]                     # eyes
      [\-o\*\']?                 # optional nose
      [\)\]\(\[dDpP/\:\}\{@\|\\] # mouth
      |
      [\)\]\(\[dDpP/\:\}\{@\|\\] # mouth
      [\-o\*\']?                 # optional nose
      [:;=8]                     # eyes
      [<>]?
      |
      <3                         # heart
    )u  			# Capture 1: entire matched URL
  (?:
  https?:				# URL protocol and colon
    (?:
      /{1,3}				# 1-3 slashes
      |					#   or
      [a-z0-9%]				# Single letter or digit or '%'
                                       # (Trying not to match e.g. "URI::Escape")
    )
    |					#   or
                                       # looks like domain name followed by a slash:
    [a-z0-9.\-]+[.]
    (?:[a-z]{2,13})
    /
  )
  (?:					# One or more:
    [^\s()<>{}\[\]]+			# Run of non-space, non-()<>{}[]
    |					#   or
    \([^\s()]*?\([^\s()]+\)[^\s()]*?\) # balanced parens, one level deep: (...(...)...)
    |
    \([^\s]+?\)				# balanced parens, non-recursive: (...)
  )+
  (?:					# End with:
    \([^\s()]*?\([^\s()]+\)[^\s()]*?\) # balanced parens, one level deep: (...(...)...)
    |
    \([^\s]+?\)				# balanced parens, non-recursive: (...)
    |					#   or
    [^\s`!()\[\]{};:'".,<>?Â«Â»â€œâ€�â€˜â€™]	# not a space or one of these punct chars
  )
  |					# OR, the following to match naked domains:
  (?:
    (?<!@)			        # not preceded by a @, avoid matching foo@_gmail.com_
    [a-z0-9]+
    (?:[.\-][a-z0-9]+)*
    [.]
    (?:[a-z]{2,13})
    \b
    /?
    (?!@)			        # not succeeded by a @,
                            # avoid matching "foo.na" in "foo.na@example.com"
  )
a	  
    (?:
      (?:            # (international)
        \+?[01]
        [ *\-.\)]*
      )?
      (?:            # (area code)
        [\(]?
        \d{3}
        [ *\-.\)]*
      )?
      \d{3}          # exchange
      [ *\-.\)]*
      \d{4}          # base
    )z	<[^>\s]+>z[\-]+>|<[\-]+z(?:@[\w_]+)z(?:\#+[\w_]+[\w\'_\-]*[\w_]+)z#[\w.+-]+@[\w-]+\.(?:[\w-]\.?)+[\w-]a…  
    (?:[^\W\d_](?:[^\W\d_]|['\-_])+[^\W\d_]) # Words with apostrophes or dashes.
    |
    (?:[+\-]?\d+[,/.:-]\d+[+\-]?)  # Numbers, including fractions, decimals.
    |
    (?:[\w_]+)                     # Words without apostrophes or dashes.
    |
    (?:\.(?:\s*\.){1,})            # Ellipsis dots.
    |
    (?:\S)                         # Everything else that isn't whitespace.
    z(%s)ú|z([^a-zA-Z0-9])\1{3,}z&(#?(x?))([^&;\s]+);c                 óR   — |€d}t        | t        «      r| j                  ||«      S | S )Nr   )r²   ÚbytesÚdecode)r   r   Úerrorss      r   Ú_str_to_unicoderÏ   \  s-   € ØÐØˆÜ�$œÔØ�{‰{˜8 VÓ,Ð,Ø€Kr   c                 óR   ‡‡— ˆˆfd„}t         j                  |t        | |«      «      S )uØ  
    Remove entities from text by converting them to their corresponding unicode character.

    Args:
        text:
            A unicode string or a byte string encoded in the given *encoding* (which defaults to 'utf-8').
        keep (list):
            List of entity names which should not be replaced. This supports both numeric entities (`&#nnnn;` and
            `&#hhhh;`) and named entities (such as `&nbsp;` or `&gt;`).
        remove_illegal (bool):
            If `True`, entities that can't be converted are removed. Otherwise, entities that can't be converted are
            kept "as is".

    Returns: A unicode string with the entities removed.

    See https://github.com/scrapy/w3lib/blob/master/w3lib/html.py

    Examples:

    ```python
    >>> from nltk.tokenize.casual import _replace_html_entities

    >>> _replace_html_entities(b"Price: &pound;100")
    'Price: \xa3100'

    >>> print(_replace_html_entities(b"Price: &pound;100"))
    Price: Â£100
    ```c                 ó   •— | j                  d«      }| j                  d«      rU	 | j                  d«      rt        |d«      }nt        |d«      }d|cxk  rdk  rn nt        |f«      j                  d«      S n>|‰v r| j                  d	«      S t
        j                  j                  j                  |«      }|�	 t        |«      S ‰rd
S | j                  d	«      S # t        $ r d }Y Œ0w xY w# t        t        f$ r Y Œ7w xY w)Nr   r   r   é   é
   é€   éŸ   Úcp1252r   r˜   )ÚgrouprÆ   rÌ   rÍ   ro   ÚhtmlÚentitiesÚname2codepointrd   ÚchrÚOverflowError)ÚmatchÚentity_bodyÚnumberÚkeepÚremove_illegals      €€r   Ú_convert_entityz/_replace_html_entities.<locals>._convert_entity‚  s÷   ø€ Ø—k‘k !“nˆØ�;‰;�qŒ>ðØ—;‘;˜q”>Ü  ¨bÓ1‘Fä  ¨bÓ1�Fð
 ˜6Ô) TÕ)Ü  & Ó+×2Ñ2°8Ó<Ð<øð ˜dÑ"Ø—{‘{ 1“~Ð%äŸ™×5Ñ5×9Ñ9¸+ÓF�ØÐðÜ˜6“{Ð"ñ $ˆrÐ7¨¯©°Q«Ð7øô ò Ø’ðûô ¤Ð.ò Ùðús$   ¥AC Â:
C+ ÃC(Ã'C(Ã+C=Ã<C=)ÚENT_REÚsubrÏ   )r   rà   rá   r   râ   s    ``  r   Ú_replace_html_entitiesrå   d  s"   ù€ õ<8ô: �:‰:�o¤°t¸XÓ'FÓGÐGr   c                   ó   — e Zd ZdZdd„Zd„ Zy)r?   a·  
    Examples:

    ```python
    >>> # Tokenizer for tweets.
    >>> from nltk.tokenize import TweetTokenizer

    >>> tknzr = TweetTokenizer()
    >>> s0 = "This is a cooool #dummysmiley: :-) :-P <3 and some arrows < > -> <--"
    >>> tknzr.tokenize(s0)
    ['This', 'is', 'a', 'cooool', '#dummysmiley', ':', ':-)', ':-P', '<3', 'and', 'some', 'arrows', '<', '>', '->', '<--']

    >>> # Examples using *strip_handles* and *reduce_len parameters*:
    >>> tknzr = TweetTokenizer(strip_handles=True, reduce_len=True)
    >>> s1 = "@remy: This is waaaaayyyy too much for you!!!!!!"
    >>> tknzr.tokenize(s1)
    [':', 'This', 'is', 'waaayyy', 'too', 'much', 'for', 'you', '!', '!', '!']
    ```c                 ó.   — || _         || _        || _        y r[   ©Úpreserve_caseÚ
reduce_lenÚstrip_handles)rD   ré   rê   rë   s       r   rC   zTweetTokenizer.__init__¹  s   € Ø*ˆÔØ$ˆŒØ*ˆÕr   c                 óX  — t        |«      }| j                  rt        |«      }| j                  rt	        |«      }t
        j                  d|«      }t        j                  |«      }| j                  s4|D �cg c])  }t        j                  |«      r|n|j                  «       ‘Œ+ }}|S c c}w )z»
        Args:
            text: str

        Returns: list(str) A tokenized list of strings; concatenating this list returns the original string if
        `preserve_case=False`
        ú\1\1\1)rå   rë   Úremove_handlesrê   Úreduce_lengtheningÚHANG_RErä   ÚWORD_REr~   ré   ÚEMOTICON_REÚsearchr�   )rD   r   Ú	safe_textr�   Úxs        r   r…   zTweetTokenizer.tokenize¾  s�   € ô & dÓ+ˆà×ÒÜ! $Ó'ˆDà�?Š?Ü% dÓ+ˆDä—K‘K 	¨4Ó0ˆ	ä—‘ 	Ó*ˆà×!Ò!ØHMÖNÀ1œ+×,Ñ,¨QÔ/‘Q°Q·W±W³YÑ>ÐNˆEÐNØˆùò Os   Á5.B'N©TFF)rÁ   rÂ   rÃ   rÄ   rC   r…   r*   r   r   r?   r?   ¥  s   „ ñó&+ó
r   r?   c                 óP   — t        j                  d«      }|j                  d| «      S )za
    Replace repeated character sequences of length 3 or greater with sequences of length 3.
    z	(.)\1{2,}rí   ©ÚregexÚcompilerä   ©r   Úpatterns     r   rï   rï   Ý  s#   € ô �m‰m˜LÓ)€GØ�;‰;�y $Ó'Ð'r   c                 óP   — t        j                  d«      }|j                  d| «      S )z4
    Remove Twitter username handles from text.
    zv(?<![A-Za-z0-9_!@#\$%&*])@(([A-Za-z0-9_]){20}(?!@))|(?<![A-Za-z0-9_!@#\$%&*])@(([A-Za-z0-9_]){1,19})(?![A-Za-z0-9_]*@)r{   rø   rû   s     r   rî   rî   å  s+   € ô �m‰mð 	Bó€Gð �;‰;�s˜DÓ!Ð!r   c                 ó<   — t        |||¬«      j                  | «      S )z:
    Convenience function for wrapping the tokenizer.
    rè   )r?   r…   )r   ré   rê   rë   s       r   Úcasual_tokenizerÿ   õ  s$   € ô ¨À*Ð\iÔj×sÑsØóð r   )NÚstrict)r*   Tr   rö   )(rÄ   rØ   r¡   r}   Úshutilr   Útypingr   r   r   rù   Útokenization_utilsr   Úutilsr	   Ú
get_loggerrÁ   r.   r¥   r   r   Ú	EMOTICONSÚURLSÚREGEXPSrú   rq   ÚVERBOSEÚIÚUNICODErñ   rð   rò   rã   rÏ   rå   r?   rï   rî   rÿ   Ú__all__r*   r   r   ú<module>r     sZ  ðñ  (ã Û 	Û 	Ý ß (Ñ (ã å 5Ý ð 
ˆ×	Ñ	˜HÓ	%€ð ØñÐ òô q3Ð+ô q3ð~ðL	€	ð$)€ð\ 	ð	ð  àààà(à.ð
ðA+€ð` ˆ%�-‰-˜ c§h¡h¨wÓ&7Ñ7¸¿¹ÈÏÉÑ9PÐSX×S`ÑS`Ñ9`Ó
a€ð ˆ%�-‰-Ð/Ó
0€ð ˆe�m‰m˜I u§}¡}°u·w±wÑ'>ÀÇÁÑ'NÓO€ð 
ˆ�‰Ð.Ó	/€óó;H÷B0ñ 0òp(ò"ó ð Ð
�r   