+
    ÖÇÜhÀn  ã                   ó`  € R t ^ RI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IHt ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHtHtHt ]! R. RO4      t ! R R4      t  ! R R4      t! ! R R4      t" ! R R4      t# ! R R]#4      t$R t%]&R8X  d   ]%! 4        . ROt'R# )a  
This module brings together a variety of NLTK functionality for
text analysis, and provides simple, interactive interfaces.
Functionality includes: concordancing, collocation discovery,
regular expression search over tokenized strings, and
distributional similarity.
N)ÚCounterÚdefaultdictÚ
namedtuple)Úreduce)Úlog)ÚBigramCollocationFinder)ÚMLE)Úpadded_everygram_pipeline)ÚBigramAssocMeasuresÚ	f_measure)ÚConditionalFreqDist)ÚFreqDist)Úsent_tokenize)ÚLazyConcatenationÚ
cut_stringÚ	tokenwrapÚConcordanceLinec                   óf   a € ] tR t^'t o Rt]R 4       tRRR 3R ltR tR t	RR lt
RR	 ltR
tV tR# )ÚContextIndexzû
A bidirectional index between words and their 'contexts' in a text.
The context of a word is usually defined to be the words that occur
in a fixed window around the word; but other definitions may also
be used by providing a custom context function.
c                óÀ   € V^ 8w  d   W^,
          ,          P                  4       MRpV\        V 4      ^,
          8w  d   W^,           ,          P                  4       MRpW#3# )z;One left token and one right token, normalized to lowercaseú*START*ú*END*)ÚlowerÚlen)ÚtokensÚiÚleftÚrights   &&  Ú+/usr/lib/python3/dist-packages/nltk/text.pyÚ_default_contextÚContextIndex._default_context/   sM   € ð )*¨Q¬ˆv˜!•e�}×"Ñ"Ô$°IˆØ)*¬c°&«k¸A­oÔ)=�˜1•u•×#Ñ#Ô%À7ˆØˆ}Ðó    Nc                ó   € V # ©N© ©Úxs   &r   Ú<lambda>ÚContextIndex.<lambda>6   s   € ÉQr!   c                óT  a a€ VS n         SS n        V'       d	   VS n        MS P                  S n        V'       d"   S Uu. uF  qS! V4      '       g   K  VNK  	  upo\	        V V3R  l\        S4       4       4      S n        \	        V V3R l\        S4       4       4      S n        R# u upi )c              3   ón   <"  € T F*  w  rSP                  V4      SP                  SV4      3x € K,  	  R # 5ir#   )Ú_keyÚ_context_func©Ú.0r   ÚwÚselfr   s   &  €€r   Ú	<genexpr>Ú(ContextIndex.__init__.<locals>.<genexpr>?   s1   øé € ð %
ÙFW¹d¸aˆT�Y‰Y�q‹\˜4×-Ñ-¨f°aÓ8Õ9ÓFWùó   ƒ25c              3   ón   <"  € T F*  w  rSP                  SV4      SP                  V4      3x € K,  	  R # 5ir#   )r,   r+   r-   s   &  €€r   r1   r2   B   s1   øé € ð %
ÙFW¹d¸aˆT×Ñ ¨Ó*¨D¯I©I°a«LÕ9ÓFWùr3   N)r+   Ú_tokensr,   r   ÚCFDÚ	enumerateÚ_word_to_contextsÚ_context_to_words)r0   r   Úcontext_funcÚfilterÚkeyÚts   ff&&& r   Ú__init__ÚContextIndex.__init__6   s�   ù€ ØˆŒ	ØˆŒßØ!-ˆDÕà!%×!6Ñ!6ˆDÔßÙ!'Ó5¡˜A¨6°!¯9—a�a¡Ñ5ˆFÜ!$õ %
ÜFOÐPVÔFWó%
ó "
ˆÔô "%õ %
ÜFOÐPVÔFWó%
ó "
ˆÖùò	 6s   ¾B%ÁB%c                ó   € V P                   # )zW
:rtype: list(str)
:return: The document that this context index was
    created from.
©r5   ©r0   s   &r   r   ÚContextIndex.tokensF   ó   € ð �|‰|Ðr!   c                óØ   € V P                  V4      p\        V P                  V,          4      p/ pV P                  P                  4        F  w  rE\	        V\        V4      4      W4&   K  	  V# )z€
Return a dictionary mapping from words to 'similarity scores,'
indicating how often these two words occur in the same
context.
)r+   Úsetr8   Úitemsr   )r0   ÚwordÚword_contextsÚscoresr/   Ú
w_contextss   &&    r   Úword_similarity_dictÚ!ContextIndex.word_similarity_dictN   s_   € ð �y‰y˜‹ˆÜ˜D×2Ñ2°4Õ8Ó9ˆàˆØ!×3Ñ3×9Ñ9Ö;‰MˆAÜ! -´°Z³ÓAˆF‹Iñ <ð ˆr!   c                ó€  € \        \        4      pV P                  V P                  V4      ,           Fp  pV P                  V,           FV  pWQ8w  g   K  W5;;,          V P                  V,          V,          V P                  V,          V,          ,          ,          uu&   KX  	  Kr  	  \        W3P                  R R7      RV # )T)r<   ÚreverseN)r   Úintr8   r+   r9   ÚsortedÚget)r0   rH   ÚnrJ   Úcr/   s   &&&   r   Úsimilar_wordsÚContextIndex.similar_words]   s™   € ÜœSÓ!ˆØ×'Ñ'¨¯	©	°$«×8Ð8ˆAØ×+Ñ+¨A×.Ð.�Ø–9Ø—IØ×.Ñ.¨qÕ1°$Õ7¸$×:PÑ:PÐQRÕ:SÐTUÕ:VÕVõ•Ió /ñ 9ô �f§*¡*°dÔ;¸B¸QÐ?Ð?r!   c                ó
  a a€ V Uu. uF  pS P                  V4      NK  	  ppV Uu. uF  p\        S P                  V,          4      NK!  	  pp\        \	        V4      4       Uu. uF  qTV,          '       d   K  W,          NK  	  pp\        \        P                  V4      oV'       d$   V'       d   \        RRP                  V4      4      hS'       g   \        4       # \        VV 3R lV 4       4      pV# u upi u upi u upi )ag  
Find contexts where the specified words can all appear; and
return a frequency distribution mapping each context to the
number of times that context was used.

:param words: The words used to seed the similarity search
:type words: str
:param fail_on_unknown: If true, then raise a value error if
    any of the given words do not occur at all in the index.
z%The following word(s) were not found:Ú c              3   ól   <"  € T F)  pSP                   V,           F  q"S9   g   K  Vx € K  	  K+  	  R # 5ir#   )r8   )r.   r/   rT   Úcommonr0   s   &  €€r   r1   Ú/ContextIndex.common_contexts.<locals>.<genexpr>|   s1   øé € ð Ù �a¨$×*@Ñ*@À×*CÐ*C QÈFÁ{—’Ñ*C‘›5ùs   ƒ4¦4)
r+   rF   r8   Úranger   r   ÚintersectionÚ
ValueErrorÚjoinr   )	r0   ÚwordsÚfail_on_unknownr/   Úcontextsr   ÚemptyÚfdrZ   s	   f&&     @r   Úcommon_contextsÚContextIndex.common_contextsg   sÑ   ù€ ñ (-Ó-¡u !�—‘˜1–¡uˆÐ-Ù<AÓB¹E°q”C˜×.Ñ.¨qÕ1Ö2¹EˆÐBÜ#(¬¨U«Ô#4ÓHÑ#4˜aÀQ¿K¹K”�—�Ñ#4ˆÐHÜœ×(Ñ(¨(Ó3ˆß—_ÜÐDÀcÇhÁhÈuÃoÓVÐVßä“:Ðäõ Ù óó ˆBð ˆIùò .ùÚBùÚHs   ‡C6§%C;Á$D Á9D )r,   r9   r+   r5   r8   ©é   )F)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ústaticmethodr   r>   r   rL   rU   re   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r   r   '   sF   ø‡ € ñð ñó ðð -1¸Á;ô 
ò òô@÷ò r!   r   c                   óX   a € ] tR t^‚t o RtR 3R ltR tR tR tRR lt	RR lt
R	tV tR
# )ÚConcordanceIndexzg
An index that can be used to look up the offset locations at which
a given word occurs in a document.
c                ó   € V # r#   r$   r%   s   &r   r'   ÚConcordanceIndex.<lambda>ˆ   s   € ©Qr!   c                óÚ   € Wn          W n         \        \        4      V n         \        V4       F8  w  r4V P                  V4      pV P                  V,          P                  V4       K:  	  R# )a¡  
Construct a new concordance index.

:param tokens: The document (list of tokens) that this
    concordance index was created from.  This list can be used
    to access the context of a given word occurrence.
:param key: A function that maps each token to a normalized
    version that will be used as a key in the index.  E.g., if
    you use ``key=lambda s:s.lower()``, then the index will be
    case-insensitive.
N)r5   r+   r   ÚlistÚ_offsetsr7   Úappend)r0   r   r<   ÚindexrH   s   &&&  r   r>   ÚConcordanceIndex.__init__ˆ   s\   € ð Œð	 ð Œ	ØDä#¤DÓ)ˆŒØLä$ VÖ,‰KˆEØ—9‘9˜T“?ˆDØ�M‰M˜$Õ×&Ñ& uÖ-ó -r!   c                ó   € V P                   # )z[
:rtype: list(str)
:return: The document that this concordance index was
    created from.
rA   rB   s   &r   r   ÚConcordanceIndex.tokens¢   rD   r!   c                óJ   € V P                  V4      pV P                  V,          # )z¼
:rtype: list(int)
:return: A list of the offset positions at which the given
    word occurs.  If a key function was specified for the
    index, then given word's key will be looked up.
)r+   ry   ©r0   rH   s   &&r   ÚoffsetsÚConcordanceIndex.offsetsª   s    € ð �y‰y˜‹ˆØ�}‰}˜TÕ"Ð"r!   c                ód   € R \        V P                  4      \        V P                  4      3,          # )z+<ConcordanceIndex for %d tokens (%d types)>)r   r5   ry   rB   s   &r   Ú__repr__ÚConcordanceIndex.__repr__´   s-   € Ø<Ü�—‘ÓÜ�—‘Óð@
õ 
ð 	
r!   c           
     óÀ  € \        V\        4      '       d   TpMV.pRP                  V4      p\        R V 4       4      pW%,
          ^,
          ^,          pV^,          p. pV P	                  V^ ,          4      p	\        VR,          4       FL  w  r¡V P	                  V4       Uu0 uF  q»V
,
          ^,
          kK  	  pp\        VP                  V	4      4      p	KN  	  V	'       d÷   V	 Fð  p
RP                  V P                  Wª\        V4      ,            4      pV P                  \        ^ W§,
          4      V
 pV P                  V
\        V4      ,           W§,            p\        RP                  V4      V) 4      P                  V4      p\        RP                  V4      V4      pRP                  VVV.4      p\        VVVV
VVV4      pVP                  V4       Kò  	  V# u upi )zs
Find all concordance lines given the query word.

Provided with a list of words, these will be found as a phrase.
rX   c              3   ób   "  € T F%  p\         P                  ! V4      '       d   K!  ^x € K'  	  R# 5i)é   N)ÚunicodedataÚ	combining)r.   Úchars   & r   r1   Ú4ConcordanceIndex.find_concordance.<locals>.<genexpr>Æ   s   é € ÐU¡z˜t¼×9NÒ9NÈt×9TŸš£zùs   ‚/¥
/:rˆ   NN)Ú
isinstancerx   r_   Úsumr�   r7   rQ   r]   r5   r   Úmaxr   Úrjustr   rz   )r0   rH   ÚwidthÚphraseÚ
phrase_strÚ
phrase_lenÚ
half_widthÚcontextÚconcordance_listr�   r   ÚoffsetÚword_offsetsÚ
query_wordÚleft_contextÚright_contextÚ
left_printÚright_printÚ
line_printÚconcordance_lines   &&&                 r   Úfind_concordanceÚ!ConcordanceIndex.find_concordanceº   s²  € ô �dœD×!Ò!Ø‰Fà�VˆFà—X‘X˜fÓ%ˆ
ÜÑU¡zÓUÓUˆ
ØÕ(¨1Õ,°Õ2ˆ
Ø˜1•*ˆð ÐØ—,‘,˜v a�yÓ)ˆÜ  ¨¥Ö,‰GˆAØ9=¿¹ÀdÔ9KÓLÑ9K¨v Q�J¨ŸN˜NÑ9KˆLÐLÜ˜\×6Ñ6°wÓ?Ó@ŠGñ -÷ Û�Ø ŸX™X d§l¡l°1¼3¸v»;µÐ&GÓH�
à#Ÿ|™|¬C°°1µ;Ó,?À!ÐD�Ø $§¡¨Q´°V³­_¸q½{Ð K�ä'¨¯©°Ó(>ÀÀÓL×RÑRØó�
ô )¨¯©°-Ó)@À*ÓM�à ŸX™X z°:¸{Ð&KÓL�
ä#2Ø ØØ!ØØØØó$Ð ð !×'Ñ'Ð(8Ö9ñ- ð.  Ðùò5 Ms   Â#Gc                ó  € V P                  WR7      pV'       g   \        R4       R# \        V\        V4      4      p\        RV R\        V4       R24       \	        VRV 4       F  w  rV\        VP
                  4       K  	  R# )aa  
Print concordance lines given the query word.
:param word: The target word or phrase (a list of strings)
:type word: str or list
:param lines: The number of lines to display (default=25)
:type lines: int
:param width: The width of each line, in characters (default=80)
:type width: int
:param save: The option to save the concordance.
:type save: bool
)r‘   z
no matcheszDisplaying z of z	 matches:N)r¡   ÚprintÚminr   r7   Úline)r0   rH   r‘   Úlinesr—   r   r    s   &&&&   r   Úprint_concordanceÚ"ConcordanceIndex.print_concordanceê   s}   € ð  ×0Ñ0°Ð0ÓCÐçÜ�,Öä˜œsÐ#3Ó4Ó5ˆEÜ�K ˜w d¬3Ð/?Ó+@Ð*AÀÐKÔLÜ'0Ð1AÀ&À5Ð1IÖ'JÑ#�ÜÐ&×+Ñ+Ö,ó (Kr!   )r+   ry   r5   N)éP   )rª   é   )ri   rj   rk   rl   rm   r>   r   r�   r„   r¡   r¨   ro   rp   rq   s   @r   rt   rt   ‚   s3   ø‡ € ññ
 $/ô .ò4ò#ò
ô. ÷`-ò -r!   rt   c                   ó0   a € ] tR tRt o RtR tR tRtV tR# )ÚTokenSearcheri  aÂ  
A class that makes it easier to use regular expressions to search
over tokenized strings.  The tokenized string is converted to a
string where tokens are marked with angle brackets -- e.g.,
``'<the><window><is><still><open>'``.  The regular expression
passed to the ``findall()`` method is modified to treat angle
brackets as non-capturing parentheses, in addition to matching the
token boundaries; and to have ``'.'`` not match the angle brackets.
c                ó@   € R P                  R V 4       4      V n        R# )Ú c              3   óB   "  € T F  pR V,           R,           x € K  	  R# 5i)Ú<Ú>Nr$   )r.   r/   s   & r   r1   Ú)TokenSearcher.__init__.<locals>.<genexpr>  s   é € Ð:±6¨a˜C !�G cŸMšM³6ùs   ‚N)r_   Ú_raw)r0   r   s   &&r   r>   ÚTokenSearcher.__init__  s   € Ø—G‘GÑ:±6Ó:Ó:ˆŽ	r!   c                óÜ  € \         P                  ! RRV4      p\         P                  ! RRV4      p\         P                  ! RRV4      p\         P                  ! RRV4      p\         P                  ! WP                  4      pV F>  pVP	                  R4      '       d   K  VP                  R4      '       g   K5  \        R	4      h	  V Uu. uF  q3^R P                  R
4      NK  	  ppV# u upi )ak  
Find instances of the regular expression in the text.
The text is a list of tokens, and a regexp pattern to match
a single token must be surrounded by angle brackets.  E.g.

