
    g                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZ ddlmZ ddlmZ ddlmZmZ ddlmZmZ 	 ddlmZ dd
lmZmZ ddlmZ  ej@                  ejB                  d      Z"g Z#	 ejH                  jK                  dd      jM                  ejN                        Z(e#e(D  cg c]  } | s| 	 c} z  Z#dejH                  vrHejF                  jS                  d      dk7  r*e#jU                  ejF                  jS                  d             ejV                  jY                  d      re#ejF                  j[                  ej\                  d      ejF                  j[                  ej\                  dd      ejF                  j[                  ej\                  dd      ejF                  j[                  ejH                  jK                  dd      d      dddgz  Z#nze#ejF                  j[                  ej\                  d      ejF                  j[                  ej\                  dd      ejF                  j[                  ej\                  dd      ddddgz  Z#	 	 	 	 	 	 dYd Z/d! Z0d" Z1dZd#Z2 G d$ d%e
&      Z3 G d' d(e3e4      Z5 ed)       G d* d+e             Z6 G d, d-e5      Z7 G d. d/e3      Z8i Z9	 d[d0Z:d\d1Z;d2d3d4d5d6d7d8d9d:d;d<d=Z<d>d?d@dAdBdCdDdEdFdGdGdHZ=dI Z>d]dJZ?d^dKZ@dL ZAdM ZB	 	 	 	 	 	 d_dNZCd`dOZDdP ZEdQ ZF G dR dS      ZG G dT dUej                        ZI G dV dW      ZJg dXZKy# e$ r
 dd	lmZ Y w xY wc c} w )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                 >    |t        | |||      }t        ||||      S N)r   r   )filenamemodecompresslevelencodingfileobjerrorsnewlines          >/var/www/openai/venv/lib/python3.12/site-packages/nltk/data.pygzip_open_unicoder#   i   s*     8T='B(FG<<    c                     | j                  dd      \  }}|dk(  r	 ||fS |dk(  r)|j                  d      rd|j                  d      z   }||fS t        j                  dd|      }||fS )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0OHe6 U? 
V	C %,,s++E U? z2u-U?r$   c                 0   	 t        |       \  }}|dk(  r/t        j                  j	                  |      rd}t        |dd      }n.|dk(  rd}t        |dd      }n|dk(  rd}t        |d      }n|dz  }d	j                  ||g      S # t        $ r d}| }Y w xY w)
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&tUD9	V	&tUD9	V	&tT2 	E77Hd#$$%  s   B BBc                 6   t        t        j                  d|             xs) | j                  t        j
                  j                        }t        j                  j                  d      r| j                  d      } nt        j                  dd|       } |r t        j
                  j                  |       } nO|t        j                  }t        j
                  j                  t        j
                  j                  ||             } | j!                  dd      j!                  t        j
                  j                  d      } t        j                  j                  d      r$t        j
                  j#                  |       rd| z   } |r| j                  d      s| dz  } | S )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]M(RS!))$4<<RWW[[#NM
||u%"''--*Fm+m,,S1r$   c                   B    e Zd ZdZedd       Zed        Zed        Zy)PathPointeraq  
    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                      y)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"   openzPathPointer.open	      r$   c                      y)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.
        NrQ   rR   s    r"   	file_sizezPathPointer.file_size  rT   r$   c                      y)aP  
        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.
        NrQ   )rR   fileids     r"   r;   zPathPointer.join  rT   r$   r   )__name__
__module____qualname____doc__r   rS   rW   r;   rQ   r$   r"   rO   rO      sC          r$   rO   )	metaclassc                   F    e Zd ZdZd Zed        Zd
dZd Zd Z	d Z
d	 Zy)FileSystemPathPointerzm
    A path pointer that identifies a file which can be accessed
    directly via a given absolute path.
    c                     t         j                  j                  |      }t         j                  j                  |      st	        d|z        || _        y)z
        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rR   rd   s     r"   __init__zFileSystemPathPointer.__init__.  s>     &ww~~e$9EABB
