+
    ÖÇÜh‹?  ã                   ó~   € R t ^ RIt^ RIt^ RIHtHtHt ^ RIHt ^ RI	H
t
 ^ RIHt  ! R R]4      t ! R R	]4      tR# )
a	  

Penn Treebank Tokenizer

The Treebank tokenizer uses regular expressions to tokenize text as in Penn Treebank.
This implementation is a port of the tokenizer sed script written by Robert McIntyre
and available at http://www.cis.upenn.edu/~treebank/tokenizer.sed.
N)ÚIteratorÚListÚTuple)Ú
TokenizerI)ÚMacIntyreContractions)Úalign_tokensc            	       ó>  a € ] tR t^t o Rt]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3.t]P                  ! R4      R	3]P                  ! R
4      R3]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3.t]P                  ! R4      R3t	]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R 3.t
]P                  ! R!4      R"3t]P                  ! R#4      R$3]P                  ! R%4      R$3]P                  ! R&4      R'3]P                  ! R(4      R'3.t]! 4       t]! ]! ]P                  ]P"                  4      4      t]! ]! ]P                  ]P$                  4      4      tR/V 3R) lR* lltV 3R+ lR, ltR-tV tR.# )0ÚTreebankWordTokenizeraÅ  
The Treebank tokenizer uses regular expressions to tokenize text as in Penn Treebank.

This tokenizer performs the following steps:

- split standard contractions, e.g. ``don't`` -> ``do n't`` and ``they'll`` -> ``they 'll``
- treat most punctuation characters as separate tokens
- split off commas and single quotes, when followed by whitespace
- separate periods that appear at the end of line

>>> from nltk.tokenize import TreebankWordTokenizer
>>> s = '''Good muffins cost $3.88\nin New York.  Please buy me\ntwo of them.\nThanks.'''
>>> TreebankWordTokenizer().tokenize(s)
['Good', 'muffins', 'cost', '$', '3.88', 'in', 'New', 'York.', 'Please', 'buy', 'me', 'two', 'of', 'them.', 'Thanks', '.']
>>> s = "They'll save and invest more."
>>> TreebankWordTokenizer().tokenize(s)
['They', "'ll", 'save', 'and', 'invest', 'more', '.']
>>> s = "hi, my name can't hello,"
>>> TreebankWordTokenizer().tokenize(s)
['hi', ',', 'my', 'name', 'ca', "n't", 'hello', ',']
z^\"ú``z(``)z \1 z([ \(\[{<])(\"|\'{2})z\1 `` z([:,])([^\d])z \1 \2z([:,])$z\.\.\.z ... z[;@#$%&]z \g<0> z([^\.])(\.)([\]\)}>"\']*)\s*$z\1 \2\3 z[?!]z([^'])' z\1 ' z[\]\[\(\)\{\}\<\>]z\(ú-LRB-z\)ú-RRB-z\[ú-LSB-z\]ú-RSB-z\{ú-LCB-z\}ú-RCB-ú--ú -- ú''z '' Ú"z([^' ])('[sS]|'[mM]|'[dD]|') z\1 \2 z)([^' ])('ll|'LL|'re|'RE|'ve|'VE|n't|N'T) c          	      óB   <€ V ^8„  d   QhRS[ RS[RS[RS[S[ ,          /# )é   ÚtextÚconvert_parenthesesÚ
return_strÚreturn)ÚstrÚboolr   )ÚformatÚ__classdict__s   "€Ú8/usr/lib/python3/dist-packages/nltk/tokenize/treebank.pyÚ__annotate__Ú"TreebankWordTokenizer.__annotate__e   s7   ø€ ÷ Eñ EÙðEÙ.2ðEÙHLðEá	‰c�ñEó    c                óØ  € VRJd   \         P                  ! R\        ^R7       V P                   F  w  rEVP	                  WQ4      pK  	  V P
                   F  w  rEVP	                  WQ4      pK  	  V P                  w  rEVP	                  WQ4      pV'       d'   V P                   F  w  rEVP	                  WQ4      pK  	  V P                  w  rEVP	                  WQ4      pRV,           R,           pV P                   F  w  rEVP	                  WQ4      pK  	  V P                   F  pVP	                  RV4      pK  	  V P                   F  pVP	                  RV4      pK  	  VP                  4       # )aU  Return a tokenized copy of `text`.

