
`]c           @  s  d  Z  d d l m Z m Z m 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 m Z d d l m Z d d l m Z m Z d d l m Z m Z y d d l Z Wn e k
 rd d l Z n Xy e j e j d	 d
 Z  Wn> e! k
 rve j e j" d d
 d d
 d e# Z$ d   Z  n Xy d d l% m& Z' Wn! e k
 rd d l% m( Z' n Xd d l) Z) d d l* m+ Z+ m, Z, m- Z- g  Z. e j/ j0 d e1 d   j2 e j3  Z4 e. g  e4 D] Z5 e5 r e5 ^ q7Z. d e j/ k oKe j. j6 d  d k rpe. j7 e j. j6 e1 d    n  e
 j8 j9 d  r@e. e j. j: e
 j; e1 d   e j. j: e
 j; e1 d  e1 d   e j. j: e
 j; e1 d  e1 d   e j. j: e j/ j0 e1 d  e1 d   e1 d   e1 d  e1 d  e1 d  g 7Z. n e. e j. j: e
 j; e1 d   e j. j: e
 j; e1 d  e1 d   e j. j: e
 j; e1 d  e1 d   e1 d   e1 d!  e1 d"  e1 d#  g 7Z. d$ d% d& e< e< e< d'  Z= d(   Z> d)   Z? e@ e< d*  ZA e e  d+ eB f d,     Y ZC d- eC e f d.     YZD d/ e f d0     YZE d1 eD f d2     YZF d3 eC f d4     YZG i  ZH e< d5  ZI e< e@ d6  ZJ i d7 d8 6d9 d: 6d; d< 6d= d> 6d? d@ 6dA dB 6dC dD 6dE dF 6dG dH 6dI dJ 6dK dL 6ZK i d8 d8 6d: d: 6d< d< 6d> d> 6d@ d@ 6dB dB 6dD dD 6dF dF 6dH dH 6dL dM 6dL dL 6ZL dN e@ e# e< e< e< dO  ZM dP dQ  ZN dR   ZO dS   ZP dT eB f dU     YZQ dV e jR f dW     YZS dX eB f dY     YZT dZ d[ d\ d] d^ d^ d_ d` da db dc dd de df dg d^ dh g ZU d S(i   u  
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
``http://nltk.org/sample/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.

  - ``http://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.
i(   t   print_functiont   unicode_literalst   divisionN(   t   ABCMetat   abstractmethod(   t   GzipFilet   WRITE(   t   add_metaclass(   t   string_typest	   text_type(   t   urlopent   url2pathnamet   prefixu     t   initial_indentt   subsequent_indentt   replace_whitespacec         C  s   d j  d   |  j   D  S(   Nu   
c         s  s   |  ] } t  |  Vq d  S(   N(   t   textwrap_fill(   t   .0t   line(    (    s(   lib/python2.7/site-packages/nltk/data.pys	   <genexpr>C   s    (   t   joint
   splitlines(   t   text(    (    s(   lib/python2.7/site-packages/nltk/data.pyt   textwrap_indentB   s    (   t   Z_SYNC_FLUSH(   t   Z_FINISH(   t   py3_datat   add_py3_datat   BytesIOu	   NLTK_DATAu    u   APPENGINE_RUNTIMEu   ~/u   ~/nltk_datau   winu	   nltk_datau   shareu   libu   APPDATAu   C:\u   C:\nltk_datau   D:\nltk_datau   E:\nltk_datau   /usr/share/nltk_datau   /usr/local/share/nltk_datau   /usr/lib/nltk_datau   /usr/local/lib/nltk_datau   rbi	   u   utf-8c         C  s:   | d  k r$ t |  | | |  } n  t j | | | |  S(   N(   t   NoneR   t   iot   TextIOWrapper(   t   filenamet   modet   compresslevelt   encodingt   fileobjt   errorst   newline(    (    s(   lib/python2.7/site-packages/nltk/data.pyt   gzip_open_unicode}   s    	c         C  sz   |  j  d d  \ } } | d k r' nI | d k r[ | j d  rp d | j d  } qp n t j d d |  } | | f S(   u  
    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')
    u   :i   u   nltku   fileu   /u   ^/{0,2}u    (   t   splitt
   startswitht   lstript   ret   sub(   t   resource_urlt   protocolt   path_(    (    s(   lib/python2.7/site-packages/nltk/data.pyt   split_resource_url   s    c         C  s   y t  |   \ } } Wn t k
 r5 d } |  } n X| d k ro t j j |  ro d } t | t d  } nU | d k r d } t | t d  } n. | d k r d } t | t  } n
 | d 7} d j	 | | g  S(   u  
    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('http://example.com/dir/file')
    'http://example.com/dir/file'
    >>> normalize_resource_url('dir/file')
    'nltk:dir/file'
    u   nltku   file://u   fileu   nltk:u   ://u    N(
   R/   t
   ValueErrort   ost   patht   isabst   normalize_resource_namet   FalseR   t   TrueR   (   R,   R-   t   name(    (    s(   lib/python2.7/site-packages/nltk/data.pyt   normalize_resource_url   s     !

c         C  s6  t  t j d |    p* |  j t j j  } t j j	 d  rQ |  j
 d  }  n t j d d |   }  | r t j j |   }  n9 | d k r t j } n  t j j t j j | |    }  |  j d d  j t j j d  }  t j j	 d  rt j j |   rd |  }  n  | r2|  j d  r2|  d 7}  n  |  S(   u(  
    :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
    u   [\\/.]$u   winu   /u   ^/+u   \N(   t   boolR*   t   searcht   endswithR1   R2   t   sept   syst   platformR(   R)   R+   t   normpathR   t   curdirt   abspathR   t   replaceR3   (   t   resource_namet   allow_relativet   relative_patht   is_dir(    (    s(   lib/python2.7/site-packages/nltk/data.pyR4      s     !$$t   PathPointerc           B  s>   e  Z d  Z e d d   Z e d    Z e d    Z RS(   uq  
    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.
    c         C  s   d S(   u   
        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(    (   t   selfR"   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   open  t    c         C  s   d S(   u   
        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.
        N(    (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt	   file_size(  RJ   c         C  s   d S(   uP  
        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 seperator character.
        N(    (   RH   t   fileid(    (    s(   lib/python2.7/site-packages/nltk/data.pyR   2  RJ   N(   t   __name__t
   __module__t   __doc__R   R   RI   RK   R   (    (    (    s(   lib/python2.7/site-packages/nltk/data.pyRG     s
   		
t   FileSystemPathPointerc           B  s\   e  Z d  Z e d    Z e d    Z d d  Z d   Z	 d   Z
 d   Z d   Z RS(	   um   
    A path pointer that identifies a file which can be accessed
    directly via a given absolute path.
    c         C  sD   t  j j |  } t  j j |  s7 t d |   n  | |  _ d S(   u   
        Create a new path pointer for the given absolute path.

        :raise IOError: If the given path does not exist.
        u   No such file or directory: %rN(   R1   R2   RA   t   existst   IOErrort   _path(   RH   RS   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   __init__C  s    c         C  s   |  j  S(   u2   The absolute path identified by this path pointer.(   RS   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR2   S  s    c         C  s4   t  |  j d  } | d  k	 r0 t | |  } n  | S(   Nu   rb(   RI   RS   R   t   SeekableUnicodeStreamReader(   RH   R"   t   stream(    (    s(   lib/python2.7/site-packages/nltk/data.pyRI   X  s    c         C  s   t  j |  j  j S(   N(   R1   t   statRS   t   st_size(   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRK   ^  s    c         C  s"   t  j j |  j |  } t |  S(   N(   R1   R2   R   RS   RP   (   RH   RL   RS   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR   a  s    c         C  s   t  d |  j  S(   Nu   FileSystemPathPointer(%r)(   t   strRS   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   __repr__e  s    c         C  s   |  j  S(   N(   RS   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   __str__k  s    N(   RM   RN   RO   R   RT   t   propertyR2   R   RI   RK   R   RZ   R[   (    (    (    s(   lib/python2.7/site-packages/nltk/data.pyRP   =  s   			t   BufferedGzipFilec           B  s   e  Z d  Z d Z d e Z e d d d d d   Z d   Z d   Z	 d   Z
 d   Z e d	  Z d d
  Z d d  Z RS(   u  
    A ``GzipFile`` subclass that buffers calls to ``read()`` and ``write()``.
    This allows faster reads and writes of data to and from gzip-compressed
    files at the cost of using more memory.

    The default buffer size is 2MB.

    ``BufferedGzipFile`` is useful for loading large gzipped pickle objects
    as well as writing large encoded feature files for classifier training.
    i   i   i	   c         K  sJ   t  j |  | | | |  | j d |  j  |  _ t   |  _ d |  _ d S(   u!  
        Return a buffered gzip file object.

        :param filename: a filesystem path
        :type filename: str
        :param mode: a file mode which can be any of 'r', 'rb', 'a', 'ab',
            'w', or 'wb'
        :type mode: str
        :param compresslevel: The compresslevel argument is an integer from 1
            to 9 controlling the level of compression; 1 is fastest and
            produces the least compression, and 9 is slowest and produces the
            most compression. The default is 9.
        :type compresslevel: int
        :param fileobj: a BytesIO stream to read from instead of a file.
        :type fileobj: BytesIO
        :param size: number of bytes to buffer during calls to read() and write()
        :type size: int
        :rtype: BufferedGzipFile
        u   sizei    N(   R   RT   t   gett   SIZEt   _sizeR   t   _nltk_buffert   _len(   RH   R   R    R!   R#   t   kwargs(    (    s(   lib/python2.7/site-packages/nltk/data.pyRT   ~  s    c         C  s   t    |  _ d |  _ d  S(   Ni    (   R   Ra   Rb   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   _reset_buffer  s    c         C  s8   | d  k	 r4 |  j j |  |  j t |  7_ n  d  S(   N(   R   Ra   t   writeRb   t   len(   RH   t   data(    (    s(   lib/python2.7/site-packages/nltk/data.pyt   _write_buffer  s    c         C  s4   t  j |  |  j j    |  j   |  j |  d  S(   N(   R   Re   Ra   t   getvalueRd   Rh   (   RH   Rg   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   _write_gzip  s    
c         C  s6   |  j  t k r) |  j d   |  j   n  t j |   S(   N(   R    t   GZ_WRITERj   R   Rd   R   t   close(   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRl     s    c         C  s!   |  j  j   t j |  |  d  S(   N(   Ra   t   flushR   (   RH   t   lib_mode(    (    s(   lib/python2.7/site-packages/nltk/data.pyRm     s    c         C  sv   | sb |  j  } t   } x= t rW t j |  |  } | sG | j   Pn  | j |  q W| j   St j |  |  Sd  S(   N(   R`   R   R6   R   t   readRm   Re   Ri   (   RH   t   sizet   contentst   blocks(    (    s(   lib/python2.7/site-packages/nltk/data.pyRo     s    			

ic         C  sL   | s |  j  } n  |  j t |  | k r; |  j |  n |  j |  d S(   u   
        :param data: bytes to write to file or buffer
        :type data: bytes
        :param size: buffer at least size bytes before writing to file
        :type size: int
        N(   R`   Rb   Rf   Rh   Rj   (   RH   Rg   Rp   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRe     s
    i   N(   RM   RN   RO   t   MBR_   R   R   RT   Rd   Rh   Rj   Rl   t   FLUSHRm   Ro   Re   (    (    (    s(   lib/python2.7/site-packages/nltk/data.pyR]   o  s   

				t   GzipFileSystemPathPointerc           B  s   e  Z d  Z d d  Z RS(   u   
    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.
    c         C  sg   t  j j d  s$ t  j j d  r9 t |  j d  } n t |  j d  } | rc t | |  } n  | S(   Nu   2.7u   3.4u   rb(   R=   t   versionR(   R]   RS   R   RU   (   RH   R"   RV   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRI     s    $N(   RM   RN   RO   R   RI   (    (    (    s(   lib/python2.7/site-packages/nltk/data.pyRu     s   t   ZipFilePathPointerc           B  sn   e  Z d  Z e d d   Z e d    Z e d    Z d
 d  Z	 d   Z
 d   Z d   Z d	   Z RS(   u~   
    A path pointer that identifies a file contained within a zipfile,
    which can be accessed by reading that zipfile.
    u    c         C  s   t  | t  r* t t j j |   } n  | r t | t d  j d  } y | j	 |  Wq t
 k
 r | j d  r g  | j   D] } | j |  r | ^ q r q t d | j | f   q Xn  | |  _ | |  _ d S(   u   
        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.
        u   /u   Zipfile %r does not contain %rN(   t
   isinstanceR   t   OpenOnDemandZipFileR1   R2   RA   R4   R6   R)   t   getinfot	   ExceptionR;   t   namelistR(   RR   R   t   _zipfilet   _entry(   RH   t   zipfilet   entryt   n(    (    s(   lib/python2.7/site-packages/nltk/data.pyRT     s    	.	c         C  s   |  j  S(   u   
        The zipfile.ZipFile object used to access the zip file
        containing the entry identified by this path pointer.
        (   R}   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR     s    c         C  s   |  j  S(   u_   
        The name of the file within zipfile that this path
        pointer points to.
        (   R~   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR     s    c         C  s   |  j  j |  j  } t |  } |  j j d  r t j j d  sW t j j d  ro t |  j d | } q t	 |  j d | } n | d  k	 r t | |  } n  | S(   Nu   .gzu   2.7u   3.4R#   (   R}   Ro   R~   R   R;   R=   Rv   R(   R]   R   R   RU   (   RH   R"   Rg   RV   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRI   %  s    $c         C  s   |  j  j |  j  j S(   N(   R}   Rz   R~   RK   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRK   4  s    c         C  s#   d |  j  | f } t |  j |  S(   Nu   %s/%s(   R~   Rw   R}   (   RH   RL   R   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR   7  s    c         C  s   t  d  |  j j |  j f S(   Nu   ZipFilePathPointer(%r, %r)(   RY   R}   R   R~   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRZ   ;  s    c         C  s(   t  j j t  j j |  j j |  j   S(   N(   R1   R2   R?   R   R}   R   R~   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR[   >  s    N(   RM   RN   RO   R   RT   R\   R   R   R   RI   RK   R   RZ   R[   (    (    (    s(   lib/python2.7/site-packages/nltk/data.pyRw     s   $			c         C  s  t  |  t  }  | d k r$ t } n  t j d |   } | j   \ } } x6| D].} | r t j j |  r | j	 d  r y t
 | |   SWq}t k
 r qO q}XqO | s t j j |  rO | d k r"t j j | t |    } t j j |  rz| j	 d  rt |  St |  Sqzq}t j j | t |   } t j j |  r}y t
 | |  SWqzt k
 rvqO qzXq}qO qO W| d k r|  j d  } xl t t |   D]U } d j | |  | | d g | |  }	 y t |	 |  SWqt k
 rqXqWn  |  j d  d }
 |
 j	 d  rC|
 j d  d }
 n  t d  j d	 |
  } t |  } | d
 7} | d j d |   7} | d d j d   | D  7} d d } d | | | f } t |   d S(   u  
    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
    u   (.*\.zip)/?(.*)$|u   .zipu   .gzu   /i   u   .i    u   Resource [93m{resource}[0m not found.
Please use the NLTK Downloader to obtain the resource:

[31m>>> import nltk
>>> nltk.download('{resource}')
[0mt   resourceu<   
  For more information see: https://www.nltk.org/data.html
u.   
  Attempted to load [93m{resource_name}[0m
RC   u   
  Searched in:u    c         s  s   |  ] } d  | Vq d S(   u	   
    - %rN(    (   R   t   d(    (    s(   lib/python2.7/site-packages/nltk/data.pys	   <genexpr>  s    u   *iF   u
   
%s
%s
%s
N(   R4   R6   R   R2   R*   t   matcht   groupsR1   t   isfileR;   Rw   RR   t   isdirR   R   RQ   Ru   RP   R'   t   rangeRf   t   findt   LookupErrort
   rpartitionRY   t   formatR   (   RC   t   pathst   mR   t   zipentryR.   t   pt   piecest   it   modified_namet   resource_zipnamet   msgR<   t   resource_not_found(    (    s(   lib/python2.7/site-packages/nltk/data.pyR   M  s\    %	'

*	

!
c         C  s  t  |   }  | d
 k rX |  j d  r@ t j j |   d } qX t j d d |   } n  t j j |  r t j j	 |  } t
 d |   n  | r t d |  | f  n  t |   } t | d  : } x0 t r | j d  } | j |  | s Pq q WWd
 QX| j   d
 S(   u  
    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.
    u   file:iu   (^\w+:)?.*/u    u   File %r already exists!u   Retrieving %r, saving to %ru   wbi   i@   Ni   (   R8   R   R(   R1   R2   R'   R*   R+   RQ   RA   R0   t   printt   _openRI   R6   Ro   Re   Rl   (   R,   R   t   verboset   infilet   outfilet   s(    (    s(   lib/python2.7/site-packages/nltk/data.pyt   retrieve  s$    	u;   A serialized python object, stored using the pickle module.u   pickleu9   A serialized python object, stored using the json module.u   jsonu9   A serialized python object, stored using the yaml module.u   yamlu   A context free grammar.u   cfgu   A probabilistic CFG.u   pcfgu   A feature CFG.u   fcfguZ   A list of first order logic expressions, parsed with nltk.sem.logic.Expression.fromstring.u   folu   A list of first order logic expressions, parsed with nltk.sem.logic.LogicParser.  Requires an additional logic_parser parameteru   logicu>   A semantic valuation, parsed by nltk.sem.Valuation.fromstring.u   valu)   The raw (byte string) contents of a file.u   rawu-   The raw (unicode string) contents of a file. u   textu   txtu   autoc         C  s  t  |   }  t |   }  | d k r |  j d  } | d } | d k rV | d } n  t j |  } | d k r t d |    q n  | t k r t d | f   n  | r t j |  | f  }	 |	 d k	 r | r t	 d |  f  n  |	 Sn  | rt	 d	 |  f  n  t
 |   }
 | d
 k r2|
 j   }	 ni| d k rPt j |
  }	 nK| d k rd d l } d d l m } | j |
  }	 d } t |	  d k rt |	 j    } n  | | k rt d   qn| d k rd d l } | j |
  }	 n|
 j   } | d k	 r&| j |  } n6 y | j d  } Wn  t k
 r[| j d  } n X| d k rq| }	 n*| d k rt j j j | d | }	 n | d k rt j j j | d | }	 n | d k rt j j j | d | d | d | }	 n | d k r4t j j | d t j j j    d | }	 ng | d k rat j j | d | d | }	 n: | d k rt j j! | d | }	 n t" d | f   |
 j#   | ry |	 t |  | f <Wqt$ k
 rqXn  |	 S(   u  
    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.
    u   autou   .iu   gziuz   Could not determine format for %s based on its file
extension; use the "format" argument to specify the format explicitly.u   Unknown format type: %s!u   <<Using cached copy of %s>>u   <<Loading %s>>u   rawu   pickleu   jsonN(   t	   json_tagsi   u   Unknown json tag.u   yamlu   utf-8u   latin-1u   textu   cfgR"   u   pcfgu   fcfgt   logic_parsert   fstruct_readeru   folu   logicu   valu@   Internal NLTK error: Format %s isn't handled by nltk.data.load()(%   R8   R   R'   t   AUTO_FORMATSR^   R   R0   t   FORMATSt   _resource_cacheR   R   Ro   t   picklet   loadt   jsont   nltk.jsontagsR   Rf   t   nextt   keyst   yamlt   decodet   UnicodeDecodeErrort   nltkt   grammart   CFGt
   fromstringt   PCFGt   FeatureGrammart   semt
   read_logict   logict   LogicParsert   read_valuationt   AssertionErrorRl   t	   TypeError(   R,   R   t   cacheR   R   R   R"   t   resource_url_partst   extt   resource_valt   opened_resourceR   R   t   tagR   t   binary_datat   string_data(    (    s(   lib/python2.7/site-packages/nltk/data.pyR     s    7
			
u   ##c         C  s|   t  |   }  t |  d d d t } | j   } xE | D]= } | j |  rR q7 n  t j d |  rj q7 n  t |  q7 Wd S(   u}  
    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   u   textR   u   ^$N(   R8   R   R5   R   R(   R*   R   R   (   R,   t   escapeR   t   linest   l(    (    s(   lib/python2.7/site-packages/nltk/data.pyt   show_cfg  s    c           C  s   t  j   d S(   uF   
    Remove all objects from the resource cache.
    :see: load()
    N(   R   t   clear(    (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   clear_cache  s    c         C  s   t  |   }  t |   \ } } | d k s< | j   d k rV t | t d g  j   S| j   d k r~ t | d g  j   St |   Sd S(   uo  
    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.
    u   nltku    u   fileN(   R8   R/   R   t   lowerR   R2   RI   R
   (   R,   R-   R.   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR     s    t
   LazyLoaderc           B  s2   e  Z e d     Z d   Z d   Z d   Z RS(   c         C  s   | |  _  d  S(   N(   RS   (   RH   RS   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRT     s    c         C  s+   t  |  j  } | j |  _ | j |  _ d  S(   N(   R   RS   t   __dict__t	   __class__(   RH   R   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   __load  s    c         C  s   |  j    t |  |  S(   N(   t   _LazyLoader__loadt   getattr(   RH   t   attr(    (    s(   lib/python2.7/site-packages/nltk/data.pyt   __getattr__  s    
c         C  s   |  j    t |   S(   N(   R   t   repr(   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRZ     s    
(   RM   RN   R   RT   R   R   RZ   (    (    (    s(   lib/python2.7/site-packages/nltk/data.pyR     s   		Ry   c           B  sA   e  Z d  Z e d    Z d   Z d   Z d   Z d   Z RS(   u  
    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         C  s]   t  | t  s t d   n  t j j |  |  |  j | k sF t  |  j   d |  _	 d  S(   Nu+   ReopenableZipFile filename must be a stringi    (
   Rx   R   R   R   t   ZipFileRT   R   R   Rl   t   _fileRefCnt(   RH   R   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRT     s    
c         C  s\   |  j  d  k s t  t |  j d  |  _  t j j |  |  } |  j d 7_ |  j	   | S(   Nu   rbi   (
   t   fpR   R   RI   R   R   R   Ro   R   Rl   (   RH   R7   t   value(    (    s(   lib/python2.7/site-packages/nltk/data.pyRo   &  s    
c         O  s   t  d   d S(   u<   :raise NotImplementedError: OpenOnDemandZipfile is read-onlyu    OpenOnDemandZipfile is read-onlyN(   t   NotImplementedError(   RH   t   argsRc   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRe   0  s    c         O  s   t  d   d S(   u<   :raise NotImplementedError: OpenOnDemandZipfile is read-onlyu    OpenOnDemandZipfile is read-onlyN(   R   (   RH   R   Rc   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   writestr4  s    c         C  s   t  t d  |  j  S(   Nu   OpenOnDemandZipFile(%r)(   R   RY   R   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRZ   8  s    (	   RM   RN   RO   R   RT   Ro   Re   R   RZ   (    (    (    s(   lib/python2.7/site-packages/nltk/data.pyRy     s   		
		RU   c           B  s  e  Z d  Z e Z e d d   Z d# d  Z d   Z	 d# d  Z
 d# e 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 i e j d# f g d 6e j d f e j d f g d 6e j d# f g d 6e j d# f g d 6e j  d f e j! d f g d 6e j  d# f g d  6e j! d# f g d! 6Z" d"   Z# RS($   u  
    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.
    u   strictc         C  sq   | j  d  | |  _ | |  _ | |  _ t j |  |  _ d |  _ d  |  _	 d |  _
 d  |  _ |  j   |  _ d  S(   Ni    RJ   (   t   seekRV   R"   R$   t   codecst
   getdecoderR   t
   bytebufferR   t
   linebuffert   _rewind_checkpointt   _rewind_numcharst
   _check_bomt   _bom(   RH   RV   R"   R$   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRT   T  s    							c         C  sG   |  j  |  } |  j rC d j |  j  | } d |  _ d |  _ n  | S(   u6  
        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
        u    N(   t   _readR   R   R   R   (   RH   Rp   t   chars(    (    s(   lib/python2.7/site-packages/nltk/data.pyRo     s    
		c         C  sY   |  j  rH t |  j   d k rH |  j  j d  } |  j t |  7_ n |  j j   d  S(   Ni   i    (   R   Rf   t   popR   RV   t   readline(   RH   R   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   discard_line  s    c   
      C  s  |  j  rI t |  j   d k rI |  j  j d  } |  j t |  7_ | S| pR d } d } |  j  r | |  j  j   7} d |  _  n  xTt r|  j j   t |  j  } |  j	 |  } | r | j
 d  r | |  j	 d  7} n  | | 7} | j t  } t |  d k rT| d } | d |  _  t |  t |  t |  |  _ | |  _ PnL t |  d k r| d } | d j t  d }	 | |	 k r| } Pqn  | s| d k	 r| } Pn  | d k  r | d 9} q q W| S(	   uj  
        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
        i   i    iH   u    u   i@  i   N(   R   Rf   R   R   R   R6   RV   t   tellR   R   R;   R   R   R5   (
   RH   Rp   R   t   readsizeR   t   startpost	   new_charsR   t   line0withendt   line0withoutend(    (    s(   lib/python2.7/site-packages/nltk/data.pyR     sD    		

#	
c         C  s   |  j    j |  S(   u  
        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.
        (   Ro   R   (   RH   t   sizehintt   keepends(    (    s(   lib/python2.7/site-packages/nltk/data.pyt	   readlines  s    	c         C  s    |  j    } | r | St  d S(   u8   Return the next decoded line from the underlying stream.N(   R   t   StopIteration(   RH   R   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR     s    c         C  s
   |  j    S(   N(   R   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   __next__  s    c         C  s   |  S(   u   Return self(    (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   __iter__  s    c         C  s   |  j  s |  j   n  d  S(   N(   t   closedRl   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   __del__  s    	c         C  s   |  S(   u   Return self(    (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt
   xreadlines  s    c         C  s
   |  j  j S(   u(   True if the underlying stream is closed.(   RV   R   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR     s    c         C  s
   |  j  j S(   u"   The name of the underlying stream.(   RV   R7   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR7     s    c         C  s
   |  j  j S(   u"   The mode of the underlying stream.(   RV   R    (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR      s    c         C  s   |  j  j   d S(   u.   
        Close the underlying stream.
        N(   RV   Rl   (   RH   (    (    s(   lib/python2.7/site-packages/nltk/data.pyRl     s    i    c         C  s_   | d k r t  d   n  |  j j | |  d |  _ d |  _ d |  _ |  j j   |  _ d S(   u  
        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).
        i   um   Relative seek is not supported for SeekableUnicodeStreamReader -- consider using char_seek_forward() instead.RJ   N(	   R0   RV   R   R   R   R   R   R   R   (   RH   t   offsett   whence(    (    s(   lib/python2.7/site-packages/nltk/data.pyR   $  s    			c         C  s?   | d k  r t  d   n  |  j |  j    |  j |  d S(   uI   
        Move the read pointer forward by ``offset`` characters.
        i    u"   Negative offsets are not supportedN(   R0   R   R   t   _char_seek_forward(   RH   R   (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   char_seek_forward<  s    c         C  s)  | d k r | } n  d } xt r$|  j j | t |   } | | 7} |  j |  \ } } t |  | k r |  j j t |  | d  d St |  | k rxC t |  | k r | | t |  7} |  j | |   \ } } q W|  j j t |  | d  d S| | t |  7} q Wd S(   u  
        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``.
        RJ   i   N(   R   R6   RV   Ro   Rf   t   _incr_decodeR   (   RH   R   t	   est_bytest   bytest   newbytesR   t   bytes_decoded(    (    s(   lib/python2.7/site-packages/nltk/data.pyR   G  s"    			
c         C  sC  |  j  d k r) |  j j   t |  j  S|  j j   } | t |  j  |  j } t d   |  j  D  } t | |  j	 |  j	 |  } |  j j
 |  j  |  j |  j	 |  |  j j   } |  j r/|  j j
 |  |  j |  j j d   d } d j |  j   } | j |  s/| j |  s/t  n  |  j j
 |  | S(   u   
        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         s  s   |  ] } t  |  Vq d  S(   N(   Rf   (   R   R   (    (    s(   lib/python2.7/site-packages/nltk/data.pys	   <genexpr>  s    i2   i    u    N(   R   R   RV   R   Rf   R   R   t   sumt   intR   R   R   t   DEBUGR   Ro   R   R(   R   (   RH   t   orig_filepost
   bytes_readt   buf_sizeR   t   filepost   check1t   check2(    (    s(   lib/python2.7/site-packages/nltk/data.pyR   o  s"    	'c         C  s  | d k r d S|  j  rD |  j j   d k rD |  j j |  j   n  | d k rb |  j j   } n |  j j |  } |  j | } |  j |  \ } } | d k	 r| rt |  d k rxH | s|  j j d  } | s Pn  | | 7} |  j |  \ } } q Wn  | | |  _ | S(   u   
        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.
        i    u    i   N(   R   RV   R   Ro   R   R   R   Rf   (   RH   Rp   t	   new_bytesR   R   R   (    (    s(   lib/python2.7/site-packages/nltk/data.pyR     s$    %	
c         C  s   x t  r y |  j | d  SWq t k
 r } | j t |  k r^ |  j | | j  |  j  S|  j d k rs   q |  j | |  j  Sq Xq Wd S(   u  
        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.
        u   strictN(   R6   R   R   t   endRf   t   startR$   (   RH   R   t   exc(    (    s(   lib/python2.7/site-packages/nltk/data.pyR     s    	u   utf8u   utf16-leu   utf16-beu   utf16u   utf16leu   utf16beu   utf32-leu   utf32-beu   utf32u   utf32leu   utf32bec         C  s   t  j d d |  j j    } |  j j |  } | r |  j j d  } |  j j d  xB | D]7 \ } } | j	 |  r_ | r | |  _ n  t
 |  Sq_ Wn  d  S(   Nu   [ -]u    i   i    (   R*   R+   R"   R   t
   _BOM_TABLER^   RV   Ro   R   R(   Rf   R   (   RH   t   enct   bom_infoR   t   bomt   new_encoding(    (    s(   lib/python2.7/site-packages/nltk/data.pyR     s    N($   RM   RN   RO   R6   R  R   RT   R   Ro   R   R   R   R   R   R   R   R   R\   R   R7   R    Rl   R   R   R   R   R   R   R   t   BOM_UTF8t   BOM_UTF16_LEt   BOM_UTF16_BEt   BOM_UTF32_LEt   BOM_UTF32_BER  R   (    (    (    s(   lib/python2.7/site-packages/nltk/data.pyRU   A  s@   8	<						
	(	.&	u   pathu   PathPointeru   FileSystemPathPointeru   BufferedGzipFileu   GzipFileSystemPathPointeru   findu   retrieveu   FORMATSu   AUTO_FORMATSu   loadu   show_cfgu   clear_cacheu
   LazyLoaderu   OpenOnDemandZipFileu   SeekableUnicodeStreamReader(V   RO   t
   __future__R    R   R   t	   functoolst   textwrapR   R1   R*   R=   R   R   t   abcR   R   t   gzipR   R   Rk   t   sixR   R   R	   t   six.moves.urllib.requestR
   R   t   cPickleR   t   ImportErrort   partialt   indentR   t   AttributeErrort   fillR5   R   t   zlibR   Rt   R   R   t   nltk.compatR   R   R   R2   t   environR^   RY   R'   t   pathsept   _paths_from_envR   t
   expandusert   appendR>   R(   R   R   R   R&   R/   R8   R6   R4   t   objectRG   RP   R]   Ru   Rw   R   R   R   R   R   R   R   R   R   R   R   Ry   RU   t   __all__(    (    (    s(   lib/python2.7/site-packages/nltk/data.pyt   <module>    s   		'#'"$$3		$$					85)2g^s)

		"1 