r$   c                     | j                   S )z2The absolute path identified by this path pointer.rd   rV   s    r"   r8   zFileSystemPathPointer.path=  s     zzr$   Nc                 N    t        | j                  d      }|t        ||      }|S Nrb)rS   rd   SeekableUnicodeStreamReaderrR   r   streams      r"   rS   zFileSystemPathPointer.openB  s)    djj$'0BFr$   c                 T    t        j                  | j                        j                  S r   )r7   statrd   st_sizerV   s    r"   rW   zFileSystemPathPointer.file_sizeH  s    wwtzz"***r$   c                 l    t         j                  j                  | j                  |      }t	        |      S r   )r7   r8   r;   rd   r`   )rR   rY   rd   s      r"   r;   zFileSystemPathPointer.joinK  s%    TZZ0$U++r$   c                      d| j                   z  S )NzFileSystemPathPointer(%r)rh   rV   s    r"   __repr__zFileSystemPathPointer.__repr__O  s    *TZZ77r$   c                     | j                   S r   rh   rV   s    r"   __str__zFileSystemPathPointer.__str__R  s    zzr$   r   )rZ   r[   r\   r]   rf   propertyr8   rS   rW   r;   rt   rv   rQ   r$   r"   r`   r`   (  s9    

  +,8r$   r`   z3Use gzip.GzipFile instead as it also uses a buffer.c                   ,     e Zd ZdZ	 ddZ fdZ xZS )BufferedGzipFilezA ``GzipFile`` subclass for compatibility with older nltk releases.

    Use ``GzipFile`` directly as it also buffers in all supported
    Python versions.
    c                 6    t        j                  | ||||       y)z#Return a buffered gzip file object.N)r   rf   )rR   r   r   r   r   kwargss         r"   rf   zBufferedGzipFile.__init__^  s     	$$wGr$   c                 $    t         |   |       y r   )superwrite)rR   data	__class__s     r"   r~   zBufferedGzipFile.writed  s     	dr$   )NN	   N)rZ   r[   r\   r]   rf   r~   __classcell__)r   s   @r"   ry   ry   V  s     BFH r$   ry   c                       e Zd ZdZddZy)GzipFileSystemPathPointerz
    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                 N    t        | j                  d      }|rt        ||      }|S rj   )r   rd   rl   rm   s      r"   rS   zGzipFileSystemPathPointer.openq  s&    $**d+0BFr$   r   )rZ   r[   r\   r]   rS   rQ   r$   r"   r   r   j  s    r$   r   c                   X    e Zd ZdZddZed        Zed        ZddZd Z	d Z
d	 Zd
 Zy)ZipFilePathPointerz~
    A path pointer that identifies a file contained within a zipfile,
    which can be accessed by reading that zipfile.
    c                    t        |t              r(t        t        j                  j                  |            }|r/t        |dd      j                  d      }	  |j                  |       || _        || _        y# t        $ ro}|j                  d      r8 |j                         D cg c]  }|j                  |      s| nc c}w c}rnt        d|j                  d|      |Y d}~d}~ww xY w)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,   rc   r   _zipfile_entry)rR   zipfileentryens        r"   rf   zZipFilePathPointer.__init__~  s     gs#)"''//'*BCG +E4=DDSIE&    
 >>#&/w//1,1!Q\\%5HA1,  ""7#3#3"66H	R s*   A9 9	C1$C,&C=C&C,,C1c                     | j                   S )z
        The zipfile.ZipFile object used to access the zip file
        containing the entry identified by this path pointer.
        )r   rV   s    r"   r   zZipFilePathPointer.zipfile  s     }}r$   c                     | j                   S )z_
        The name of the file within zipfile that this path
        pointer points to.
        )r   rV   s    r"   r   zZipFilePathPointer.entry  s     {{r$   Nc                     | j                   j                  | j                        }t        |      }| j                  j	                  d      rt        | j                  |      }|S |t        ||      }|S )N.gz)r   )r   readr   r   rB   r   rl   )rR   r   r   rn   s       r"   rS   zZipFilePathPointer.open  se    }}!!$++.;;&dkk6:F  !0BFr$   c                 `    | j                   j                  | j                        j                  S r   )r   r   r   rW   rV   s    r"   rW   zZipFilePathPointer.file_size  s!    }}$$T[[1;;;r$   c                 P    | j                    d| }t        | j                  |      S )Nr*   )r   r   r   )rR   rY   r   s      r"   r;   zZipFilePathPointer.join  s'    ;;-q)!$--77r$   c                 P    d| j                   j                  d| j                  dS )NzZipFilePathPointer(z, ))r   r   r   rV   s    r"   rt   zZipFilePathPointer.__repr__  s&    $T]]%;%;$>bqQQr$   c                     t         j                  j                  t         j                  j                  | j                  j
                  | j                              S r   )r7   r8   rF   r;   r   r   r   rV   s    r"   rv   zZipFilePathPointer.__str__  s4    wwT]]-C-CT[[ QRRr$   )r   r   )rZ   r[   r\   r]   rf   rw   r   r   rS   rW   r;   rt   rv   rQ   r$   r"   r   r   x  sP    
