d*e?fd+YZ@eed,eAfd-YZBd.eBfd/YZCd0eBfd1YZDd2eBfd3YZEd4eEfd5YZFd6eFfd7YZGidd8ZHdd9d:ZId d;ZJdS(<i(tprint_functionN(tislicetchaint combinations(tpprint(t defaultdicttdeque(t version_info(t slice_boundstraise_unorderable_types( t class_typest text_typet string_typesttotal_orderingtpython_2_unicode_compatiblet getproxiest ProxyHandlert build_openertinstall_openertHTTPPasswordMgrWithDefaultRealmtProxyBasicAuthHandlertProxyDigestAuthHandlertselfc Cs`ddl}t|t|ts1|j}ntd|jxttj |j D]\}}|j drq^nt |dt rq^n|j|\}}}}|r |ddkr |dkst|t|kr |d}d||f}n|j||||} ttjd || fd d d d t|dq^WdS(Nis%%s supports the following operations:t_t__deprecated__iRis%s.%ss%s%stinitial_indents - tsubsequent_indentt i(tinspecttstrt isinstanceR t __class__tprintt__name__tsortedtpydoct allmethodstitemst startswithtgetattrtFalset getargspectNonetlent formatargspecttextwraptfill( tobjtselfnameRtnametmethodtargstvarargstvarkwtdefaultstargspec((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytusage!s(   ($ cCsddl}|jjjdkS(s Return True if this function is run within idle. Tkinter programs that are run in idle should never call ``Tk.mainloop``; so this function should be used to gate all calls to ``Tk.mainloop``. :warning: This function works by checking ``sys.stdin``. If the user has modified ``sys.stdin``, then it may return incorrect results. :rtype: bool iNtPyShelltRPCProxy(R9R:(tsyststdinRR!(R;((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytin_idle<s icCs ttt|||dS(s Pretty print a sequence of data items :param data: the data stream to print :type data: sequence or iter :param start: the start position :type start: int :param end: the end position :type end: int N(RtlistR(tdatatstarttend((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytprNs iFcCs&tdjtj|d|dS(s Pretty print a string, breaking lines on whitespace :param s: the string to print, consisting of words and spaces :type s: str :param width: the display width :type width: int s twidthN(R tjoinR-twrap(tsRC((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt print_string[s RcCs%djtj|j|d|S(s# Pretty print a list of text tokens, breaking lines on whitespace :param tokens: the tokens to print :type tokens: list :param separator: the string to use to separate tokens :type separator: str :param width: the display width (default=70) :type width: int s RC(RDR-RE(ttokenst separatorRC((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt tokenwrapfs cCstddkotddkS(Niiii(R(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytpy25xscCstddkotddkS(Niiii(R(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytpy26zscCstddkotddkS(Niiii(R(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytpy27|stIndexcBseZdZRS(cCs<tj|tx%|D]\}}||j|qWdS(N(Rt__init__R>tappend(Rtpairstkeytvalue((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyROs(R!t __module__RO(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRNst{t}cCs7ttj|tjj|d||jdS(s3 Return a string with markers surrounding the matched substrings. Search str for substrings matching ``regexp`` and wrap the matches with braces. This is convenient for learning about regular expressions. :param regexp: The regular expression. :type regexp: str :param string: The string being matched. :type string: str :param left: The left delimiter (printed before the matched substring) :type left: str :param right: The right delimiter (printed after the matched substring) :type right: str :rtype: str s\g<0>N(R tretcompiletMtsubtrstrip(tregexptstringtlefttright((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytre_showscCs]t|dr|jSt|trMt|d}|jSWdQXn tddS(Ntreadtrs2Must be called with a filename or file-like object(thasattrRaRR topent ValueError(tftinfile((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt filestrings  c#st|dfg}xk|r|j\}|V|kry'|jfd||DWqtk r{qXqqWdS(sTraverse the nodes of a tree in breadth-first order. (No need to check for cycles.) The first argument should be the tree root; children should be a function taking as argument a tree node and returning an iterator of the node's children. ic3s|]}|dfVqdS(iN((t.0tc(tdepth(s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pys sN(Rtpoplefttextendt TypeError(ttreetchildrentmaxdepthtqueuetnode((Rks[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt breadth_firsts  ' cCsWd}dg}y|jtjtjWntk r?nXy|jtjdWnttfk rtnXy|jtjdWnttfk rnX|jdxN|D]F}|sqnyt ||}|}Wnt t fk rqXPqW|sIt ddj g|D]}|r!t |^q!n ||fSdS(st Given a byte string, attempt to decode it. Tries the standard 'UTF8' and 'latin-1' encodings, Plus several gathered from locale information. The calling program *must* first call:: locale.setlocale(locale.LC_ALL, '') If successful it returns ``(decoded_unicode, successful_encoding)``. If unsuccessful it raises a ``UnicodeError``. sutf-8islatin-1s@Unable to decode input data. Tried the following encodings: %s.s, N(R*RPtlocalet nl_langinfotCODESETtAttributeErrort getlocalet IndexErrortgetdefaultlocaleR t UnicodeErrort LookupErrorRDtrepr(R?tsuccessful_encodingt encodingstenctdecoded((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytguess_encodings:      5cCs<t}g|D](}||kr|j| r|^qS(N(tsettadd(txstseentx((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt unique_list s cCsktt}xX|D]P}t||drUx4||D]}||j|q7Wq||||RcRP(tdt inverted_dictRRtterm((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt invert_dicts  cs|rdn dtfdD}tfdD}xD]}||}||}xe|r|j}|j|||j||O}||j||O}||8}qwWqZW|S(s Calculate the transitive closure of a directed graph, optionally the reflexive transitive closure. The algorithm is a slight modification of the "Marking Algorithm" of Ioannidis & Ramakrishnan (1998) "Efficient Transitive Closure Algorithms". :param graph: the initial graph, represented as a dictionary of sets :type graph: dict(set) :param reflexive: if set, also make the closure reflexive :type reflexive: bool :rtype: dict(set) cSs t|gS(N(R(tk((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt1scSstS(N(R(R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyR3sc3s%|]}||jfVqdS(N(tcopy(RiR(tgraph(s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pys 5sc3s!|]}||fVqdS(N((RiR(tbase_set(s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pys 7s(tdicttpopRt setdefaulttget(Rt reflexivet agenda_grapht closure_graphtitagendatclosuretj((RRs[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyttransitive_closure"s        cCsLi}x?|D]7}x.||D]"}|j|tj|qWq W|S(s Inverts a directed graph. :param graph: the graph, represented as a dictionary of sets :type graph: dict(set) :return: the inverted graph :rtype: dict(set) (RRR(RtinvertedRRRS((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt invert_graphDs  $cCstddS(Ns>To remove HTML markup, use BeautifulSoup's get_text() function(tNotImplementedError(thtml((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt clean_htmlYscCstddS(Ns>To remove HTML markup, use BeautifulSoup's get_text() function(R(turl((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt clean_url\scGsg}xx|D]p}t|ttfs4|g}nxF|D]>}t|ttfrl|jt|q;|j|q;Wq W|S(s Flatten a list. >>> from nltk.util import flatten >>> flatten(1, 2, ['b', 'a' , ['c', 'd']], 3) [1, 2, 'b', 'a', 'c', 'd', 3] :param args: items and lists to be combined into a single list :rtype: list (RR>ttupleRmtflattenRP(R3Rtltitem((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRcs    ccst|}|r/t|f|d|}n|rRt||f|d}ng}x-|dkr|jt||d8}q[Wx-|D]%}|j|t|V|d=qWdS(s Return the ngrams generated from a sequence of items, as an iterator. For example: >>> from nltk.util import ngrams >>> list(ngrams([1,2,3,4,5], 3)) [(1, 2, 3), (2, 3, 4), (3, 4, 5)] Use ngrams for a list version of this function. Set pad_left or pad_right to true in order to get additional ngrams: >>> list(ngrams([1,2,3,4,5], 2, pad_right=True)) [(1, 2), (2, 3), (3, 4), (4, 5), (5, None)] :param sequence: the source data to be converted into ngrams :type sequence: sequence or iter :param n: the degree of the ngrams :type n: int :param pad_left: whether the ngrams should be left-padded :type pad_left: bool :param pad_right: whether the ngrams should be right-padded :type pad_right: bool :param pad_symbol: the symbol to use for padding (default is None) :type pad_symbol: any :rtype: iter(tuple) iiN(titerRRPtnextR(tsequencetntpad_leftt pad_rightt pad_symbolthistoryR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytngramss    cks&xt|d|D] }|VqWdS(s Return the bigrams generated from a sequence of items, as an iterator. For example: >>> from nltk.util import bigrams >>> list(bigrams([1,2,3,4,5])) [(1, 2), (2, 3), (3, 4), (4, 5)] Use bigrams for a list version of this function. :param sequence: the source data to be converted into bigrams :type sequence: sequence or iter :rtype: iter(tuple) iN(R(RtkwargsR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytbigramsscks&xt|d|D] }|VqWdS(s Return the trigrams generated from a sequence of items, as an iterator. For example: >>> from nltk.util import trigrams >>> list(trigrams([1,2,3,4,5])) [(1, 2, 3), (2, 3, 4), (3, 4, 5)] Use trigrams for a list version of this function. :param sequence: the source data to be converted into trigrams :type sequence: sequence or iter :rtype: iter(tuple) iN(R(RRR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyttrigramssiccs\|dkrt|}nx:t||dD]%}xt||D] }|VqEWq/WdS(s Returns all possible ngrams generated from a sequence of items, as an iterator. >>> sent = 'a b c'.split() >>> list(everygrams(sent)) [('a',), ('b',), ('c',), ('a', 'b'), ('b', 'c'), ('a', 'b', 'c')] >>> list(everygrams(sent, max_len=2)) [('a',), ('b',), ('c',), ('a', 'b'), ('b', 'c')] :param sequence: the source data to be converted into trigrams :type sequence: sequence or iter :param min_len: minimum length of the ngrams, aka. n-gram order/degree of ngram :type min_len: int :param max_len: maximum length of the ngrams (set to length of sequence by default) :type max_len: int :rtype: iter(tuple) iiN(R+trangeR(Rtmin_lentmax_lenRtng((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt everygramss  ccsyxrt|||dtD]W}|d }|d}x:t||dD]%}|ddkrdqHn||VqHWqWdS(s Returns all possible skipgrams generated from a sequence of items, as an iterator. Skipgrams are ngrams that allows tokens to be skipped. Refer to http://homepages.inf.ed.ac.uk/ballison/pdf/lrec_skipgrams.pdf >>> sent = "Insurgents killed in ongoing fighting".split() >>> list(skipgrams(sent, 2, 2)) [('Insurgents', 'killed'), ('Insurgents', 'in'), ('Insurgents', 'ongoing'), ('killed', 'in'), ('killed', 'ongoing'), ('killed', 'fighting'), ('in', 'ongoing'), ('in', 'fighting'), ('ongoing', 'fighting')] >>> list(skipgrams(sent, 3, 2)) [('Insurgents', 'killed', 'in'), ('Insurgents', 'killed', 'ongoing'), ('Insurgents', 'killed', 'fighting'), ('Insurgents', 'in', 'ongoing'), ('Insurgents', 'in', 'fighting'), ('Insurgents', 'ongoing', 'fighting'), ('killed', 'in', 'ongoing'), ('killed', 'in', 'fighting'), ('killed', 'ongoing', 'fighting'), ('in', 'ongoing', 'fighting')] :param sequence: the source data to be converted into trigrams :type sequence: sequence or iter :param n: the degree of the ngrams :type n: int :param k: the skip distance :type k: int :rtype: iter(tuple) RiiN(RtTrueRR*(RRRtngramtheadttailt skip_tail((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt skipgramss   t OrderedDictcBseZddZdZdZdZdZdZdZ dZ dZ ddd Z d Z dd Zd Zd ZRS(cKs`|j||jd|_|jd|_|dkrLtj|ntj||dS(Ntkeystdefault_factory(RRt_keyst_default_factoryR*RRO(RR?R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRO s  cCs$tj|||jj|dS(N(Rt __delitem__Rtremove(RRR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRscCs6ytj||SWntk r1|j|SXdS(N(Rt __getitem__tKeyErrort __missing__(RRR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs cCsd|jDS(Ncss|] }|VqdS(N((RiRR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pys s(R(R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRscCs/|j r%||jkr%tn|jS(N(RRR(RRR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs cCs9tj|||||jkr5|jj|ndS(N(Rt __setitem__RRP(RRRR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyR#scCstj||jjdS(N(RtclearR(R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyR(s cCstj|}|j|_|S(N(RRR(RR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyR,s cCst|j|jS(N(tzipRtvalues(R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyR%1scCs|r|rCt|ts!tt|t|ks?t|St|tsvt|tsvt|tsvtt|tst|tr|jSt|trg|D]\}}|^qSnd|jkr|jSgSdS(NR( RR>tAssertionErrorR+RRRt__dict__R(RR?RRRRS((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyR5s  cCs?|jstn|jj}||}||=||fS(N(RRR(RRRRS((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytpopitemHs    cCs9tj|||||jkr5|jj|ndS(N(RRRRP(RRRtfailobj((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRQscCsPtj||x9|j|D](}||jkr |jj|q q WdS(N(RtupdateRRRP(RR?RR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRVscCst|j|jS(N(tmapRR(R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyR\sN(R!RTR*RORRRRRRRR%RRRRR(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs           tAbstractLazySequencecBseZdZdZdZdZdZdZdddZ dZ dZ d Z d Z d Zd Zd ZdZdZdZdZRS(sG An abstract base class for read-only sequences whose values are computed as needed. Lazy sequences act like tuples -- they can be indexed, sliced, and iterated over; but they may not be modified. The most common application of lazy sequences in NLTK is for corpus view objects, which provide access to the contents of a corpus without loading the entire corpus into memory, by loading pieces of the corpus from disk as needed. The result of modifying a mutable element of a lazy sequence is undefined. In particular, the modifications made to the element may or may not persist, depending on whether and when the lazy sequence caches that element's value or reconstructs it from scratch. Subclasses are required to define two methods: ``__len__()`` and ``iterate_from()``. cCstddS(se Return the number of tokens in the corpus file underlying this corpus view. s!should be implemented by subclassN(R(R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt__len__zscCstddS(s Return an iterator that generates the tokens in the corpus file underlying this corpus view, starting at the token number ``start``. If ``start>=len(self)``, then this iterator will generate no tokens. s!should be implemented by subclassN(R(RR@((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt iterate_fromscCst|tr4t||\}}t|||S|dkrS|t|7}n|dkrntdnyt|j|SWntk rtdnXdS(s Return the *i* th token in the corpus file underlying this corpus view. Negative indices and spans are both supported. isindex out of rangeN( RtsliceRtLazySubsequenceR+RzRRt StopIteration(RRR@tstop((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs   cCs |jdS(sdReturn an iterator that generates the tokens in the corpus file underlying this corpus view.i(R(R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRscstfd|DS(s8Return the number of times this list contains ``value``.c3s!|]}|krdVqdS(iN((Ritelt(RS(s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pys s(tsum(RRS((RSs[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytcountscCskt|t||\}}x:tt|||D] \}}||kr7||Sq7WtddS(sReturn the index of the first occurrence of ``value`` in this list that is greater than or equal to ``start`` and less than ``stop``. Negative start and stop values are treated like negative slice bounds -- i.e., they count from the end of the list.sindex(x): x not in listN(RRt enumerateRRe(RRSR@RRR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pytindexs % cCst|j|S(s,Return true if this list contains ``value``.(tboolR(RRS((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt __contains__scCst||gS(s,Return a list concatenating self with other.(tLazyConcatenation(Rtother((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt__add__scCst||gS(s,Return a list concatenating other with self.(R(RR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt__radd__scCst|g|S(s=Return a list concatenating self with itself ``count`` times.(R(RR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt__mul__scCst|g|S(s=Return a list concatenating self with itself ``count`` times.(R(RR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt__rmul__si<cCsg}d}x|D]m}|jt||t|dd7}||jkrt|dkrdtdj|d SqWdtdj|SdS(s Return a string representation for this corpus view that is similar to a list's representation; but if it would be more than 60 characters long, it is truncated. iiis [%s, ...]s, s[%s]N(RPR~R+t_MAX_REPR_SIZER RD(RtpiecestlengthR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt__repr__s !cCs.t|t|ko-t|t|kS(N(ttypeR>(RR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt__eq__scCs ||k S(N((RR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt__ne__scCsAt|t|kr+td||nt|t|kS(Nt<(RR R>(RR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt__lt__scCstd|jjdS(sH :raise ValueError: Corpus view objects are unhashable. s%s objects are unhashableN(ReRR!(R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyt__hash__sN(R!RTt__doc__RRRRRR*RRRRRRRRRRRR(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRds$             RcBs8eZdZdZdZdZdZdZRS(s A subsequence produced by slicing a lazy sequence. This slice keeps a reference to its source sequence, and generates its values by looking them up in the source sequence. idcCsD|||jkr3tt|j|||Stj|SdS(s Construct a new slice from a given underlying sequence. The ``start`` and ``stop`` indices should be absolute indices -- i.e., they should not be negative (for indexing from the back of a list) or greater than the length of ``source``. N(tMIN_SIZER>RRtobjectt__new__(tclstsourceR@R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs cCs||_||_||_dS(N(t_sourcet_startt_stop(RRR@R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyROs  cCs|j|jS(N(RR(R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRscCs3t|jj||jtdt||S(Ni(RRRRtmaxR+(RR@((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyR s(R!RTRRRRORR(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs   RcBs)eZdZdZdZdZRS(s% A lazy sequence formed by concatenating a list of lists. This underlying list of lists may itself be lazy. ``LazyConcatenation`` maintains an index that it uses to keep track of the relationship between offsets in the concatenated lists and offsets in the sublists. cCs||_dg|_dS(Ni(t_listt_offsets(Rt list_of_lists((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyROs cCsMt|jt|jkrBx!|j|jdD]}q5Wn|jdS(Ni(R+RRR(Rttok((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRsccsm||jdkr/tj|j|d}nt|jd}|j|}t|jtrv|jj|}nt|j|d}x|D]}|t|jdkr|t||jdkst d|jj |t|n-|j|d|t|ks$t dx$|t d||D] }|Vq<W|t|7}|d7}qWdS(Niis!offests not monotonic increasing!s"inconsistent list value (num elts)i( Rtbisectt bisect_rightR+RRRRRR*RRPR(Rt start_indext sublist_indexRt sublist_itertsublistRS((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyR s$    $  (R!RTRRORR(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs  tLazyMapcBs2eZdZdZdZdZdZRS(s A lazy sequence whose elements are formed by applying a given function to each element in one or more underlying lists. The function is applied lazily -- i.e., when you read a value from the list, ``LazyMap`` will calculate that value by applying its function to the underlying lists' value(s). ``LazyMap`` is essentially a lazy version of the Python primitive function ``map``. In particular, the following two expressions are equivalent: >>> from nltk.util import LazyMap >>> function = str >>> sequence = [1,2,3] >>> map(function, sequence) # doctest: +SKIP ['1', '2', '3'] >>> list(LazyMap(function, sequence)) ['1', '2', '3'] Like the Python ``map`` primitive, if the source lists do not have equal size, then the value None will be supplied for the 'missing' elements. Lazy maps can be useful for conserving memory, in cases where individual values take up a lot of space. This is especially true if the underlying list's values are constructed lazily, as is the case with many corpus readers. A typical example of a use case for this class is performing feature detection on the tokens in a corpus. Since featuresets are encoded as dictionaries, which can take up a lot of memory, using a ``LazyMap`` can significantly reduce memory usage when training and running classifiers. cOs|stdn||_||_|jdd|_|jdkrQind|_td|Dt|k|_ dS(sJ :param function: The function that should be applied to elements of ``lists``. It should take as many arguments as there are ``lists``. :param lists: The underlying lists. :param cache_size: Determines the size of the cache used by this lazy map. (default=5) s"LazyMap requires at least two argst cache_sizeiicss|]}t|tVqdS(N(RR(Ritlst((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pys tsN( Rnt_listst_funcRt _cache_sizeR*t_cacheRR+t _all_lazy(Rtfunctiontliststconfig((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRO`s    ccsJt|jdkrQ|jrQx,|jdj|D]}|j|Vq5WdSt|jdkrxtry|j|jd|VWntk rdSX|d7}qiWn|jrmg|jD]}|j|^q}xctrig}x<|D]4}y|jt|Wq|jdqXqW|dgt|jkrNdS|j|V|d7}qWnxtrEy$g|jD]}||^q}Wntk r)dgt|j}xCt |jD]2\}}y||||s(RR (R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs(R!RTRRORRR(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyR>s !  ) tLazyZipcBs)eZdZdZdZdZRS(s A lazy sequence whose elements are tuples, each containing the i-th element from each of the argument sequences. The returned list is truncated in length to the length of the shortest argument sequence. The tuples are constructed lazily -- i.e., when you read a value from the list, ``LazyZip`` will calculate that value by forming a tuple from the i-th element of each of the argument sequences. ``LazyZip`` is essentially a lazy version of the Python primitive function ``zip``. In particular, an evaluated LazyZip is equivalent to a zip: >>> from nltk.util import LazyZip >>> sequence1, sequence2 = [1, 2, 3], ['a', 'b', 'c'] >>> zip(sequence1, sequence2) # doctest: +SKIP [(1, 'a'), (2, 'b'), (3, 'c')] >>> list(LazyZip(sequence1, sequence2)) [(1, 'a'), (2, 'b'), (3, 'c')] >>> sequences = [sequence1, sequence2, [6,7,8,9]] >>> list(zip(*sequences)) == list(LazyZip(*sequences)) True Lazy zips can be useful for conserving memory in cases where the argument sequences are particularly long. A typical example of a use case for this class is combining long sequences of gold standard and predicted values in a classification or tagging task in order to calculate accuracy. By constructing tuples lazily and avoiding the creation of an additional long sequence, memory usage can be significantly reduced. cGstj|d|dS(sT :param lists: the underlying lists :type lists: list(list) cWs|S(N((telts((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRsN(RRO(RR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyROsccsDtj||}x+|t|kr?t|V|d7}qWdS(Ni(RRR+R(RRR((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs  cCstd|jDS(Ncss|]}t|VqdS(N(R+(RiR ((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pys s(tminR (R((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs(R!RTRRORR(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRs  t LazyEnumeratecBseZdZdZRS(s A lazy sequence whose elements are tuples, each ontaining a count (from zero) and a value yielded by underlying sequence. ``LazyEnumerate`` is useful for obtaining an indexed list. The tuples are constructed lazily -- i.e., when you read a value from the list, ``LazyEnumerate`` will calculate that value by forming a tuple from the count of the i-th element and the i-th element of the underlying sequence. ``LazyEnumerate`` is essentially a lazy version of the Python primitive function ``enumerate``. In particular, the following two expressions are equivalent: >>> from nltk.util import LazyEnumerate >>> sequence = ['first', 'second', 'third'] >>> list(enumerate(sequence)) [(0, 'first'), (1, 'second'), (2, 'third')] >>> list(LazyEnumerate(sequence)) [(0, 'first'), (1, 'second'), (2, 'third')] Lazy enumerations can be useful for conserving memory in cases where the argument sequences are particularly long. A typical example of a use case for this class is obtaining an indexed list for a long sequence of values. By constructing tuples lazily and avoiding the creation of an additional long sequence, memory usage can be significantly reduced. cCs#tj|tt||dS(sI :param lst: the underlying list :type lst: list N(RRORR+(RR ((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRO s(R!RTRRO(((s[/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/util.pyRsc CsC|d}t|}d}d}t|drMtj|jjd}n-|jdd|jd}|jdx||kr>||f}||d} |j| r|| \} } nd} xt rT|jt d| d| dkr|j n|j} |j } | dkr/Pn|| d} | |dkrdSqW||krt| | f|| sd       R         :  "    +   \(/}1*G+