>>> from nltk.text import TokenSearcher
>>> from nltk.book import text1, text5, text9
>>> text5.findall("<.*><.*><bro>")
you rule bro; telling you bro; u twizted bro
>>> text1.findall("<a>(<.*>)<man>")
monied; nervous; dangerous; white; white; white; pious; queer; good;
mature; white; Cape; great; wise; wise; butterless; white; fiendish;
pale; furious; better; certain; complete; dismasted; younger; brave;
brave; brave; brave
>>> text9.findall("<th.*>{3,}")
thread through those; the thought that; that the thing; the thing
that; that that thing; through these than through; them that the;
through the thick; them that they; thought that the

:param regexp: A regular expression
:type regexp: str
z\sr¯   r±   z(?:<(?:r²   z)>)z	(?<!\\)\.z[^>]z$Bad regexp for TokenSearcher.findallz><éÿÿÿÿ)ÚreÚsubÚfindallr´   Ú
startswithÚendswithr^   Úsplit©r0   ÚregexpÚhitsÚhs   &&  r   rº   ÚTokenSearcher.findall  sÀ   € ô0 —’˜˜r 6Ó*ˆÜ—’˜˜i¨Ó0ˆÜ—’˜˜e VÓ,ˆÜ—’˜ f¨fÓ5ˆô �zŠz˜&§)¡)Ó,ˆó ˆAØ—<‘< ×$Ô$¨¯©°C¯¬Ü Ð!GÓHÐHñ ñ
 .2Ó2©T¨�!�B�—‘˜dÖ#©TˆÐ2Øˆùò 3s   Ã	C))r´   N)	ri   rj   rk   rl   rm   r>   rº   ro   rp   rq   s   @r   r­   r­     s   ø‡ € ñò;÷'ð 'r!   r­   c                   óî   a € ] tR tRt o RtRtRR ltR tR tRR lt	RR	 lt