!F    <8RSr$   r   c                 j   t        | d      } |t        }t        j                  d|       }|j	                         \  }}|D ]3  }|r?t
        j                  j                  |      r |j                  d      r	 t        ||       c S |r t
        j                  j                  |      sg|tt
        j                  j                  |t        |             }t
        j                  j                  |      s|j                  d      rt        |      c S t        |      c S t
        j                  j                  |t        |            }t
        j                  j                  |      s'	 t        ||      c S  |\| j!                  d      }t#        t%        |            D ]4  }dj                  |d| ||   dz   gz   ||d z         }		 t'        |	|      c S  | j!                  d      d   }
|
j                  d      r|
j+                  d      d	   }
t-        d
      j/                  |
      }t1        |      }|dz  }|dj/                  |       z  }|ddj                  d |D              z   z  }d}d| d| d| d}t)        |      # t        $ r Y Qw xY w# t        $ r Y aw xY w# t(        $ r Y w xY w)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   &   K   | ]	  }d |z    yw)z	
    - %rNrQ   ).0ds     r"   	<genexpr>zfind.<locals>.<genexpr>@  s     'H%Qq(8%s   zF**********************************************************************
)r:   r8   r.   matchgroupsr7   isfilerB   r   rc   isdirr;   r	   rb   r   r`   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
GX bggnnU+v0F)%?? "''--.GGLL](CD77>>!$zz%(8;;4Q77GGLLW(=>77>>!$!1!X>>- < $$S)s6{#AHHVBQZ6!9v3E2F%FPQPR%STMM5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   7J(JJ%	JJ	J"!J"%	J21J2c                 :   t        |       } |K| j                  d      r#t        j                  j	                  |       d   }nt        j                  dd|       }t        j                  j                  |      r-t        j                  j                  |      }t        d|z        |rt        d| d|       t        |       }t        |d	      5 }	 |j                  d
      }|j                  |       |sn&	 ddd       |j                          y# 1 sw Y   xY w)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/   rb   rH   r6   print_openrS   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D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    ddl m}  |t        |             j                         S )z6
    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                     ddl m}  ||       S )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                     ddl m}  ||       S )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                      ddl m}   |        S )a  
    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                 2    ddl m} | dk(  rd} nd}  ||       S )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                    t        |       } |dk(  rE| j                  d      }|d   }|dk(  r|d   }t        j                  |      }|t	        d| z        |t
        vrt	        d| d	      |r,t        j                  | |f      }	|	|rt        d
|  d       |	S t        |       \  }
}|dd dk(  r|rt        d|  d       t        j                  j                  |dd       d   }|j                  d      rt        |      S |j                  d      rt        |j                  d      d         S |j                  d      r
t               S |j                  d      rt        |j                  d      d         S |rt        d|  d       t!        |       }|dk(  r|j#                         }	n|dk(  rt%        |j#                               }	n|dk(  rTddl}ddlm} |j-                  |      }	d}t/        |	      dk7  rt1        |	j3                               }||vr`t	        d      |dk(  rddl}|j7                  |      }	n9|j#                         }||j9                  |      }n	 |j9                  d      }|dk(  r|}	n|d k(  r"t<        j>                  jA                  ||!      }	n|d"k(  r"t<        jB                  jA                  ||!      }	n|d#k(  r$t<        jD                  jA                  ||||$      }	n|d%k(  r5tG        jH                  |tF        jJ                  jM                         |&      }	nJ|d'k(  rtG        jH                  |||&      }	n,|d(k(  rtG        jN                  ||!      }	ntQ        d)|d*      |jS                          |r	 |	t        | |f<   |	S |	S # t:        $ r |j9                  d      }Y Bw xY w# tT        $ r Y |	S w xY w)+a  
    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(6OHeRSzY9,rJKggmmE#2J'+./$$:;!#))C."455BC"$$B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\623 <] & <)00;<R  	 	s$   'N N> N;:N;>	O
Oc                     t        |       } t        | dd      }|j                         }|D ]6  }|j                  |      rt	        j
                  d|      r,t        |       8 y)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_cfgr    s[     *,7LV5AL##%E<<88D!a r$   c                  ,    t         j                          y)zF
    Remove all objects from the resource cache.
    :see: load()
    N)r   clearrQ   r$   r"   clear_cacher    s    
 r$   c                    t        |       } t        |       \  }}||j                         dk(  r"t        |t        dgz         j                         S |j                         dk(  rt        |dg      j                         S t        |       S )ao  
    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   rS   r
   r0   s      r"   r   r     s~     *,7L(6OHe8>>+v5E42$;',,..		V	#EB4 %%''|$$r$   c                   $    e Zd Zd Zd Zd Zd Zy)
LazyLoaderc                     || _         y r   rh   re   s     r"   rf   zLazyLoader.__init__  s	    
r$   c                 r    t        | j                        }|j                  | _        |j                  | _        y r   )r   rd   __dict__r   )rR   r   s     r"   __loadzLazyLoader.__load  s,    