>>> from nltk.tokenize import TreebankWordTokenizer
>>> s = '''Good muffins cost $3.88 (roughly 3,36 euros)\nin New York.  Please buy me\ntwo of them.\nThanks.'''
>>> TreebankWordTokenizer().tokenize(s) # doctest: +NORMALIZE_WHITESPACE
['Good', 'muffins', 'cost', '$', '3.88', '(', 'roughly', '3,36',
'euros', ')', 'in', 'New', 'York.', 'Please', 'buy', 'me', 'two',
'of', 'them.', 'Thanks', '.']
>>> TreebankWordTokenizer().tokenize(s, convert_parentheses=True) # doctest: +NORMALIZE_WHITESPACE
['Good', 'muffins', 'cost', '$', '3.88', '-LRB-', 'roughly', '3,36',
'euros', '-RRB-', 'in', 'New', 'York.', 'Please', 'buy', 'me', 'two',
'of', 'them.', 'Thanks', '.']

:param text: A string with a sentence or sentences.
:type text: str
:param convert_parentheses: if True, replace parentheses to PTB symbols,
    e.g. `(` to `-LRB-`. Defaults to False.
:type convert_parentheses: bool, optional
:param return_str: If True, return tokens as space-separated string,
    defaults to False.
:type return_str: bool, optional
:return: List of tokens from `text`.
:rtype: List[str]
FzHParameter 'return_str' has been deprecated and should no longer be used.)ÚcategoryÚ
stacklevelÚ z \1 \2 )ÚwarningsÚwarnÚDeprecationWarningÚSTARTING_QUOTESÚsubÚPUNCTUATIONÚPARENS_BRACKETSÚCONVERT_PARENTHESESÚDOUBLE_DASHESÚENDING_QUOTESÚCONTRACTIONS2ÚCONTRACTIONS3Úsplit)Úselfr   r   r   ÚregexpÚsubstitutions   &&&&  r   ÚtokenizeÚTreebankWordTokenizer.tokenizee   sK  € ð6 ˜UÓ"Ü�MŠMð"ä+Øõ	ð %)×$8Ô$8Ñ ˆFØ—:‘:˜lÓ1ŠDñ %9ð %)×$4Ô$4Ñ ˆFØ—:‘:˜lÓ1ŠDñ %5ð  $×3Ñ3ÑˆØ�z‰z˜,Ó-ˆçØ(,×(@Ô(@Ñ$�Ø—z‘z ,Ó5’ñ )Að  $×1Ñ1ÑˆØ�z‰z˜,Ó-ˆð �T�z˜CÕˆà$(×$6Ô$6Ñ ˆFØ—:‘:˜lÓ1ŠDñ %7ð ×(Ô(ˆFØ—:‘:˜j¨$Ó/ŠDñ )à×(Ô(ˆFØ—:‘:˜j¨$Ó/ŠDñ )ð �z‰z‹|Ðr"   c                óL   <€ V ^8„  d   QhRS[ RS[S[S[S[3,          ,          /# )r   r   r   )r   r   r   Úint)r   r   s   "€r   r    r!   ¬   s(   ø€ ÷ ).ñ ).¡#ð ).©(±5¹¹c¸µ?Õ*Cñ ).r"   c              #  óH  "  € V P                  V4      pRV9   g   RV9   d^   \        P                  ! RV4       Uu. uF  q3P                  4       NK  	  ppV Uu. uF  pVR9   d   VP	                  ^ 4      MTNK  	  ppMTp\        Wa4       Rj  x€L
  R# u upi u upi  L5i)añ  
Returns the spans of the tokens in ``text``.
Uses the post-hoc nltk.tokens.align_tokens to return the offset spans.

    >>> from nltk.tokenize import TreebankWordTokenizer
    >>> s = '''Good muffins cost $3.88\nin New (York).  Please (buy) me\ntwo of them.\n(Thanks).'''
    >>> expected = [(0, 4), (5, 12), (13, 17), (18, 19), (19, 23),
    ... (24, 26), (27, 30), (31, 32), (32, 36), (36, 37), (37, 38),
    ... (40, 46), (47, 48), (48, 51), (51, 52), (53, 55), (56, 59),
    ... (60, 62), (63, 68), (69, 70), (70, 76), (76, 77), (77, 78)]
    >>> list(TreebankWordTokenizer().span_tokenize(s)) == expected
    True
    >>> expected = ['Good', 'muffins', 'cost', '$', '3.88', 'in',
    ... 'New', '(', 'York', ')', '.', 'Please', '(', 'buy', ')',
    ... 'me', 'two', 'of', 'them.', '(', 'Thanks', ')', '.']
    >>> [s[start:end] for start, end in TreebankWordTokenizer().span_tokenize(s)] == expected
    True

:param text: A string with a sentence or sentences.
:type text: str
:yield: Tuple[int, int]
r   r   z
``|'{2}|\"N)r   r
   r   )r7   ÚreÚfinditerÚgroupÚpopr   )r4   r   Ú
raw_tokensÚmÚmatchedÚtokÚtokenss   &&     r   Úspan_tokenizeÚ#TreebankWordTokenizer.span_tokenize¬   s§   é € ð. —]‘] 4Ó(ˆ
ð �4ŒK˜T Tœ\ä*,¯+ª+°mÀTÔ*JÓKÑ*J Q—w‘w–yÑ*JˆGÐKñ
 &óá%�Cð #&Ð):Ô":�—‘˜A”ÀÒCÙ%ð ð ˆFð
  ˆFä Ó-×-Ò-ùò Lùòñ 	.ùs(   ‚9B"»BÁB"Á#BÁ<B"ÂB ÂB"© N)FF)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r<   Úcompiler*   r,   r-   r.   r/   r0   r   Ú_contractionsÚlistÚmapr1   r2   r7   rE   Ú__static_attributes__Ú__classdictcell__)r   s   @r   r	   r	      s  ø‡ € ñð0 
�Š�FÓ	˜UÐ#Ø	�Š�GÓ	˜gÐ&Ø	�ŠÐ,Ó	-¨yÐ9ð€Oð 
�ŠÐ$Ó	% yÐ1Ø	�Š�JÓ	 Ð)Ø	�Š�IÓ	 Ð)Ø	�Š�KÓ	  *Ð-à�JŠJÐ7Ó8Øð	
ð 
�Š�GÓ	˜jÐ)Ø	�Š�KÓ	  (Ð+ð€Kð —z’zÐ"7Ó8¸*ÐE€Oð 
�Š�EÓ	˜GÐ$Ø	�Š�EÓ	˜GÐ$Ø	�Š�EÓ	˜GÐ$Ø	�Š�EÓ	˜GÐ$Ø	�Š�EÓ	˜GÐ$Ø	�Š�EÓ	˜GÐ$ðÐð —Z’Z Ó&¨Ð0€Mð 
�Š�EÓ	˜FÐ#Ø	�Š�DÓ	˜6Ð"Ø	�ŠÐ4Ó	5°yÐAØ	�ŠÐ@Ó	AÀ9ÐMð	€Mñ *Ó+€MÙ™˜RŸZ™Z¨×)DÑ)DÓEÓF€MÙ™˜RŸZ™Z¨×)DÑ)DÓEÓF€M÷Eò E÷N).ö ).r"   r	   c            	       ó>  a€ ] tR t^Øt oRt]! 4       t]P                   U u. uF)  p \        P                  ! V P                  RR4      4      NK+  	  up t]P                   U u. uF)  p \        P                  ! V P                  RR4      4      NK+  	  up t]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3]P                  ! R	4      R3]P                  ! R
4      R3.t]P                  ! R4      R3t]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3.t]P                  ! R4      R3]P                  ! R4      R3]P                  ! R4      R3.t]P                  ! R4      R3]P                  ! R 4      R3]P                  ! R!4      R"3]P                  ! R#4      R3]P                  ! R$4      R3]P                  ! R%4      R&3]P                  ! R'4      R(3.t]P                  ! R)4      R*3]P                  ! R+4      R(3]P                  ! R,4      R3.tR3V3R- lR. lltR3V3R/ lR0 lltR1tVtR2# u up i u up i )4ÚTreebankWordDetokenizeraË
  