RR
 ltRR ltR tR tR tRR ltRR ltR tR R ltR!R ltR tR tR t]P2                  ! R4      tR tR tR tRtV tR# )"ÚTexti9  a£  
A wrapper around a sequence of simple (string) tokens, which is
intended to support initial exploration of texts (via the
interactive console).  Its methods perform a variety of analyses
on the text's contexts (e.g., counting, concordancing, collocation
discovery), and display the results.  If you wish to write a
program which makes use of these analyses, then you should bypass
the ``Text`` class, and use the appropriate analysis function or
class directly instead.

A ``Text`` is typically initialized from a given document or
corpus.  E.g.:

>>> import nltk.corpus
>>> from nltk.text import Text
>>> moby = Text(nltk.corpus.gutenberg.words('melville-moby_dick.txt'))

TNc                óR  € V P                   '       d   \        V4      pWn        V'       d	   W n        R# RVR,          9   d;   VR,          P	                  R4      pRP                  R V^V  4       4      V n        R# RP                  R VR,           4       4      R,           V n        R# )	zV
Create a Text object.

:param tokens: The source text.
:type tokens: sequence of str
Ú]:Nrh   NrX   c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir#   ©Ústr©r.   Útoks   & r   r1   Ú Text.__init__.<locals>.<genexpr>b  s   é € Ð C±]¨c¤ S§ ³]ùó   ‚c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir#   rÈ   rÊ   s   & r   r1   rÌ   d  s   é € Ð @±Z¨c¤ S§ ³ZùrÍ   :Né   Nz...N)Ú_COPY_TOKENSrx   r   Únamer{   r_   )r0   r   rÑ   Úends   &&& r   r>   ÚText.__init__S  s�   € ð ××ÐÜ˜&“\ˆFØŒçØŽIØ�F˜3•KÔØ˜•+×#Ñ# CÓ(ˆCØŸ™Ñ C°V¸A¸c±]Ó CÓCˆDŽIàŸ™Ñ @°V¸B¶ZÓ @Ó@À5ÕHˆDŽIr!   c                ó(   € V P                   V,          # r#   )r   )r0   r   s   &&r   Ú__getitem__ÚText.__getitem__j  s   € Ø�{‰{˜1�~Ðr!   c                ó,   € \        V P                  4      # r#   )r   r   rB   s   &r   Ú__len__ÚText.__len__m  s   € Ü�4—;‘;ÓÐr!   c                ó–   € RV P                   9  d   \        V P                  R R7      V n        V P                  P	                  WV4      # )a|  
Prints a concordance for ``word`` with the specified context window.
Word matching is not case-sensitive.

