
    /h                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
Jr  SSKJr  SSKJr  SSKJrJr  SSKJrJr   SSKJr  SS
KJrJr  SSKJr  \R@                  " \RB                  SS9r"/ r# \RH                  RK                  SS5      RM                  \RN                  5      r(\#\( V s/ s H  o (       d  M  U PM     sn -  r#S\RH                  ;  aI  \RF                  RS                  S5      S:w  a*  \#RU                  \RF                  RS                  S5      5        \RV                  RY                  S5      (       a  \#\RF                  R[                  \R\                  S5      \RF                  R[                  \R\                  SS5      \RF                  R[                  \R\                  SS5      \RF                  R[                  \RH                  RK                  SS5      S5      SSS/-  r#Oz\#\RF                  R[                  \R\                  S5      \RF                  R[                  \R\                  SS5      \RF                  R[                  \R\                  SS5      SSSS/-  r#      SYS  jr/S! r0S" r1SZS# jr2 " S$ S%\
S&9r3 " S' S(\3\45      r5\" S)5       " S* S+\5      5       r6 " S, S-\55      r7 " S. S/\35      r80 r9 S[S0 jr:S\S1 jr;S2S3S4S5S6S7S8S9S:S;S<S=.r<S>S?S@SASBSCSDSESFSGSGSH.r=SI r>S]SJ jr?S^SK jr@SL rASM rB      S_SN jrCS`SO jrDSP rESQ rF " SR SS5      rG " ST SU\R                  5      rI " SV SW5      rJ/ SXQrKg! \ a
    SS	KJr   GNf = fs  sn f )aa  
Functions to find and load NLTK resource files, such as corpora,
grammars, and saved processing objects.  Resource files are identified
using URLs, such as ``nltk:corpora/abc/rural.txt`` or
``https://raw.githubusercontent.com/nltk/nltk/develop/nltk/test/toy.cfg``.
The following URL protocols are supported:

  - ``file:path``: Specifies the file whose path is *path*.
    Both relative and absolute paths may be used.

  - ``https://host/path``: Specifies the file stored on the web
    server *host* at path *path*.

  - ``nltk:path``: Specifies the file stored in the NLTK data
    package at *path*.  NLTK will search for these files in the
    directories specified by ``nltk.data.path``.

If no protocol is specified, then the default protocol ``nltk:`` will
be used.

This module provides to functions that can be used to access a
resource file, given its URL: ``load()`` loads a given resource, and
adds it to a resource cache; and ``retrieve()`` copies a given resource
to a local file.
    N)ABCMetaabstractmethod)WRITE)GzipFile)BytesIOTextIOWrapper)url2pathnameurlopen)Z_SYNC_FLUSH)Z_FINISH)grammarsem)
deprecatedz  )prefix	NLTK_DATA APPENGINE_RUNTIMEz~/z~/nltk_datawin	nltk_datasharelibAPPDATAzC:\zC:\nltk_datazD:\nltk_datazE:\nltk_dataz/usr/share/nltk_dataz/usr/local/share/nltk_dataz/usr/lib/nltk_dataz/usr/local/lib/nltk_datac                 8    Uc  [        XX$5      n[        XCXV5      $ N)r   r   )filenamemodecompresslevelencodingfileobjerrorsnewlines          A/var/www/auris/envauris/lib/python3.13/site-packages/nltk/data.pygzip_open_unicoder#   i   s"     8=BF<<    c                     U R                  SS5      u  pUS:X  a   X4$ US:X  a-  UR                  S5      (       a  SUR                  S5      -   nX4$ [        R                  " SSU5      nX4$ )a  
Splits a resource url into "<protocol>:<path>".

>>> windows = sys.platform.startswith('win')
>>> split_resource_url('nltk:home/nltk')
('nltk', 'home/nltk')
>>> split_resource_url('nltk:/home/nltk')
('nltk', '/home/nltk')
>>> split_resource_url('file:/home/nltk')
('file', '/home/nltk')
>>> split_resource_url('file:///home/nltk')
('file', '/home/nltk')
>>> split_resource_url('file:///C:/home/nltk')
('file', '/C:/home/nltk')
:   nltkfile/z^/{0,2}r   )split
startswithlstripresubresource_urlprotocolpath_s      r"   split_resource_urlr4   w   s      #((a0OH6 ? 
V	C  %,,s++E ? z2u-?r$   c                 >    [        U 5      u  pUS:X  a4  [        R                  R	                  U5      (       a  Sn[        USS5      nO0US:X  a  Sn[        USS5      nOUS:X  a  Sn[        US5      nOUS-  nS	R                  X/5      $ ! [         a    SnU n Nf = f)
a  
Normalizes a resource url

>>> windows = sys.platform.startswith('win')
>>> os.path.normpath(split_resource_url(normalize_resource_url('file:grammar.fcfg'))[1]) == \
... ('\\' if windows else '') + os.path.abspath(os.path.join(os.curdir, 'grammar.fcfg'))
True
>>> not windows or normalize_resource_url('file:C:/dir/file') == 'file:///C:/dir/file'
True
>>> not windows or normalize_resource_url('file:C:\\dir\\file') == 'file:///C:/dir/file'
True
>>> not windows or normalize_resource_url('file:C:\\dir/file') == 'file:///C:/dir/file'
True
>>> not windows or normalize_resource_url('file://C:/dir/file') == 'file:///C:/dir/file'
True
>>> not windows or normalize_resource_url('file:////C:/dir/file') == 'file:///C:/dir/file'
True
>>> not windows or normalize_resource_url('nltk:C:/dir/file') == 'file:///C:/dir/file'
True
>>> not windows or normalize_resource_url('nltk:C:\\dir\\file') == 'file:///C:/dir/file'
True
>>> windows or normalize_resource_url('file:/dir/file/toy.cfg') == 'file:///dir/file/toy.cfg'
True
>>> normalize_resource_url('nltk:home/nltk')
'nltk:home/nltk'
>>> windows or normalize_resource_url('nltk:/home/nltk') == 'file:///home/nltk'
True
>>> normalize_resource_url('https://example.com/dir/file')
'https://example.com/dir/file'
>>> normalize_resource_url('dir/file')
'nltk:dir/file'
r(   zfile://FNr)   znltk:Tz://r   )r4   
ValueErrorospathisabsnormalize_resource_namejoin)r1   r2   names      r"   normalize_resource_urlr=      s    B+L9 6bggmmD11&tUD9	V	&tUD9	V	&tT2 	E77H#$$%  s   B BBc                    [        [        R                  " SU 5      5      =(       d)    U R                  [        R
                  R                  5      n[        R                  R                  S5      (       a  U R                  S5      n O[        R                  " SSU 5      n U(       a   [        R
                  R                  U 5      n OOUc  [        R                  n[        R
                  R                  [        R
                  R                  X 5      5      n U R!                  SS5      R!                  [        R
                  R                  S5      n [        R                  R                  S5      (       a)  [        R
                  R#                  U 5      (       a  SU -   n U(       a  U R                  S5      (       d  U S-  n U $ )a  
:type resource_name: str or unicode
:param resource_name: The name of the resource to search for.
    Resource names are posix-style relative path names, such as
    ``corpora/brown``.  Directory names will automatically
    be converted to a platform-appropriate path separator.
    Directory trailing slashes are preserved

>>> windows = sys.platform.startswith('win')
>>> normalize_resource_name('.', True)
'./'
>>> normalize_resource_name('./', True)
'./'
>>> windows or normalize_resource_name('dir/file', False, '/') == '/dir/file'
True
>>> not windows or normalize_resource_name('C:/file', False, '/') == '/C:/file'
True
>>> windows or normalize_resource_name('/dir/file', False, '/') == '/dir/file'
True
>>> windows or normalize_resource_name('../dir/file', False, '/') == '/dir/file'
True
>>> not windows or normalize_resource_name('/dir/file', True, '/') == 'dir/file'
True
>>> windows or normalize_resource_name('/dir/file', True, '/') == '/dir/file'
True
z[\\/.]$r   r*   z^/+\)boolr.   searchendswithr7   r8   sepsysplatformr,   r-   r/   normpathcurdirabspathr;   replacer9   )resource_nameallow_relativerelative_pathis_dirs       r"   r:   r:      s/   6 "))J67 =;Q;Q
<F ||u%%%,,S1vsM:((7 IIM](RS!))$4<<RWW[[#NM
||u%%"''--*F*Fm+m,,S11r$   c                   L    \ rS rSrSr\SS j5       r\S 5       r\S 5       rSr	g)	PathPointer   aU  
An abstract base class for 'path pointers,' used by NLTK's data
package to identify specific paths.  Two subclasses exist:
``FileSystemPathPointer`` identifies a file that can be accessed
directly via a given absolute path.  ``ZipFilePathPointer``
identifies a file contained within a zipfile, that can be accessed
by reading that zipfile.
Nc                     g)z
Return a seekable read-only stream that can be used to read
the contents of the file identified by this path pointer.

:raise IOError: If the path specified by this pointer does
    not contain a readable file.
N )selfr   s     r"   openPathPointer.open	      r$   c                     g)z
Return the size of the file pointed to by this path pointer,
in bytes.

:raise IOError: If the path specified by this pointer does
    not contain a readable file.
NrR   rS   s    r"   	file_sizePathPointer.file_size  rV   r$   c                     g)a   
Return a new path pointer formed by starting at the path
identified by this pointer, and then following the relative
path given by ``fileid``.  The path components of ``fileid``
should be separated by forward slashes, regardless of
the underlying file system's path separator character.
NrR   )rS   fileids     r"   r;   PathPointer.join  rV   r$   rR   r   )
__name__
__module____qualname____firstlineno____doc__r   rT   rY   r;   __static_attributes__rR   r$   r"   rO   rO      sC          r$   rO   )	metaclassc                   P    \ rS rSrSrS r\S 5       rSS jrS r	S r
S	 rS
 rSrg)FileSystemPathPointeri(  za
A path pointer that identifies a file which can be accessed
directly via a given absolute path.
c                     [         R                  R                  U5      n[         R                  R                  U5      (       d  [	        SU-  5      eXl        g)zk
Create a new path pointer for the given absolute path.

:raise IOError: If the given path does not exist.
zNo such file or directory: %rN)r7   r8   rH   existsOSError_pathrS   rj   s     r"   __init__FileSystemPathPointer.__init__.  s?     &ww~~e$$9EABB
r$   c                     U R                   $ )z2The absolute path identified by this path pointer.rj   rX   s    r"   r8   FileSystemPathPointer.path=  s     zzr$   Nc                 N    [        U R                  S5      nUb  [        X!5      nU$ Nrb)rT   rj   SeekableUnicodeStreamReaderrS   r   streams      r"   rT   FileSystemPathPointer.openB  s'    djj$'0BFr$   c                 V    [         R                  " U R                  5      R                  $ r   )r7   statrj   st_sizerX   s    r"   rY   FileSystemPathPointer.file_sizeH  s    wwtzz"***r$   c                 l    [         R                  R                  U R                  U5      n[	        U5      $ r   )r7   r8   r;   rj   rf   )rS   r\   rj   s      r"   r;   FileSystemPathPointer.joinK  s%    TZZ0$U++r$   c                      SU R                   -  $ )NzFileSystemPathPointer(%r)ro   rX   s    r"   __repr__FileSystemPathPointer.__repr__O  s    *TZZ77r$   c                     U R                   $ r   ro   rX   s    r"   __str__FileSystemPathPointer.__str__R  s    zzr$   ro   r   )r^   r_   r`   ra   rb   rl   propertyr8   rT   rY   r;   r   r   rc   rR   r$   r"   rf   rf   (  s9    

  +,8r$   rf   z3Use gzip.GzipFile instead as it also uses a buffer.c                   8   ^  \ rS rSrSr SS jrU 4S jrSrU =r$ )BufferedGzipFileiV  zA ``GzipFile`` subclass for compatibility with older nltk releases.