# !))!++r$   c                 :    | j                          t        | |      S r   )_LazyLoader__loadgetattr)rR   attrs     r"   __getattr__zLazyLoader.__getattr__  s     tT""r$   c                 8    | j                          t        |       S r   )r'  reprrV   s    r"   rt   zLazyLoader.__repr__  s     Dzr$   N)rZ   r[   r\   rf   r'  r*  rt   rQ   r$   r"   r!  r!    s    ,#r$   r!  c                   .    e Zd ZdZd Zd Zd Zd Zd Zy)r   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                     t        |t              st        d      t        j                  j                  | |       | j                  |k(  sJ | j                          d| _        y )Nz+ReopenableZipFile filename must be a stringr   )	r   r   r  r   ZipFilerf   r   r   _fileRefCnt)rR   r   s     r"   rf   zOpenOnDemandZipFile.__init__  sQ    (C(IJJ  x0}}(((

 r$   c                     | j                   J t        | j                  d      | _         t        j                  j                  | |      }| xj                  dz  c_        | j                          |S )Nrk   r'   )fprS   r   r   r/  r   r0  r   )rR   r<   values      r"   r   zOpenOnDemandZipFile.read  sY    wwt}}d+$$T40 	A

r$   c                     t        d      z<:raise NotImplementedError: OpenOnDemandZipfile is read-onlyz OpenOnDemandZipfile is read-onlyNotImplementedErrorrR   argsr{   s      r"   r~   zOpenOnDemandZipFile.write      !"DEEr$   c                     t        d      r5  r6  r8  s      r"   writestrzOpenOnDemandZipFile.writestr  r:  r$   c                 2    t        d| j                  z        S )NzOpenOnDemandZipFile(%r))r,  r   rV   s    r"   rt   zOpenOnDemandZipFile.__repr__  s    -=>>r$   N)	rZ   r[   r\   r]   rf   r   r~   r<  rt   rQ   r$   r"   r   r     s"    FF?r$   r   c                      e Zd ZdZdZd dZd!dZd Zd!dZd"dZ	d	 Z
d
 Zd Zd Zd Zd Zd Zed        Zed        Zed        Zd Zd#dZd Zd!dZd Zd!dZd Zej:                  dfgej<                  dfej>                  dfgej<                  dfgej>                  dfgej@                  dfejB                  dfgej@                  dfgejB                  dfgdZ"d Z#y)$rl   a  
    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                     |j                  d       || _        	 || _        	 || _        	 t	        j
                  |      | _        	 d| _        	 d | _        	 d| _	        	 d | _
        	 | j                         | _        y )Nr   r$   )seekrn   r   r    codecs
getdecoderr  
bytebuffer
linebuffer_rewind_checkpoint_rewind_numchars
_check_bom_bom)rR   rn   r   r    s       r"   rf   z$SeekableUnicodeStreamReader.__init__1  s    A$ 	! 	 ''1	 	F 	; #$	@
 !%	M
 OO%		=r$   Nc                     | j                  |      }| j                  r,dj                  | j                        |z   }d| _        d| _        |S )a6  
        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)_readrD  r;   rF  )rR   sizecharss      r"   r   z SeekableUnicodeStreamReader.readi  sF     