The Treebank detokenizer uses the reverse regex operations corresponding to
the Treebank tokenizer's regexes.

Note:

- There're additional assumption mades when undoing the padding of ``[;@#$%&]``
  punctuation symbols that isn't presupposed in the TreebankTokenizer.
- There're additional regexes added in reversing the parentheses tokenization,
   such as the ``r'([\]\)\}\>])\s([:;,.])'``, which removes the additional right
   padding added to the closing parentheses precedding ``[:;,.]``.
- It's not possible to return the original whitespaces as they were because
  there wasn't explicit records of where `'\n'`, `'\t'` or `'\s'` were removed at
  the text.split() operation.

>>> from nltk.tokenize.treebank import TreebankWordTokenizer, TreebankWordDetokenizer
>>> s = '''Good muffins cost $3.88\nin New York.  Please buy me\ntwo of them.\nThanks.'''
>>> d = TreebankWordDetokenizer()
>>> t = TreebankWordTokenizer()
>>> toks = t.tokenize(s)
>>> d.detokenize(toks)
'Good muffins cost $3.88 in New York. Please buy me two of them. Thanks.'

The MXPOST parentheses substitution can be undone using the ``convert_parentheses``
parameter:

>>> s = '''Good muffins cost $3.88\nin New (York).  Please (buy) me\ntwo of them.\n(Thanks).'''
>>> expected_tokens = ['Good', 'muffins', 'cost', '$', '3.88', 'in',
... 'New', '-LRB-', 'York', '-RRB-', '.', 'Please', '-LRB-', 'buy',
... '-RRB-', 'me', 'two', 'of', 'them.', '-LRB-', 'Thanks', '-RRB-', '.']
>>> expected_tokens == t.tokenize(s, convert_parentheses=True)
True
>>> expected_detoken = 'Good muffins cost $3.88 in New (York). Please (buy) me two of them. (Thanks).'
>>> expected_detoken == d.detokenize(t.tokenize(s, convert_parentheses=True), convert_parentheses=True)
True