Use ``GzipFile`` directly as it also buffers in all supported
Python versions.
c                 4    [         R                  " XX#U5        g)z#Return a buffered gzip file object.N)r   rl   )rS   r   r   r   r   kwargss         r"   rl   BufferedGzipFile.__init__^  s     	$$wGr$   c                 $   > [         TU ]  U5        g r   )superwrite)rS   data	__class__s     r"   r   BufferedGzipFile.writed  s     	dr$   rR   )NN	   N)	r^   r_   r`   ra   rb   rl   r   rc   __classcell__)r   s   @r"   r   r   V  s     BFH r$   r   c                   "    \ rS rSrSrSS jrSrg)GzipFileSystemPathPointerij  z
A subclass of ``FileSystemPathPointer`` that identifies a gzip-compressed
file located at a given absolute path.  ``GzipFileSystemPathPointer`` is
appropriate for loading large gzip-compressed pickle objects efficiently.
Nc                 V    [        U R                  S5      nU(       a  [        X!5      nU$ rr   )r   rj   rt   ru   s      r"   rT   GzipFileSystemPathPointer.openq  s$    $**d+0BFr$   rR   r   )r^   r_   r`   ra   rb   rT   rc   rR   r$   r"   r   r   j  s    r$   r   c                   d    \ rS rSrSrSS jr\S 5       r\S 5       rSS jr	S r
S	 rS
 rS rSrg)ZipFilePathPointerix  zr
A path pointer that identifies a file contained within a zipfile,
which can be accessed by reading that zipfile.
c                     [        U[        5      (       a(  [        [        R                  R                  U5      5      nU(       a/  [        USS5      R                  S5      n UR                  " U5        Xl        X l        g! [         a  nUR                  S5      (       aI  UR                  " 5        Vs/ s H  oDR                  U5      (       d  M  UPM     Os  snf sn(       a   SnANv[        SUR                  < SU< 35      UeSnAff = f)z
Create a new path pointer pointing at the specified entry
in the given zipfile.

:raise IOError: If the given zipfile does not exist, or if it
does not contain the specified entry.
Tr*   zZipfile z does not contain N)
isinstancestrOpenOnDemandZipFiler7   r8   rH   r:   r-   getinfo	ExceptionrB   namelistr,   ri   r   _zipfile_entry)rS   zipfileentryens        r"   rl   ZipFilePathPointer.__init__~  s     gs##)"''//'*BCG +E4=DDSIE&    
 >>#&&&//1,1!\\%5HA1, ,  ""7#3#3"66H	Rs0   "B 
D)D4CCD*DDc                     U R                   $ )zn
The zipfile.ZipFile object used to access the zip file
containing the entry identified by this path pointer.
)r   rX   s    r"   r   ZipFilePathPointer.zipfile  s     }}r$   c                     U R                   $ )zG
The name of the file within zipfile that this path
pointer points to.
)r   rX   s    r"   r   ZipFilePathPointer.entry  s     {{r$   Nc                     U R                   R                  U R                  5      n[        U5      nU R                  R	                  S5      (       a  [        U R                  US9nU$ Ub  [        X15      nU$ )N.gz)r   )r   readr   r   rB   r   rt   )rS   r   r   rv   s       r"   rT   ZipFilePathPointer.open  sf    }}!!$++.;;&&dkk6:F  !0BFr$   c                 `    U R                   R                  U R                  5      R                  $ r   )r   r   r   rY   rX   s    r"   rY   ZipFilePathPointer.file_size  s!    }}$$T[[1;;;r$   c                 P    U R                    SU 3n[        U R                  U5      $ )Nr*   )r   r   r   )rS   r\   r   s      r"   r;   ZipFilePathPointer.join  s'    ;;-q)!$--77r$   c                 T    SU R                   R                  < SU R                  < S3$ )NzZipFilePathPointer(z, ))r   r   r   rX   s    r"   r   ZipFilePathPointer.__repr__  s&    $T]]%;%;$>bqQQr$   c                     [         R                  R                  [         R                  R                  U R                  R
                  U R                  5      5      $ r   )r7   r8   rF   r;   r   r   r   rX   s    r"   r   ZipFilePathPointer.__str__  s4    wwT]]-C-CT[[ QRRr$   )r   r   )r   r   )r^   r_   r`   ra   rb   rl   r   r   r   rT   rY   r;   r   r   rc   rR   r$   r"   r   r   x  sP    
!F    <8RSr$   r   c                    [        U S5      n Uc  [        n[        R                  " SU 5      nUR	                  5       u  p4U GH^  nU(       aH  [
        R                  R                  U5      (       a$  UR                  S5      (       a   [        XP5      s  $ U(       a&  [
        R                  R                  U5      (       d  M  Uc  [
        R                  R                  U[        U 5      5      n[
        R                  R                  U5      (       a0  UR                  S5      (       a  [        U5      s  $ [        U5      s  $ GM  [
        R                  R                  U[        U5      5      n[
        R                  R                  U5      (       d  GMS   [        Xd5      s  $    UcZ  U R!                  S5      n[#        [%        U5      5       H1  nSR                  USU Xx   S-   /-   XxS -   5      n	 ['        X5      s  $    U R!                  S5      S   n
U
R                  S5      (       a  U
R+                  S5      S	   n
[-        S
5      R/                  U
S9n[1        U5      nUS-  nUSR/                  U S9-  nUSSR                  S U 5       5      -   -  nSnSU SU SU S3n[)        U5      e! [         a     GM}  f = f! [         a     GM  f = f! [(         a     GM  f = f)a  
Find the given resource by searching through the directories and
zip files in paths, where a None or empty string specifies an absolute path.
Returns a corresponding path name.  If the given resource is not
found, raise a ``LookupError``, whose message gives a pointer to
the installation instructions for the NLTK downloader.

Zip File Handling:

  - If ``resource_name`` contains a component with a ``.zip``
    extension, then it is assumed to be a zipfile; and the
    remaining path components are used to look inside the zipfile.

  - If any element of ``nltk.data.path`` has a ``.zip`` extension,
    then it is assumed to be a zipfile.

  - If a given resource name that does not contain any zipfile
    component is not found initially, then ``find()`` will make a
    second attempt to find that resource, by replacing each
    component *p* in the path with *p.zip/p*.  For example, this
    allows ``find()`` to map the resource name
    ``corpora/chat80/cities.pl`` to a zip file path pointer to
    ``corpora/chat80.zip/chat80/cities.pl``.

  - When using ``find()`` to locate a directory contained in a
    zipfile, the resource name must end with the forward slash
    character.  Otherwise, ``find()`` will not locate the
    directory.

:type resource_name: str or unicode
:param resource_name: The name of the resource to search for.
    Resource names are posix-style relative path names, such as
    ``corpora/brown``.  Directory names will be
    automatically converted to a platform-appropriate path separator.
:rtype: str
TNz(.*\.zip)/?(.*)$|z.zipr   r*   r'   .r   zResource [93m{resource}[0m not found.
Please use the NLTK Downloader to obtain the resource:

[31m>>> import nltk
>>> nltk.download('{resource}')
[0m)resourcez<
  For more information see: https://www.nltk.org/data.html
z.
  Attempted to load [93m{resource_name}[0m
)rJ   z
  Searched in:r   c              3   ,   #    U  H
  nS U-  v   M     g7f)z	
    - %rNrR   ).0ds     r"   	<genexpr>find.<locals>.<genexpr>@  s     'H%Qq(8%s   zF**********************************************************************
)r:   r8   r.   matchgroupsr7   isfilerB   r   ri   isdirr;   r	   rh   r   rf   r+   rangelenfindLookupError
rpartitionr   formattextwrap_indent)rJ   pathsmr   zipentryr3   ppiecesimodified_nameresource_zipnamemsgrC   resource_not_founds                 r"   r   r     s   J ,M4@M } 	%}5A
G bggnnU++v0F0F)%?? "''--..GGLL](CD77>>!$$zz%((8;;4Q77	 % GGLLW(=>77>>!$$!1!>>- < $$S)s6{#AHHVBQZ69v3E2F%FPR%STMM11 $ %**3/2  ((+66s;A>
	 f&f'  #
CKKCBII# J  C 'H%'H HHHC
CcU"SEC53
(
))u  $ # ! !  s6   
J0
K2
K0
J?>J?
KK
K#"K#c                 t   [        U 5      n UcQ  U R                  S5      (       a#  [        R                  R	                  U 5      S   nO[
        R                  " SSU 5      n[        R                  R                  U5      (       a-  [        R                  R                  U5      n[        SU-  5      eU(       a  [        SU < SU< 35        [        U 5      n[        US	5       n UR                  S
5      nUR                  U5        U(       d  OM,  SSS5        UR                  5         g! , (       d  f       N= f)a  
Copy the given resource to a local file.  If no filename is
specified, then use the URL's filename.  If there is already a
file named ``filename``, then raise a ``ValueError``.

:type resource_url: str
:param resource_url: A URL specifying where the resource should be
    loaded from.  The default protocol is "nltk:", which searches
    for the file in the the NLTK data package.
Nzfile:z(^\w+:)?.*/r   zFile %r already exists!zRetrieving z, saving to wbi   )r=   r,   r7   r8   r+   r.   r/   rh   rH   r6   print_openrT   r   r   close)r1   r   verboseinfileoutfiless         r"   retriever   F  s     *,7L""7++ww}}\226Hvvnb,?H	ww~~h77??8,2X=>>L+<|DE < F 
h	I&AMM!	  
 LLN 
	s   ".D))
D7z;A serialized python object, stored using the pickle module.z9A serialized python object, stored using the json module.z9A serialized python object, stored using the yaml module.zA context free grammar.zA probabilistic CFG.zA feature CFG.zZA list of first order logic expressions, parsed with nltk.sem.logic.Expression.fromstring.zA list of first order logic expressions, parsed with nltk.sem.logic.LogicParser.  Requires an additional logic_parser parameterz>A semantic valuation, parsed by nltk.sem.Valuation.fromstring.z)The raw (byte string) contents of a file.z-The raw (unicode string) contents of a file. )picklejsonyamlcfgpcfgfcfgfollogicvalrawtextr   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   txtr   c                 L    SSK Jn  U" [        U 5      5      R                  5       $ )z.
Prevents any class or function from loading.
r   )RestrictedUnpickler)nltk.app.wordnet_appr   r   load)stringr   s     r"   restricted_pickle_loadr     s     9wv/4466r$   c                     SSK Jn  U" U 5      $ )z
Return a pickle-free Punkt tokenizer instead of loading a pickle.

>>> import nltk
>>> tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')
>>> print(tokenizer.tokenize("Hello! How are you?"))
['Hello!', 'How are you?']
r   )PunktTokenizer)nltk.tokenizer   )langtoks     r"   switch_punktr     s     4t9r$   c                     SSK Jn  U" U 5      $ )a  
Return a pickle-free Named Entity Chunker instead of loading a pickle.

>>> import nltk
>>> from nltk.corpus import treebank
>>> from pprint import pprint
>>> chunker = nltk.data.load('chunkers/maxent_ne_chunker/PY3/english_ace_multiclass.pickle')
>>> pprint(chunker.parse(treebank.tagged_sents()[2][8:14])) # doctest: +NORMALIZE_WHITESPACE
Tree('S', [('chairman', 'NN'), ('of', 'IN'), Tree('ORGANIZATION', [('Consolidated', 'NNP'), ('Gold', 'NNP'), ('Fields', 'NNP')]), ('PLC', 'NNP')])

r   )
ne_chunker)
nltk.chunkr   )fmtr   s     r"   switch_chunkerr     s     &c?r$   c                      SSK Jn   U " 5       $ )aq  
Return a pickle-free Treebank Pos Tagger instead of loading a pickle.

>>> import nltk
>>> from nltk.tokenize import word_tokenize
>>> tagger = nltk.data.load('taggers/maxent_treebank_pos_tagger/PY3/english.pickle')
>>> print(tagger.tag(word_tokenize("Hello, how are you?")))
[('Hello', 'NNP'), (',', ','), ('how', 'WRB'), ('are', 'VBP'), ('you', 'PRP'), ('?', '.')]

r   maxent_pos_tagger)nltk.classify.maxentr   r   s    r"   switch_t_taggerr    s     7r$   c                 4    SSK Jn  U S:X  a  Sn OSn U" U 5      $ )a  
Return a pickle-free Averaged Perceptron Tagger instead of loading a pickle.

>>> import nltk
>>> from nltk.tokenize import word_tokenize
>>> tagger = nltk.data.load('taggers/averaged_perceptron_tagger/averaged_perceptron_tagger.pickle')
>>> print(tagger.tag(word_tokenize("Hello, how are you?")))
[('Hello', 'NNP'), (',', ','), ('how', 'WRB'), ('are', 'VBP'), ('you', 'PRP'), ('?', '.')]

r   )_get_taggerrurusN)nltk.tagr  )r   r  s     r"   switch_p_taggerr    s#     %t|tr$   c                    [        U 5      n US:X  aG  U R                  S5      nUS   nUS:X  a  US   n[        R                  U5      nUc  [	        SU -  5      eU[
        ;  a  [	        SU S	35      eU(       a1  [        R                  X45      n	U	b  U(       a  [        S
U  S35        U	$ [        U 5      u  pUSS S:X  a  U(       a  [        SU  S35        [        R                  R                  USS 5      S   nUR                  S5      (       a  [        U5      $ UR                  S5      (       a  [        UR                  S5      S   5      $ UR                  S5      (       a
  [        5       $ UR                  S5      (       a  [        UR                  S5      S   5      $ U(       a  [        SU  S35        [!        U 5      nUS:X  a  UR#                  5       n	GOUS:X  a  [%        UR#                  5       5      n	GOUS:X  aX  SSKnSSKJn  UR-                  U5      n	Sn[/        U	5      S:w  a  [1        U	R3                  5       5      nUU;  a  [	        S5      eGOOUS:X  a  SSKnUR7                  U5      n	GO2UR#                  5       nUb  UR9                  U5      nO UR9                  S5      nUS:X  a  Un	OUS :X  a  [<        R>                  RA                  UUS!9n	OUS":X  a  [<        RB                  RA                  UUS!9n	OUS#:X  a!  [<        RD                  RA                  UUUUS$9n	OUS%:X  a3  [F        RH                  " U[F        RJ                  RM                  5       US&9n	OHUS':X  a  [F        RH                  " UXFS&9n	O,US(:X  a  [F        RN                  " UUS!9n	O[Q        S)U< S*35      eURS                  5         U(       a   U	[        X4'   U	$ U	$ ! [:         a    UR9                  S5      n GN?f = f! [T         a     U	$ f = f)+a7  
Load a given resource from the NLTK data package.  The following
resource formats are currently supported:

  - ``pickle``
  - ``json``
  - ``yaml``
  - ``cfg`` (context free grammars)
  - ``pcfg`` (probabilistic CFGs)
  - ``fcfg`` (feature-based CFGs)
  - ``fol`` (formulas of First Order Logic)
  - ``logic`` (Logical formulas to be parsed by the given logic_parser)
  - ``val`` (valuation of First Order Logic model)
  - ``text`` (the file contents as a unicode string)
  - ``raw`` (the raw file contents as a byte string)

If no format is specified, ``load()`` will attempt to determine a
format based on the resource name's file extension.  If that
fails, ``load()`` will raise a ``ValueError`` exception.

For all text formats (everything except ``pickle``, ``json``, ``yaml`` and ``raw``),
it tries to decode the raw contents using UTF-8, and if that doesn't
work, it tries with ISO-8859-1 (Latin-1), unless the ``encoding``
is specified.

:type resource_url: str
:param resource_url: A URL specifying where the resource should be
    loaded from.  The default protocol is "nltk:", which searches
    for the file in the the NLTK data package.
:type cache: bool
:param cache: If true, add this resource to a cache.  If load()
    finds a resource in its cache, then it will return it from the
    cache rather than loading it.
:type verbose: bool
:param verbose: If true, print a message when loading a resource.
    Messages are not displayed when a resource is retrieved from
    the cache.
:type logic_parser: LogicParser
:param logic_parser: The parser that will be used to parse logical
    expressions.
:type fstruct_reader: FeatStructReader
:param fstruct_reader: The parser that will be used to parse the
    feature structure of an fcfg.
:type encoding: str
:param encoding: the encoding of the input; only used for text formats.
autor   r   gzNzzCould not determine format for %s based on its file
extension; use the "format" argument to specify the format explicitly.zUnknown format type: !z<<Using cached copy of z>>iz.picklez%<<Loading pickle-free alternative to ztokenizers/punktzchunkers/maxent_ne_chunker_z"taggers/maxent_treebank_pos_taggerz"taggers/averaged_perceptron_taggerz
<<Loading r   r   r   r   )	json_tagsr'   zUnknown json tag.r   utf-8zlatin-1r   r   )r   r   r   )logic_parserfstruct_readerr   r   )r  r   r   r   zInternal NLTK error: Format z" isn't handled by nltk.data.load())+r=   r+   AUTO_FORMATSgetr6   FORMATS_resource_cacher   r4   r7   r8   r,   r   r   r  r  r   r   r   r   nltk.jsontagsr  r   r   nextkeysr   	safe_loaddecodeUnicodeDecodeErrorr   CFG
fromstringPCFGFeatureGrammarr   
read_logicr   LogicParserread_valuationAssertionErrorr   	TypeError)r1   r   cacher   r  r  r   resource_url_partsextresource_valr2   r3   filopened_resourcer   r  tagr   binary_datastring_datas                       r"   r   r     s   n *,7L )//4 $$;$R(C!!#&>=?KL  W0:;; &**L+AB#/~R@A(6OHRSzY9,rJKggmmE#2J'+.//$$:;;!#))C."455BCC"$$BCC"399S>"#566 
<.+, L)O&++-	8	-o.B.B.DE	6	+yy1|!|((*+Ci011  	6	~~o6 &**,%,,X6K<)009 V&Lu_";;11+1QLv"<<22;2RLv"11<<)-!	 = L u_>> YY224!L
 w>>,L u_--kHML 17: 
  	6BO\23 <] & <)00;<R  	 	s$   O 
O1 O.-O.1
O?>O?c                     [        U 5      n [        U SSS9nUR                  5       nU HD  nUR                  U5      (       a  M  [        R
                  " SU5      (       a  M9  [        U5        MF     g)a]  
Write out a grammar file, ignoring escaped and empty lines.

:type resource_url: str
:param resource_url: A URL specifying where the resource should be
    loaded from.  The default protocol is "nltk:", which searches
    for the file in the the NLTK data package.
:type escape: str
:param escape: Prepended string that signals lines to be ignored
r   F)r   r%  z^$N)r=   r   
splitlinesr,   r.   r   r   )r1   escaper(  linesls        r"   show_cfgr3    sa     *,7LV5AL##%E<<88D!a r$   c                  ,    [         R                  5         g)z:
Remove all objects from the resource cache.
:see: load()
N)r  clearrR   r$   r"   clear_cacher6    s    
 r$   c                    [        U 5      n [        U 5      u  pUb  UR                  5       S:X  a"  [        U[        S/-   5      R                  5       $ UR                  5       S:X  a  [        US/5      R                  5       $ [        U 5      $ )aC  
Helper function that returns an open file object for a resource,
given its resource URL.  If the given resource URL uses the "nltk:"
protocol, or uses no protocol, then use ``nltk.data.find`` to find
its path, and open it with the given mode; if the resource URL
uses the 'file' protocol, then open the file with the given mode;
otherwise, delegate to ``urllib2.urlopen``.

:type resource_url: str
:param resource_url: A URL specifying where the resource should be
    loaded from.  The default protocol is "nltk:", which searches
    for the file in the the NLTK data package.
r(   r   r)   )r=   r4   lowerr   r8   rT   r
   r0   s      r"   r   r     s|     *,7L(6OH8>>+v5E42$;',,..		V	#EB4 %%''|$$r$   c                   ,    \ rS rSrS rS rS rS rSrg)
LazyLoaderi  c                     Xl         g r   ro   rk   s     r"   rl   LazyLoader.__init__  s    
r$   c                 r    [        U R                  5      nUR                  U l        UR                  U l        g r   )r   rj   __dict__r   )rS   r   s     r"   __loadLazyLoader.__load  s,    

# !))!++r$   c                 8    U R                  5         [        X5      $ r   )_LazyLoader__loadgetattr)rS   attrs     r"   __getattr__LazyLoader.__getattr__  s     t""r$   c                 8    U R                  5         [        U 5      $ r   )rB  reprrX   s    r"   r   LazyLoader.__repr__  s     Dzr$   )r   r>  rj   N)	r^   r_   r`   ra   rl   rB  rE  r   rc   rR   r$   r"   r:  r:    s    ,#r$   r:  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
r   i  a  
A subclass of ``zipfile.ZipFile`` that closes its file pointer
whenever it is not using it; and re-opens it when it needs to read
data from the zipfile.  This is useful for reducing the number of
open file handles when many zip files are being accessed at once.
``OpenOnDemandZipFile`` must be constructed from a filename, not a
file-like object (to allow re-opening).  ``OpenOnDemandZipFile`` is
read-only (i.e. ``write()`` and ``writestr()`` are disabled.
c                     [        U[        5      (       d  [        S5      e[        R                  R                  X5        U R                  U:X  d   eU R                  5         SU l        g )Nz+ReopenableZipFile filename must be a stringr   )	r   r   r$  r   ZipFilerl   r   r   _fileRefCnt)rS   r   s     r"   rl   OpenOnDemandZipFile.__init__  sR    (C((IJJ  0}}(((

 r$   c                     U R                   b   e[        U R                  S5      U l         [        R                  R                  X5      nU =R                  S-  sl        U R                  5         U$ )Nrs   r'   )fprT   r   r   rL  r   rM  r   )rS   r<   values      r"   r   OpenOnDemandZipFile.read  sW    wwt}}d+$$T0 	A

r$   c                     [        S5      ez<:raise NotImplementedError: OpenOnDemandZipfile is read-onlyz OpenOnDemandZipfile is read-onlyNotImplementedErrorrS   argsr   s      r"   r   OpenOnDemandZipFile.write      !"DEEr$   c                     [        S5      erT  rU  rW  s      r"   writestrOpenOnDemandZipFile.writestr  rZ  r$   c                 2    [        SU R                  -  5      $ )NzOpenOnDemandZipFile(%r))rH  r   rX   s    r"   r   OpenOnDemandZipFile.__repr__  s    -=>>r$   )rM  rP  N)r^   r_   r`   ra   rb   rl   r   r   r\  r   rc   rR   r$   r"   r   r     s"    FF?r$   r   c                      \ rS rSrSrSrS"S jrS#S jrS rS#S jr	S$S	 jr
S
 rS rS rS rS rS rS r\S 5       r\S 5       r\S 5       rS rS%S jrS rS#S jrS rS#S jrS r\R<                  S4/\R>                  S4\R@                  S4/\R>                  S4/\R@                  S4/\RB                  S4\RD                  S4/\RB                  S4/\RD                  S4/S.r#S  r$S!r%g)&rt   i  aY  
A stream reader that automatically encodes the source byte stream
into unicode (like ``codecs.StreamReader``); but still supports the
``seek()`` and ``tell()`` operations correctly.  This is in contrast
to ``codecs.StreamReader``, which provide *broken* ``seek()`` and
``tell()`` methods.

This class was motivated by ``StreamBackedCorpusView``, which
makes extensive use of ``seek()`` and ``tell()``, and needs to be
able to handle unicode-encoded files.

Note: this class requires stateless decoders.  To my knowledge,
this shouldn't cause a problem with any of python's builtin
unicode encodings.
Tc                     UR                  S5        Xl         X l         X0l         [        R
                  " U5      U l         SU l         S U l         SU l	         S U l
         U R                  5       U l        g )Nr   r$   )seekrv   r   r    codecs
getdecoderr  
bytebuffer
linebuffer_rewind_checkpoint_rewind_numchars
_check_bom_bom)rS   rv   r   r    s       r"   rl   $SeekableUnicodeStreamReader.__init__1  s    A$ 	! 	 ''1	 	F 	; #$	@
 !%	M
 OO%		=r$   Nc                     U R                  U5      nU R                  (       a,  SR                  U R                  5      U-   nSU l        SU l        U$ )z
Read up to ``size`` bytes, decode them using this reader's
encoding, and return the resulting unicode string.

:param size: The maximum number of bytes to read.  If not
    specified, then read as many bytes as possible.
:type size: int
:rtype: unicode
r   N)_readrf  r;   rh  )rS   sizecharss      r"   r    SeekableUnicodeStreamReader.readi  sF     

4  ??GGDOO,u4E"DO$(D!r$   c                     U R                   (       aS  [        U R                   5      S:  a:  U R                   R                  S5      nU =R                  [        U5      -  sl        g U R                  R                  5         g )Nr'   r   )rf  r   poprh  rv   readlinerS   lines     r"   discard_line(SeekableUnicodeStreamReader.discard_line}  sR    ??s4??3a7??&&q)D!!SY.!KK  "r$   c                    U R                   (       aT  [        U R                   5      S:  a;  U R                   R                  S5      nU =R                  [        U5      -  sl        U$ U=(       d    SnSnU R                   (       a#  X@R                   R                  5       -  nSU l          U R                  R                  5       [        U R                  5      -
  nU R                  U5      nU(       a)  UR                  S5      (       a  X`R                  S5      -  nXF-  nUR                  S5      n[        U5      S:  a@  US   nUSS U l         [        U5      [        U5      [        U5      -
  -
  U l        XPl
         U$ [        U5      S:X  a&  US   nUS   R                  S5      S   n	X:w  a  Un U$ U(       a  Ub  Un U$ US	:  a  US
-  nGM'  )a2  
Read a line of text, decode it using this reader's encoding,
and return the resulting unicode string.

:param size: The maximum number of bytes to read.  If no
    newline is encountered before ``size`` bytes have been read,
    then the returned value may not be a complete line of text.
:type size: int
r'   r   H   r   NTFi@     )rf  r   rr  rh  rv   tellre  rm  rB   r/  rg  )
rS   rn  ru  readsizero  startpos	new_charsr1  line0withendline0withoutends
             r"   rs  $SeekableUnicodeStreamReader.readline  s    ??s4??3a7??&&q)D!!SY.!K:2 ??__((**E"DO{{'')C,@@H

8,I Y//55ZZ]*	E$$T*E5zA~Qx"')(+I#e*s4y:P(Q%*2'   Uq$Qx"'("5"5e"<Q"?2'D   0  $A= r$   c                 @    U R                  5       R                  U5      $ )z
Read this file's contents, decode them using this reader's
encoding, and return it as a list of unicode lines.

:rtype: list(unicode)
:param sizehint: Ignored.
:param keepends: If false, then strip newlines.
)r   r/  )rS   sizehintkeependss      r"   	readlines%SeekableUnicodeStreamReader.readlines  s     yy{%%h//r$   c                 @    U R                  5       nU(       a  U$ [        e)z8Return the next decoded line from the underlying stream.)rs  StopIterationrt  s     r"   r   SeekableUnicodeStreamReader.next  s    }}Kr$   c                 "    U R                  5       $ r   )r  rX   s    r"   __next__$SeekableUnicodeStreamReader.__next__  s    yy{r$   c                     U $ zReturn selfrR   rX   s    r"   __iter__$SeekableUnicodeStreamReader.__iter__      r$   c                 H    U R                   (       d  U R                  5         g g r   )closedr   rX   s    r"   __del__#SeekableUnicodeStreamReader.__del__  s    {{JJL r$   c                     U $ r   rR   rX   s    r"   	__enter__%SeekableUnicodeStreamReader.__enter__  s    r$   c                 $    U R                  5         g r   )r   )rS   typerQ  	tracebacks       r"   __exit__$SeekableUnicodeStreamReader.__exit__  s    

r$   c                     U $ r  rR   rX   s    r"   
xreadlines&SeekableUnicodeStreamReader.xreadlines  r  r$   c                 .    U R                   R                  $ )z(True if the underlying stream is closed.)rv   r  rX   s    r"   r  "SeekableUnicodeStreamReader.closed  s     {{!!!r$   c                 .    U R                   R                  $ )z"The name of the underlying stream.)rv   r<   rX   s    r"   r<    SeekableUnicodeStreamReader.name       {{r$   c                 .    U R                   R                  $ )z"The mode of the underlying stream.)rv   r   rX   s    r"   r    SeekableUnicodeStreamReader.mode  r  r$   c                 8    U R                   R                  5         g)z
Close the underlying stream.
N)rv   r   rX   s    r"   r   !SeekableUnicodeStreamReader.close  s     	r$   c                     US:X  a  [        S5      eU R                  R                  X5        SU l        SU l        SU l        U R                  R                  5       U l        g)a  
Move the stream to a new file position.  If the reader is
maintaining any buffers, then they will be cleared.

:param offset: A byte count offset.
:param whence: If 0, then the offset is from the start of the file
    (offset should be positive), if 1, then the offset is from the
    current position (offset may be positive or negative); and if 2,
    then the offset is from the end of the file (offset should
    typically be negative).
r'   zmRelative seek is not supported for SeekableUnicodeStreamReader -- consider using char_seek_forward() instead.Nr$   )r6   rv   rb  rf  re  rh  r|  rg  )rS   offsetwhences      r"   rb   SeekableUnicodeStreamReader.seek  s\     Q;5 
 	( $"&++"2"2"4r$   c                     US:  a  [        S5      eU R                  U R                  5       5        U R                  U5        g)z9
Move the read pointer forward by ``offset`` characters.
r   z"Negative offsets are not supportedN)r6   rb  r|  _char_seek_forward)rS   r  s     r"   char_seek_forward-SeekableUnicodeStreamReader.char_seek_forward  s7     A:ABB		$))+'r$   c                 $   Uc  UnSn U R                   R                  U[        U5      -
  5      nX4-  nU R                  U5      u  pV[        U5      U:X  a*  U R                   R	                  [        U5      * U-   S5        g[        U5      U:  ap  [        U5      U:  a7  X![        U5      -
  -  nU R                  USU 5      u  pV[        U5      U:  a  M7  U R                   R	                  [        U5      * U-   S5        gX![        U5      -
  -  nGM	  )z
Move the file position forward by ``offset`` characters,
ignoring all buffers.

:param est_bytes: A hint, giving an estimate of the number of
    bytes that will be needed to move forward by ``offset`` chars.
    Defaults to ``offset``.
Nr$   r'   )rv   r   r   _incr_decoderb  )rS   r  	est_bytesbytesnewbytesro  bytes_decodeds          r"   r  .SeekableUnicodeStreamReader._char_seek_forward)  s    I{{''	CJ(>?HE $(#4#4U#; E 5zV#  #e*}!<a@ 5zF"%j6)#e*!44I+/+<+<U:I=N+O(E %j6)   #e*}!<a@ #e*,,I3 r$   c                    U R                   c0  U R                  R                  5       [        U R                  5      -
  $ U R                  R                  5       nU[        U R                  5      -
  U R
                  -
  n[        S U R                    5       5      n[        X R                  -  U R                  U-   -  5      nU R                  R                  U R
                  5        U R                  U R                  U5        U R                  R                  5       nU R                  (       a  U R                  R                  U5        U R                  U R                  R                  S5      5      S   nSR                  U R                   5      nUR                  U5      (       d  UR                  U5      (       d   eU R                  R                  U5        U$ )z
Return the current file position on the underlying byte
stream.  If this reader is maintaining any buffers, then the
returned file position will be the position of the beginning
of those buffers.
c              3   8   #    U  H  n[        U5      v   M     g 7fr   )r   )r   ru  s     r"   r   3SeekableUnicodeStreamReader.tell.<locals>.<genexpr>d  s     =_Ts4yy_s   2   r   r   )rf  rv   r|  r   re  rg  sumintrh  rb  r  DEBUGr  r   r;   r,   )rS   orig_filepos
bytes_readbuf_sizer  fileposcheck1check2s           r"   r|   SeekableUnicodeStreamReader.tellQ  sr    ??";;##%DOO(<<< {{'') #S%99T=T=TT
=T__==...$2G2G(2RS
	 	001 5 5yA++""$ ::KKW%&&t{{'7'7';<Q?FWWT__-F$$V,,0A0A&0I0III 	& r$   c                 J   US:X  a  gU R                   (       aC  U R                  R                  5       S:X  a%  U R                  R                  U R                   5        Uc  U R                  R                  5       nOU R                  R                  U5      nU R                  U-   nU R                  U5      u  pEUb`  U(       dY  [        U5      S:  aJ  U(       dC  U R                  R                  S5      nU(       d  O X2-  nU R                  U5      u  pEU(       d  MC  X5S U l        U$ )z
Read up to ``size`` bytes from the underlying stream, decode
them using this reader's encoding, and return the resulting
unicode string.  ``linebuffer`` is not included in the result.
r   r   Nr'   )rj  rv   r|  r   re  r  r   )rS   rn  	new_bytesr  ro  r  s         r"   rm  !SeekableUnicodeStreamReader._read  s     19 99))+q0KKTYY' <((*I((.I)+  $007 u3y>A3E KK,,Q/	 "'+'8'8'?$ e  / r$   c                 >     U R                  US5      $ ! [         a}  nUR                  [        U5      :X  a.  U R                  USUR                   U R
                  5      s SnA$ U R
                  S:X  a  e U R                  XR
                  5      s SnA$ SnAff = f)a  
Decode the given byte string into a unicode string, using this
reader's encoding.  If an exception is encountered that
appears to be caused by a truncation error, then just decode
the byte string without the bytes that cause the trunctaion
error.

Return a tuple ``(chars, num_consumed)``, where ``chars`` is
the decoded unicode string, and ``num_consumed`` is the
number of bytes that were consumed.
strictN)r  r  endr   startr    )rS   r  excs      r"   r  (SeekableUnicodeStreamReader._incr_decode  s     ;{{5(33% ; 77c%j(;;u[syy'94;;GG [[H,
  ;;ukk::;s'    
BAB B&+BBBzutf16-lezutf16-bezutf32-lezutf32-be)utf8utf16utf16leutf16beutf32utf32leutf32bec                    [         R                  " SSU R                  R                  5       5      nU R                  R                  U5      nU(       aq  U R                  R                  S5      nU R                  R                  S5        U H5  u  pEUR                  U5      (       d  M  U(       a  XPl        [        U5      s  $    g )Nz[ -]r      r   )r.   r/   r   r8  
_BOM_TABLEr  rv   r   rb  r,   r   )rS   encbom_infor  bomnew_encodings         r"   ri  &SeekableUnicodeStreamReader._check_bom  s    ffVR!4!4!67 ??&&s+KK$$R(EKKQ &.!##C((#(4s8O	 &. r$   )	rj  rg  rh  re  r  r   r    rf  rv   )r  r   NT)r   )&r^   r_   r`   ra   rb   r  rl   r   rv  rs  r  r  r  r  r  r  r  r  r   r  r<   r   r   rb  r  r  r|  rm  r  rc  BOM_UTF8BOM_UTF16_LEBOM_UTF16_BEBOM_UTF32_LEBOM_UTF32_BEr  ri  rc   rR   r$   r"   rt   rt     sK     E2=p(#:x	0 
 " "        50	(&-P(\$L;> //4()&&
3f6I6I:5VW(($/0(($/0&&
3f6I6I:5VW(($/0(($/0Jr$   rt   )r8   rO   rf   r   r   r   r   r   r  r  r   r3  r6  r:  r   r   rt   )rs   r   r  NNN)TNr   r  )english)
multiclass)r	  TFNNN)z##)Lrb   rc  	functoolsr7   r   r.   rD   textwrapr   abcr   r   gzipr   GZ_WRITEr   ior   r   urllib.requestr	   r
   zlibr   FLUSHImportErrorr   r(   r   r   nltk.internalsr   partialindentr   r8   environr  r+   pathsep_paths_from_env
expanduserappendrE   r,   r;   r   r#   r4   r=   r:   rO   r   rf   r   r   r   r  r   r   r  r  r   r   r   r  r  r   r3  r6  r   r:  rL  r   rt   __all__)r   s   0r"   <module>r     sb  4   	  	 
   ' "  % 0'*  %##HOODA 
9 **..b177

C O)OqqO) )bjj(RWW-?-?-E-MKK""=12<<5!!
SZZ-
SZZ+6
SZZ4
RZZ^^Iv6D D 	
SZZ-
SZZ+6
SZZ4$" D$ 
=65%p-j&G &R+K +\ ABx  C& 5 MS MSl (p*f#T LGG$", L6;* 7" , 
qh,%> >(?'// (?`B BJa-  '&&'* 	*s   M 4
MMMM