:param word: The target word or phrase (a list of strings)
:type word: str or list
:param width: The width of each line, in characters (default=80)
:type width: int
:param lines: The number of lines to display (default=25)
:type lines: int

:seealso: ``ConcordanceIndex``
Ú_concordance_indexc                 ó"   € V P                  4       # r#   ©r   ©Úss   &r   r'   Ú"Text.concordance.<locals>.<lambda>„  ó
   € ¨1¯7©7¬9r!   ©r<   )Ú__dict__rt   r   rÛ   r¨   ©r0   rH   r‘   r§   s   &&&&r   ÚconcordanceÚText.concordancet  sB   € ð   t§}¡}Ô4Ü&6Ø—‘Ñ!4ô'ˆDÔ#ð ×&Ñ&×8Ñ8¸ÀeÓLÐLr!   c                óš   € RV P                   9  d   \        V P                  R R7      V n        V P                  P	                  W4      RV # )a~  
Generate a concordance for ``word`` with the specified context window.
Word matching is not case-sensitive.

:param word: The target word or phrase (a list of strings)
:type word: str or list
:param width: The width of each line, in characters (default=80)
:type width: int
:param lines: The number of lines to display (default=25)
:type lines: int

:seealso: ``ConcordanceIndex``
rÛ   c                 ó"   € V P                  4       # r#   rÝ   rÞ   s   &r   r'   Ú'Text.concordance_list.<locals>.<lambda>™  rá   r!   râ   N)rã   rt   r   rÛ   r¡   rä   s   &&&&r   r—   ÚText.concordance_list‰  sG   € ð   t§}¡}Ô4Ü&6Ø—‘Ñ!4ô'ˆDÔ#ð ×&Ñ&×7Ñ7¸ÓDÀVÀeÐLÐLr!   c                ó¾  a€ RV P                   9   d#   V P                  V8X  d   V P                  V8X  gŸ   Yn        W n        ^ RIHp VP                  R4      o\        P                  ! V P                  V4      pVP                  ^4       VP                  V3R l4       \        4       p\        VP                  VP                  V4      4      V n        V P                  # )aŠ  
Return collocations derived from the text, ignoring stopwords.

    >>> from nltk.book import text4
    >>> text4.collocation_list()[:2]
    [('United', 'States'), ('fellow', 'citizens')]