4  ??GGDOO,u4E"DO$(D!r$   c                     | j                   rRt        | j                         dkD  r:| j                   j                  d      }| xj                  t        |      z  c_        y | j                  j                          y )Nr'   r   )rD  r   poprF  rn   readlinerR   lines     r"   discard_linez(SeekableUnicodeStreamReader.discard_line}  sR    ??s4??3a7??&&q)D!!SY.!KK  "r$   c                 ^   | j                   rSt        | j                         dkD  r;| j                   j                  d      }| xj                  t        |      z  c_        |S |xs d}d}| j                   r$|| j                   j                         z  }d| _         	 | j                  j                         t        | j                        z
  }| j                  |      }|r%|j                  d      r|| j                  d      z  }||z  }|j                  d      }t        |      dkD  rA|d   }|dd | _         t        |      t        |      t        |      z
  z
  | _        || _
        	 |S t        |      dk(  r&|d   }|d   j                  d      d   }	||	k7  r|}	 |S |r||}	 |S |d	k  r|d
z  })aj  
        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@     )rD  r   rN  rF  rn   tellrC  rJ  rB   r  rE  )
rR   rK  rQ  readsizerL  startpos	new_charsr  line0withendline0withoutends
             r"   rO  z$SeekableUnicodeStreamReader.readline  s    ??s4??3a7??&&q)D!!SY.!K:2 ??T__((**E"DO{{'')C,@@H

8,I Y//5TZZ]*	YE$$T*E5zA~Qx"')(+I#e*s4y:P(Q%*2'   Uq$Qx"'("5"5e"<Q"??2'D   0  $A= r$   c                 @    | j                         j                  |      S )a  
        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  )rR   sizehintkeependss      r"   	readlinesz%SeekableUnicodeStreamReader.readlines  s     yy{%%h//r$   c                 6    | j                         }|r|S t        )z8Return the next decoded line from the underlying stream.)rO  StopIterationrP  s     r"   r   z SeekableUnicodeStreamReader.next  s    }}Kr$   c                 "    | j                         S r   )r   rV   s    r"   __next__z$SeekableUnicodeStreamReader.__next__  s    yy{r$   c                     | S zReturn selfrQ   rV   s    r"   __iter__z$SeekableUnicodeStreamReader.__iter__      r$   c                 >    | j                   s| j                          y y r   )closedr   rV   s    r"   __del__z#SeekableUnicodeStreamReader.__del__  s    {{JJL r$   c                     | S r   rQ   rV   s    r"   	__enter__z%SeekableUnicodeStreamReader.__enter__  s    r$   c                 $    | j                          y r   )r   )rR   typer3  	tracebacks       r"   __exit__z$SeekableUnicodeStreamReader.__exit__  s    

r$   c                     | S rf  rQ   rV   s    r"   
xreadlinesz&SeekableUnicodeStreamReader.xreadlines  rh  r$   c                 .    | j                   j                  S )z(True if the underlying stream is closed.)rn   rj  rV   s    r"   rj  z"SeekableUnicodeStreamReader.closed  s     {{!!!r$   c                 .    | j                   j                  S )z"The name of the underlying stream.)rn   r<   rV   s    r"   r<   z SeekableUnicodeStreamReader.name       {{r$   c                 .    | j                   j                  S )z"The mode of the underlying stream.)rn   r   rV   s    r"   r   z SeekableUnicodeStreamReader.mode  rv  r$   c                 8    | j                   j                          y)z.
        Close the underlying stream.
        N)rn   r   rV   s    r"   r   z!SeekableUnicodeStreamReader.close  s     	r$   c                     |dk(  rt        d      | j                  j                  ||       d| _        d| _        d| _        | j                  j                         | _        y)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   rn   r@  rD  rC  rF  rW  rE  )rR   offsetwhences      r"   r@  z SeekableUnicodeStreamReader.seek  s^     Q;5 
 	( $"&++"2"2"4r$   c                     |dk  rt        d      | j                  | j                                | j                  |       y)zI
        Move the read pointer forward by ``offset`` characters.
        r   z"Negative offsets are not supportedN)r6   r@  rW  _char_seek_forward)rR   rz  s     r"   char_seek_forwardz-SeekableUnicodeStreamReader.char_seek_forward  s7     A:ABB		$))+'r$   c                     ||}d}	 | j                   j                  |t        |      z
        }||z  }| j                  |      \  }}t        |      |k(  r*| j                   j	                  t        |       |z   d       yt        |      |kD  rot        |      |kD  r7||t        |      z
  z  }| j                  |d|       \  }}t        |      |kD  r7| j                   j	                  t        |       |z   d       y||t        |      z
  z  })a  
        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'   )rn   r   r   _incr_decoder@  )rR   rz  	est_bytesbytesnewbytesrL  bytes_decodeds          r"   r}  z.SeekableUnicodeStreamReader._char_seek_forward)  s    I{{''	CJ(>?HXE $(#4#4U#; E= 5zV#  #e*}!<a@ 5zF"%j6)#e*!44I+/+<+<U:I=N+O(E= %j6)   #e*}!<a@ #e*,,I3 r$   c                    | j                   0| j                  j                         t        | j                        z
  S | j                  j                         }|t        | j                        z
  | j
                  z
  }t        d | j                   D              }t        || j                  z  | j                  |z   z        }| j                  j                  | j
                         | j                  | j                  |       | j                  j                         }| j                  r| j                  j                  |       | j                  | j                  j                  d            d   }dj                  | j                         }|j                  |      s|j                  |      sJ | j                  j                  |       |S )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   2   K   | ]  }t        |        y wr   )r   )r   rQ  s     r"   r   z3SeekableUnicodeStreamReader.tell.<locals>.<genexpr>d  s     =_Ts4y_s   2   r   r   )rD  rn   rW  r   rC  rE  sumintrF  r@  r}  DEBUGr  r   r;   r,   )rR   orig_filepos