During tokenization it's safe to add more spaces but during detokenization,
simply undoing the padding doesn't really help.

- During tokenization, left and right pad is added to ``[!?]``, when
  detokenizing, only left shift the ``[!?]`` is needed.
  Thus ``(re.compile(r'\s([?!])'), r'\g<1>')``.

- During tokenization ``[:,]`` are left and right padded but when detokenizing,
  only left shift is necessary and we keep right pad after comma/colon
  if the string after is a non-digit.
  Thus ``(re.compile(r'\s([:,])\s([^\d])'), r'\1 \2')``.

>>> from nltk.tokenize.treebank import TreebankWordDetokenizer
>>> toks = ['hello', ',', 'i', 'ca', "n't", 'feel', 'my', 'feet', '!', 'Help', '!', '!']
>>> twd = TreebankWordDetokenizer()
>>> twd.detokenize(toks)
"hello, i can't feel my feet! Help!!"

>>> toks = ['hello', ',', 'i', "can't", 'feel', ';', 'my', 'feet', '!',
... 'Help', '!', '!', 'He', 'said', ':', 'Help', ',', 'help', '?', '!']
>>> twd.detokenize(toks)
"hello, i can't feel; my feet! Help!! He said: Help, help?!"
z(?#X)z\sz+([^' ])\s('ll|'LL|'re|'RE|'ve|'VE|n't|N'T) z\1\2 z([^' ])\s('[sS]|'[mM]|'[dD]|') z(\S)\s(\'\')ú\1\2z(\'\')\s([.,:)\]>};%])r   r   r   r   r   Ú(r   Ú)r   Ú[r   Ú]r   Ú{r   Ú}z([\[\(\{\<])\sz\g<1>z\s([\]\)\}\>])z([\]\)\}\>])\s([:;,.])z([^'])\s'\sz\1' z\s([?!])z([^\.])\s(\.)([\]\)}>"\']*)\s*$z\1\2\3z([#$])\sz\s([;%])z
\s\.\.\.\sz...z\s([:,])z\1z([ (\[{<])\s``z\1``z(``)\sr
   c                ó<   <€ V ^8„  d   QhRS[ S[,          RS[RS[/# ©r   rD   r   r   ©r   r   r   )r   r   s   "€r   r    Ú$TreebankWordDetokenizer.__annotate__[  s'   ø€ ÷ 3ñ 3™t¡C�yð 3¹tð 3ÑPSñ 3r"   c                óâ  € RP                  V4      pRV,           R,           pV P                   F  pVP                  RV4      pK  	  V P                   F  pVP                  RV4      pK  	  V P                   F  w  rEVP                  WS4      pK  	  VP                  4       pV P                  w  rEVP                  WS4      pV'       d'   V P                   F  w  rEVP                  WS4      pK  	  V P                   F  w  rEVP                  WS4      pK  	  V P                   F  w  rEVP                  WS4      pK  	  V P                   F  w  rEVP                  WS4      pK  	  VP                  4       # )a]  
Treebank detokenizer, created by undoing the regexes from
the TreebankWordTokenizer.tokenize.

:param tokens: A list of strings, i.e. tokenized text.
:type tokens: List[str]
:param convert_parentheses: if True, replace PTB symbols with parentheses,
    e.g. `-LRB-` to `(`. Defaults to False.
:type convert_parentheses: bool, optional
:return: str
r&   rU   )Újoinr2   r+   r1   r0   Ústripr/   r.   r-   r,   r*   )r4   rD   r   r   r5   r6   s   &&&   r   r7   Ú TreebankWordDetokenizer.tokenize[  sN  € ð �x‰x˜Óˆð �T�z˜CÕˆð ×(Ô(ˆFØ—:‘:˜g tÓ,ŠDñ )à×(Ô(ˆFØ—:‘:˜g tÓ,ŠDñ )ð %)×$6Ô$6Ñ ˆFØ—:‘:˜lÓ1ŠDñ %7ð �z‰z‹|ˆð  $×1Ñ1ÑˆØ�z‰z˜,Ó-ˆçØ(,×(@Ô(@Ñ$�Ø—z‘z ,Ó5’ñ )Að %)×$8Ô$8Ñ ˆFØ—:‘:˜lÓ1ŠDñ %9ð %)×$4Ô$4Ñ ˆFØ—:‘:˜lÓ1ŠDñ %5ð %)×$8Ô$8Ñ ˆFØ—:‘:˜lÓ1ŠDñ %9ð �z‰z‹|Ðr"   c                ó<   <€ V ^8„  d   QhRS[ S[,          RS[RS[/# r]   r^   )r   r   s   "€r   r    r_   �  s'   ø€ ÷ :ñ :¡¡c¥ð :Áð :ÑRUñ :r"   c                ó$   € V P                  W4      # )z&Duck-typing the abstract *tokenize()*.)r7   )r4   rD   r   s   &&&r   Ú
detokenizeÚ"TreebankWordDetokenizer.detokenize�  s   € à�}‰}˜VÓ9Ð9r"   rG   N)F)rH   rI   rJ   rK   rL   r   rN   r1   r<   rM   Úreplacer2   r0   r/   r.   r-   r,   r*   r7   rf   rQ   rR   )Úpatternr   s   0@r   rT   rT   Ø   s›  ø‡ € ñ:ñx *Ó+€Mð %×2Ò2óá2ˆGô 	�
Š
�7—?‘? 7¨EÓ2Ö3Ù2ñ€Mð %×2Ò2óá2ˆGô 	�
Š
�7—?‘? 7¨EÓ2Ö3Ù2ñ€Mð 
�ŠÐBÓ	CÀXÐNØ	�ŠÐ6Ó	7¸ÐBØ	�Š�OÓ	$ gÐ.à�JŠJÐ0Ó1Øð	
ð 
�Š�EÓ	˜CÐ ð	€Mð —Z’Z Ó(¨%Ð0€Mð 
�Š�GÓ	˜cÐ"Ø	�Š�GÓ	˜cÐ"Ø	�Š�GÓ	˜cÐ"Ø	�Š�GÓ	˜cÐ"Ø	�Š�GÓ	˜cÐ"Ø	�Š�GÓ	˜cÐ"ðÐð 
�ŠÐ%Ó	&¨Ð1Ø	�ŠÐ%Ó	&¨Ð1Ø	�ŠÐ-Ó	.°Ð8ð€Oð 
�Š�NÓ	# WÐ-Ø	�Š�KÓ	  (Ð+à	�ŠÐ6Ó	7¸ÐCð
 
�Š�KÓ	  (Ð+Ø	�Š�KÓ	  (Ð+à	�Š�MÓ	" FÐ+ð �JŠJ�{Ó#Øð	
ð€Kð, 
�ŠÐ%Ó	&¨Ð0Ø	�Š�IÓ	 Ð&Ø	�Š�EÓ	˜DÐ!ð€O÷3ò 3÷j:÷ :ð :ùòuùòs   ¡/JÁ!/JrT   )rL   r<   r'   Útypingr   r   r   Únltk.tokenize.apir   Únltk.tokenize.destructiver   Únltk.tokenize.utilr   r	   rT   rG   r"   r   Ú<module>rn      s>   ðñó 
Û ß (Ñ (å (Ý ;Ý +ôx.˜Jô x.ôvz:˜jö z:r"   