:param num: The maximum number of collocations to return.
:type num: int
:param window_size: The number of tokens spanned by a collocation (default=2)
:type window_size: int
:rtype: list(tuple(str, str))
Ú_collocations)Ú	stopwordsÚenglishc                 óV   <€ \        V 4      ^8  ;'       g    V P                  4       S9   # ©é   )r   r   )r/   Úignored_wordss   &€r   r'   Ú'Text.collocation_list.<locals>.<lambda>¹  s#   ø€ ¬s°1«v¸©z×/WÐ/W¸Q¿W¹W»YÈ-Ñ=WÐ/Wr!   )rã   Ú_numÚ_window_sizeÚnltk.corpusrí   r`   r   Ú
from_wordsr   Úapply_freq_filterÚapply_word_filterr
   rx   ÚnbestÚlikelihood_ratiorì   )r0   ÚnumÚwindow_sizerí   ÚfinderÚbigram_measuresrò   s   &&&   @r   Úcollocation_listÚText.collocation_list�  s³   ø€ ð ˜tŸ}™}Ô,Ø—	‘	˜SÔ Ø×!Ñ! [Ô0àŒIØ +Ôõ .à%ŸO™O¨IÓ6ˆMÜ,×7Ò7¸¿¹À[ÓQˆFØ×$Ñ$ QÔ'Ø×$Ñ$Ô%WÔXÜ1Ó3ˆOÜ!%Ø—‘˜_×=Ñ=¸sÓCó"ˆDÔð ×!Ñ!Ð!r!   c                ó¢   € V P                  W4       UUu. uF  w  r4VR,           V,           NK  	  ppp\        \        VRR7      4       R# u uppi )a•  
Print collocations derived from the text, ignoring stopwords.

    >>> from nltk.book import text4
    >>> text4.collocations() # doctest: +NORMALIZE_WHITESPACE
    United States; fellow citizens; years ago; four years; Federal
    Government; General Government; Vice President; American people; God
    bless; Chief Justice; one another; fellow Americans; Old World;
    Almighty God; Fellow citizens; Chief Magistrate; every citizen; Indian
    tribes; public debt; foreign nations


:param num: The maximum number of collocations to print.
:type num: int
:param window_size: The number of tokens spanned by a collocation (default=2)
:type window_size: int
rX   ú; )Ú	separatorN)r   r¤   r   )r0   rü   rý   Úw1Úw2Úcollocation_stringss   &&&   r   ÚcollocationsÚText.collocationsÀ  sO   € ð( )-×(=Ñ(=¸cÔ(Oô
Ù(O™f˜bˆB��H�r�MˆMÑ(Oð 	ñ 
ô 	ŒiÐ+°tÔ<Ö=ùó
s   •Ac                ó8   € V P                   P                  V4      # )z:
Count the number of times this word appears in the text.
)r   Úcountr€   s   &&r   r  Ú
Text.countØ  ó   € ð �{‰{× Ñ  Ó&Ð&r!   c                ó8   € V P                   P                  V4      # )zA
Find the index of the first occurrence of the word in the text.
)r   r{   r€   s   &&r   r{   Ú
Text.indexÞ  r  r!   c                ó   € \         hr#   )ÚNotImplementedError)r0   Úmethods   &&r   ÚreadabilityÚText.readabilityä  s   € ä!Ð!r!   c                óæ  aaa€ RV P                   9  d    \        V P                  R R R7      V n        SP	                  4       oV P                  P
                  oSSP                  4       9   dr   \        SS,          4      o\        VVV3R lSP                  4        4       4      pVP                  V4       UUu. uF  w  rEVNK	  	  ppp\        \        V4      4       R# \        R4       R# u uppi )a>  
Distributional similarity: find other words which appear in the
same contexts as the specified word; list most similar words first.

:param word: The word used to seed the similarity search
:type word: str
:param num: The number of words to generate (default=20)
:type num: int
:seealso: ContextIndex.similar_words()
Ú_word_context_indexc                 ó"   € V P                  4       # r#   )Úisalphar%   s   &r   r'   ÚText.similar.<locals>.<lambda>ö  s
   € ¨a¯i©i¬kr!   c                 ó"   € V P                  4       # r#   rÝ   rÞ   s   &r   r'   r  ö  s
   € ÈÏÉÌr!   )r;   r<   c              3   ól   <"  € T F)  pSV,           F  pVS9   g   K  VS8X  d   K  Vx € K  	  K+  	  R # 5ir#   r$   )r.   r/   rT   rb   ÚwcirH   s   &  €€€r   r1   ÚText.similar.<locals>.<genexpr>ÿ  sB   øé € ð á)�AØ˜QŸ˜�AØ˜‘=ô ð *+¨d©÷ ’áñ Û)ùs   ƒ4�4¦4z
No matchesN)rã   r   r   r  r   r8   Ú
conditionsrF   r   Úmost_commonr¤   r   )	r0   rH   rü   rd   r/   Ú_r`   rb   r  s	   &f&    @@r   ÚsimilarÚText.similarè  sÀ   ú€ ð !¨¯©Ô5ä'3Ø—‘Ñ$9Ñ?Rô(ˆDÔ$ð �z‰z‹|ˆØ×&Ñ&×8Ñ8ˆØ�3—>‘>Ó#Ô#Ü˜3˜t�9“~ˆHÜö àŸ™Ô)óó ˆBð $&§>¡>°#Ô#6Ô7Ñ#6™4˜1“QÑ#6ˆEÑ7Ü”)˜EÓ"Ö#ä�,Öùó 8s   Â:C-c                ó˜  € RV P                   9  d   \        V P                  R R7      V n         V P                  P	                  VR4      pV'       g   \        R4       R# VP                  V4       UUu. uF  w  rEVNK	  	  ppp\        \        R V 4       4      4       R# u uppi   \         d   p\        T4        Rp?R# Rp?ii ; i)a  
Find contexts where the specified words appear; list
most frequent common contexts first.

:param words: The words used to seed the similarity search
:type words: str
:param num: The number of words to generate (default=20)
:type num: int
:seealso: ContextIndex.common_contexts()
r  c                 ó"   € V P                  4       # r#   rÝ   rÞ   s   &r   r'   Ú&Text.common_contexts.<locals>.<lambda>  rá   r!   râ   TzNo common contexts were foundc              3   óF   "  € T F  w  rVR ,           V,           x € K  	  R# 5i)r   Nr$   )r.   r  r  s   &  r   r1   Ú'Text.common_contexts.<locals>.<genexpr>!  s   é € ÐL¹O±&°"  S¥¨2§¢»Oùs   ‚!N)	rã   r   r   r  re   r¤   r  r   r^   )r0   r`   rü   rd   r/   r   Úranked_contextsÚes   &&&     r   re   ÚText.common_contexts
  s¥   € ð !¨¯©Ô5ä'3Ø—‘Ñ!4ô(ˆDÔ$ð		Ø×)Ñ)×9Ñ9¸%ÀÓFˆBßÜÐ5Ö6à13·±ÀÔ1DÔ"EÑ1D©¨£1Ñ1D�Ñ"EÜ”iÑL¹OÓLÓLÖMùó #Føô ô 	Ü�!�HŠHûð	ús5   °#B( ÁB( Á!B( Á5B"ÂB( Â"B( Â(C	Â3CÃC	c                ó"   € ^ RI Hp V! W4       R# )zÌ
Produce a plot showing the distribution of the words through the text.
Requires pylab to be installed.

:param words: The words to be plotted
:type words: list(str)
:seealso: nltk.draw.dispersion_plot()
)Údispersion_plotN)Ú	nltk.drawr,  )r0   r`   r,  s   && r   r,  ÚText.dispersion_plot&  s   € õ 	.á˜Ö$r!   c                óZ   € \        W!4      w  r4\        VR 7      pVP                  W44       V# ))Úorder)r	   r   Úfit)r0   Útokenized_sentsrS   Ú
train_dataÚpadded_sentsÚmodels   &&&   r   Ú_train_default_ngram_lmÚText._train_default_ngram_lm3  s)   € Ü#<¸QÓ#PÑ ˆ
Ü˜!”ˆØ�	‰	�*Ô+Øˆr!   c                óº  € \        RP                  V P                  4      4       Uu. uF  qDP                  R4      NK  	  upV n        \        V R4      '       g>   \        R\        P                  R7       V P                  V P                  ^R7      V n
        . pV^ 8”  g   Q R4       h\        V4      V8  d^   \        V P                  P                  WVR7      4       F(  w  rgVR8X  d   K  VR	8X  d    MVP                  V4       K*  	  V^,          pKm  V'       d   RP                  V4      R,           MR
pV\        VRV 4      ,           p	\        V	4       V	# u upi )a¿  
Print random text, generated using a trigram language model.
See also `help(nltk.lm)`.

:param length: The length of text to generate (default=100)
:type length: int

:param text_seed: Generation can be conditioned on preceding context.
:type text_seed: list(str)

:param random_seed: A random seed or an instance of `random.Random`. If provided,
    makes the random sampling part of generation reproducible. (default=42)
:type random_seed: int
rX   Ú_trigram_modelzBuilding ngram index...)Úfile)rS   z!The `length` must be more than 0.)Ú	text_seedÚrandom_seedz<s>z</s>r¯   N)r   r_   r   r½   Ú_tokenized_sentsÚhasattrr¤   ÚsysÚstderrr6  r9  r   r7   Úgeneraterz   r   )
r0   Úlengthr;  r<  ÚsentÚgenerated_tokensÚidxÚtokenÚprefixÚ
output_strs
   &&&&      r   rA  ÚText.generate9  sC  € ô" )6°c·h±h¸t¿{¹{Ó6KÔ(Ló!
Ù(L �J‰J�sŽOÑ(Lñ!
ˆÔô �tÐ-×.Ò.ÜÐ+´#·*±*Õ=Ø"&×">Ñ">Ø×%Ñ%¨ð #?ó #ˆDÔð Ðà˜ŒzÐ>Ð>Ó>ˆzÜÐ"Ó# fÔ,Ü'Ø×#Ñ#×,Ñ,Ø¸[ð -ó ö‘
�ð
 ˜E”>ÙØ˜F”?ÙØ ×'Ñ'¨Ö.ñð ˜1ÕŠKç.7�—‘˜)Ó$ sÖ*¸RˆØœiÐ(8¸¸&Ð(AÓBÕBˆ
ÜˆjÔØÐùò9!
s   §Ec                ó>   € V P                  4       P                  ! V!  # )zK
See documentation for FreqDist.plot()
:seealso: nltk.prob.FreqDist.plot()
)ÚvocabÚplot)r0   Úargss   &*r   rL  Ú	Text.plotg  s   € ð
 �z‰z‹|× Ò  $Ñ'Ð'r!   c                ó\   € RV P                   9  d   \        V 4      V n        V P                  # )z
:seealso: nltk.prob.FreqDist
Ú_vocab)rã   r   rP  rB   s   &r   rK  Ú
Text.vocabn  s%   € ð ˜4Ÿ=™=Ô(ä" 4›.ˆDŒKØ�{‰{Ðr!   c                óò   € RV P                   9  d   \        V 4      V n        V P                  P                  V4      pV Uu. uF  pRP	                  V4      NK  	  pp\        \        VR4      4       R# u upi )aC  
Find instances of the regular expression in the text.
The text is a list of tokens, and a regexp pattern to match
a single token must be surrounded by angle brackets.  E.g.

>>> from nltk.book import text1, text5, text9
>>> text5.findall("<.*><.*><bro>")
you rule bro; telling you bro; u twizted bro
>>> text1.findall("<a>(<.*>)<man>")
monied; nervous; dangerous; white; white; white; pious; queer; good;
mature; white; Cape; great; wise; wise; butterless; white; fiendish;
pale; furious; better; certain; complete; dismasted; younger; brave;
brave; brave; brave
>>> text9.findall("<th.*>{3,}")
thread through those; the thought that; that the thing; the thing
that; that that thing; through these than through; them that the;
through the thick; them that they; thought that the

:param regexp: A regular expression
:type regexp: str
Ú_token_searcherrX   r  N)rã   r­   rS  rº   r_   r¤   r   r¾   s   &&  r   rº   ÚText.findallw  sc   € ð.  D§M¡MÔ1Ü#0°Ó#6ˆDÔ à×#Ñ#×+Ñ+¨FÓ3ˆÙ%)Ó*¡T �—‘˜–¡TˆÐ*ÜŒi˜˜dÓ#Ö$ùò +s   ÁA4z\w+|[\.\!\?]c                óx  € V^,
          pV^ 8¼  d3   V P                   P                  W,          4      '       g   V^,          pK9  V^ 8w  d	   W,          MRpV^,           pV\        V4      8  d3   V P                   P                  W,          4      '       g   V^,          pKB  V\        V4      8w  d	   W,          MRpWE3# )z¹
One left & one right token, both case-normalized.  Skip over
non-sentence-final punctuation.  Used by the ``ContextIndex``
that is created for ``similar()`` and ``common_contexts()``.
r   r   )Ú_CONTEXT_REÚmatchr   )r0   r   r   Újr   r   s   &&&   r   Ú_contextÚText._context›  s—   € ð ��EˆØ�1Œf˜T×-Ñ-×3Ñ3°FµI×>Ò>Ø��FŠAØ œFˆvŽy¨	ˆð ��EˆØ”#�f“+Œo d×&6Ñ&6×&<Ñ&<¸V½Y×&GÒ&GØ��FŠAØ¤# f£+Ô-�–	°7ˆàˆ}Ðr!   c                ó(   € R V P                   ,          # ©z
<Text: %s>©rÑ   rB   s   &r   Ú__str__ÚText.__str__³  ó   € Ø˜dŸi™iÕ'Ð'r!   c                ó(   € R V P                   ,          # r\  r]  rB   s   &r   r„   ÚText.__repr__¶  r`  r!   )rì   rÛ   rô   rS  r=  r9  rP  rõ   r  rÑ   r   r#   )éO   r«   )rh   é   rg   rð   )éd   Né*   ) ri   rj   rk   rl   rm   rÐ   r>   rÕ   rØ   rå   r—   r   r  r  r{   r  r!  re   r,  r6  rA  rL  rK  rº   r¸   ÚcompilerV  rY  r^  r„   ro   rp   rq   s   @r   rÄ   rÄ   9  s–   ø‡ € ñð. €LôIò.ò ôMô*Mô(!"ôF>ò0'ò'ò"ô  ôDò8%ôô,ò\(òò%ðD —*’*˜_Ó-€Kòò0(÷(ð (r!   rÄ   c                   ó<   a € ] tR tRt o RtR tR tR tR tRt	V t
R# )	ÚTextCollectioni»  a  A collection of texts, which can be loaded with list of texts, or
with a corpus consisting of one or more texts, and which supports
counting, concordancing, collocation discovery, etc.  Initialize a
TextCollection as follows:

>>> import nltk.corpus
>>> from nltk.text import TextCollection
>>> from nltk.book import text1, text2, text3
>>> gutenberg = TextCollection(nltk.corpus.gutenberg)
>>> mytexts = TextCollection([text1, text2, text3])

Iterating over a TextCollection produces all the tokens of all the
texts in order.
c                óæ   € \        VR 4      '       d.   VP                  4        Uu. uF  q!P                  V4      NK  	  ppWn        \        P                  V \        V4      4       / V n        R# u upi )r`   N)r>  Úfileidsr`   Ú_textsrÄ   r>   r   Ú
_idf_cache)r0   ÚsourceÚfs   && r   r>   ÚTextCollection.__init__Ë  sX   € Ü�6˜7×#Ò#Ø/5¯~©~Ô/?Ó@Ñ/?¨!—l‘l 1–oÑ/?ˆFÐ@àŒÜ�‰�dÔ-¨fÓ5Ô6ØˆŽùò	 As   ¥A.c                óD   € VP                  V4      \        V4      ,          # )z"The frequency of the term in text.)r  r   ©r0   ÚtermÚtexts   &&&r   ÚtfÚTextCollection.tfÓ  s   € à�z‰z˜$Ó¤# d£)Õ+Ð+r!   c                ól  € V P                   P                  V4      pVf�   \        V P                   Uu. uF  q1V9   g   K  RNK  	  up4      p\        V P                  4      ^ 8X  d   \	        R4      hV'       d&   \        \        V P                  4      V,          4      MRpW P                   V&   V# u upi )z”The number of texts in the corpus divided by the
number of texts that the term appears in.
If a term does not appear in the corpus, 0.0 is returned.Tz+IDF undefined for empty document collectiong        )rm  rR   r   rl  r^   r   )r0   rs  Úidfrt  Úmatchess   &&   r   rx  ÚTextCollection.idf×  s�   € ð
 �o‰o×!Ñ! $Ó'ˆØŠ;Ü¨D¯KªKÓH©K DÀ4¹<Ÿ4˜4©KÑHÓIˆGÜ�4—;‘;Ó 1Ô$Ü Ð!NÓOÐOß5<”#”c˜$Ÿ+™+Ó&¨Õ0Ô1À#ˆCØ$'�O‰O˜DÑ!Øˆ