bytes_readbuf_sizer  fileposcheck1check2s           r"   rW  z SeekableUnicodeStreamReader.tellQ  sn    ??";;##%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&0III 	& r$   c                    |dk(  ry| j                   rB| j                  j                         dk(  r%| j                  j                  | j                          || j                  j                         }n| j                  j                  |      }| j                  |z   }| j                  |      \  }}|L|sJt        |      dkD  r<|s:| j                  j                  d      }|sn||z  }| j                  |      \  }}|s:||d | _        |S )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'   )rH  rn   rW  r   rC  r  r   )rR   rK  	new_bytesr  rL  r  s         r"   rJ  z!SeekableUnicodeStreamReader._read  s     19 99))+q0KKTYY' <((*I((.I)+  $007} u3y>A3E KK,,Q/	 "'+'8'8'?$}   / r$   c                 :   	 	 | j                  |d      S # t        $ r|}|j                  t        |      k(  r.| j                  |d|j                   | j
                        cY d}~S | j
                  dk(  r | j                  || j
                        cY d}~S d}~ww xY w)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    )rR   r  excs      r"   r  z(SeekableUnicodeStreamReader._incr_decode  s     ;{{5(33% ; 77c%j(;;u[syy'94;;GG [[H,
  ;;udkk::;s'    	BA BB$+BBBzutf16-lezutf16-bezutf32-lezutf32-be)utf8utf16utf16leutf16beutf32utf32leutf32bec                 j   t        j                  dd| j                  j                               }| j                  j                  |      }|rg| j                  j                  d      }| j                  j                  d       |D ],  \  }}|j                  |      s|r|| _        t        |      c S  y )Nz[ -]r      r   )r.   r/   r   r  
_BOM_TABLEr   rn   r   r@  r,   r   )rR   encbom_infor  bomnew_encodings         r"   rG  z&SeekableUnicodeStreamReader._check_bom  s    ffVR!4!4!67 ??&&s+KK$$R(EKKQ &.!\##C(#(4s8O	 &. r$   )r  r   NT)r   )$rZ   r[   r\   r]   r  rf   r   rR  rO  r`  r   rd  rg  rk  rm  rq  rs  rw   rj  r<   r   r   r@  r~  r}  rW  rJ  r  rA  BOM_UTF8BOM_UTF16_LEBOM_UTF16_BEBOM_UTF32_LEBOM_UTF32_BEr  rG  rQ   r$   r"   rl   rl     sK     E2=p(#:x	0 
 " "        50	(&-P(\$L;> //4()&&
3f6I6I:5VW(($/0(($/0&&
3f6I6I:5VW(($/0(($/0Jr$   rl   )r8   rO   r`   ry   r   r   r   r   r   r   r   r  r  r!  r   r   rl   )rk   r   r   NNN)TNr   r  )english)
multiclass)r   TFNNN)z##)Lr]   rA  	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   r`   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r!  r/  r   rl   __all__)r   s   0r"   <module>r     sa  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   L4 7M?M4MM