³ò
4ÒÇIc           @   s8   d  d k  Z  d  d k Z e Z d e f d „  ƒ  YZ d S(   iÿÿÿÿNt   LazyCorpusLoaderc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s6  
    A proxy object which is used to stand in for a corpus object
    before the corpus is loaded.  This allows NLTK to create an object
    for each corpus, but defer the costs associated with loading those
    corpora until the first time that they're actually accessed.

    The first time this object is accessed in any way, it will load
    the corresponding corpus, and transform itself into that corpus
    (by modifying its own C{__class__} and C{__dict__} attributes).

    If the corpus can not be found, then accessing this object will
    raise an exception, displaying installation instructions for the
    NLTK data package.  Once they've properly installed the data
    package (or modified C{nltk.data.path} to point to its location),
    they can then use the corpus object without restarting python.
    c         O   sV   d d k  l } t | | ƒ p t ‚ | |  _ |  _ | |  _ | |  _ | |  _ d  S(   Niÿÿÿÿ(   t   CorpusReader(	   t   nltk.corpus.reader.apiR   t
   issubclasst   AssertionErrort   _LazyCorpusLoader__namet   __name__t   _LazyCorpusLoader__reader_clst   _LazyCorpusLoader__argst   _LazyCorpusLoader__kwargs(   t   selft   namet
   reader_clst   argst   kwargsR   (    (    s&   /p/zhu/06/nlp/nltk/nltk/corpus/util.pyt   __init__"   s    		c         C   s  t  i d d |  i ƒ } t oP y t i i d | ƒ } WqÚ t j
 o# ‚  t i i d |  i ƒ } qÚ Xnl y t i i d |  i ƒ } WnK t j
 o? } y t i i d | ƒ } WqÚ t j
 o | ‚ qÚ Xn X|  i | |  i	 |  i
 Ž } | i |  _ | i |  _ d  S(   Ns   (([^/]*)(/.*)?)s
   \2.zip/\1/s
   corpora/%s(   t   ret   subR   t   TRY_ZIPFILE_FIRSTt   nltkt   datat   findt   LookupErrorR   R   R	   t   __dict__t	   __class__(   R
   t   zip_namet   roott   et   corpus(    (    s&   /p/zhu/06/nlp/nltk/nltk/corpus/util.pyt   __load*   s    "c         C   s   |  i  ƒ  t |  | ƒ S(   N(   t   _LazyCorpusLoader__loadt   getattr(   R
   t   attr(    (    s&   /p/zhu/06/nlp/nltk/nltk/corpus/util.pyt   __getattr__C   s    
c         C   s   d |  i  i d |  i f S(   Ns   <%s in %r (not loaded yet)>s   .../corpora/(   R   R   R   (   R
   (    (    s&   /p/zhu/06/nlp/nltk/nltk/corpus/util.pyt   __repr__I   s    (   R   t
   __module__t   __doc__R   R   R!   R"   (    (    (    s&   /p/zhu/06/nlp/nltk/nltk/corpus/util.pyR       s
   			(   R   R   t   FalseR   t   objectR    (    (    (    s&   /p/zhu/06/nlp/nltk/nltk/corpus/util.pys   <module>   s   