ùò Is   ³B1Á B1c                óP   € V P                  W4      V P                  V4      ,          # r#   )ru  rx  rr  s   &&&r   Útf_idfÚTextCollection.tf_idfå  s   € Ø�w‰w�tÓ" T§X¡X¨d£^Õ3Ð3r!   )rm  rl  N)ri   rj   rk   rl   rm   r>   ru  rx  r|  ro   rp   rq   s   @r   ri  ri  »  s#   ø‡ € ñòò,ò÷4ð 4r!   ri  c                  ó”  € ^ RI Hp  \        V P                  RR7      4      p\	        V4       \	        4        \	        R4       VP                  R4       \	        4        \	        R4       VP                  R4       \	        4        \	        R4       VP                  4        \	        4        \	        R4       VP                  . RO4       \	        4        \	        R4       VP                  ^24       \	        4        \	        R	4       \	        R
V^,          4       \	        RVR,          4       \	        RVP                  4       R,          4       R# )é    )ÚbrownÚnews)Ú
categorieszConcordance:zDistributionally similar words:zCollocations:zDispersion plot:zVocabulary plot:z	Indexing:ztext[3]:z
text[3:5]::rñ   é   Nztext.vocab()['news']:N)r�  ÚreportÚsaidÚ	announced)rö   r€  rÄ   r`   r¤   rå   r!  r  r,  rL  rK  )r€  rt  s     r   Údemor‡  é  sæ   € Ý!ä�—‘ v�Ó.Ó/€DÜ	ˆ$„KÜ	„GÜ	ˆ.ÔØ×Ñ�VÔÜ	„GÜ	Ð
+Ô,Ø‡L�L�ÔÜ	„GÜ	ˆ/ÔØ×ÑÔÜ	„Gô 
Ð
ÔØ×ÑÒ@ÔAÜ	„GÜ	Ð
ÔØ‡I�Iˆb„MÜ	„GÜ	ˆ+ÔÜ	ˆ*�d˜1•gÔÜ	ˆ,˜˜S�	Ô"Ü	Ð
! 4§:¡:£<°Õ#7Ö8r!   Ú__main__)r   Úqueryr   r˜   r�   rž   r¦   )r   rt   r­   rÄ   ri  )(rm   r¸   r?  r‰   Úcollectionsr   r   r   Ú	functoolsr   Úmathr   Únltk.collocationsr   Únltk.lmr   Únltk.lm.preprocessingr	   Únltk.metricsr
   r   Únltk.probabilityr   r6   r   Únltk.tokenizer   Ú	nltk.utilr   r   r   r   r   rt   r­   rÄ   ri  r‡  ri   Ú__all__r$   r!   r   Ú<module>r•     s¦   ðñó 
Û 
Û ß 8Ñ 8Ý Ý å 5Ý Ý ;ß 7Ý 7Ý %Ý 'ß >Ñ >áØÚMó€÷Xñ X÷v|-ñ |-÷~5ñ 5÷p~(ñ ~(ôD+4�Tô +4ò\9ð< ˆzÔÙ„Fò‚r!   