m
TEc        $   @   sY  d  Z  d Z d Z d k Z d k Z d k l Z d k l Z l Z l	 Z	 l
 Z
 e i d h  d d <d	 d
 <d d <i e i d   Z e i d e i i e h  d d <i e i d    Z d Z d Z e i d j o d p d Z d Z d Z d Z d Z e e e e f Z d Z d Z d Z d Z d Z d Z d Z d  Z  d! Z! d" Z" d# Z# d$ Z$ d% Z% d& Z& d' Z' d( Z( d) Z) d* Z* d+ Z+ d, Z, d- Z- d. Z. d/ Z/ d0 Z0 d1 Z1 d2 Z2 e e e e e e  e! e" e# e$ e% e& e' e( e) e* e+ e, e- e. e/ e0 e1 e2 f Z3 d3 Z4 d4 Z5 d5 Z6 e4 e5 e6 d f Z8 d Z9 dY f  dZ     YZ: d[ f  d\     YZ; d] f  d^     YZ< d_ f  d`     YZ= da f  db     YZ> dc   Z? e?   dd f  de     YZ@ df f  dg     YZA d dh  ZB d d di  ZC dj   ZD eB eC eD ZE ZF ZG dk   ZH dl   ZI dm   ZJ dn   ZK do   ZL h  dp dq  ZM dr   ZN d d ds  ZO dt   ZP du f  dv     YZQ dw f  dx     YZR dy ZS eQ eS  ZT dz   ZU d{   ZV d|   ZW eS d}  ZX eX ZY e@ e d  ZZ e@ e d  Z[ e@ e d~  Z\ e@ e d  Z] eZ e[ e\ e] f Z^ h  a_ h  a` d   Za ea   d   Zb d   Zc d   Zd d   Ze d d  Zf d S(   sU  An OO interface to the WordNet database.

Usage
-----
>>> from wordnet import *

>>> # Retrieve words from the database
>>> N['dog']
dog(n.)
>>> V['dog']
dog(v.)
>>> ADJ['clear']
clear(adj.)
>>> ADV['clearly']
clearly(adv.)

>>> # Examine a word's senses and pointers:
>>> N['dog'].getSenses()
('dog' in {noun: dog, domestic dog, Canis familiaris}, 'dog' in {noun: frump, dog}, 'dog' in {noun: dog}, 'dog' in {noun: cad, bounder, blackguard, dog, hound, heel}, 'dog' in {noun: frank, frankfurter, hotdog, hot dog, dog, wiener, wienerwurst, weenie}, 'dog' in {noun: pawl, detent, click, dog}, 'dog' in {noun: andiron, firedog, dog, dog-iron})
>>> # Extract the first sense
>>> dog = N['dog'][0]   # aka N['dog'].getSenses()[0]
>>> dog
'dog' in {noun: dog, domestic dog, Canis familiaris}
>>> dog.getPointers()[:5]
(hypernym -> {noun: canine, canid}, member meronym -> {noun: Canis, genus Canis}, member meronym -> {noun: pack}, hyponym -> {noun: pooch, doggie, doggy, barker, bow-wow}, hyponym -> {noun: cur, mongrel, mutt})
>>> dog.getPointerTargets(MEMBER_MERONYM)
[{noun: Canis, genus Canis}, {noun: pack}]
s"   Oliver Steele <steele@osteele.com>s   2.0.1N(   s   environ(   s   IntTypes   ListTypes
   StringTypes	   TupleTypet   WNHOMEt   mact   :t   doss   C:\wn16t   nts   C:\Program Files\WordNet\2.0s   /p/zhu/06/WordNet-2.1t   WNSEARCHDIRt   Databaset   dicti   i    t   rbt   rt   nount   verbt	   adjectivet   adverbs   has instancet   instancet   antonymt   hypernymt   hyponymt	   attributes   also seet
   entailmentt   causes
   verb groups   member meronyms   substance meronyms   part meronyms   member holonyms   substance holonyms   part holonymt   similars   participle oft	   pertainymt   framess   domain categorys   domain usages   domain regionals   class categorys   class usages   class regionalt   attributivet   predicatives   immediate postnominals   Something %ss   Somebody %ss   It is %sings   Something is %sing PPs%   Something %s something Adjective/Nouns   Something %s Adjective/Nouns   Somebody %s Adjectives   Somebody %s somethings   Somebody %s somebodys   Something %s somebodys   Something %s somethings   Something %s to somebodys   Somebody %s on somethings   Somebody %s somebody somethings!   Somebody %s something to somebodys#   Somebody %s something from somebodys#   Somebody %s somebody with somethings!   Somebody %s somebody of somethings!   Somebody %s something on somebodys   Somebody %s somebody PPs   Somebody %s something PPs   Somebody %s PPs   Somebody's (body part) %ss"   Somebody %s somebody to INFINITIVEs   Somebody %s somebody INFINITIVEs   Somebody %s that CLAUSEs   Somebody %s to somebodys   Somebody %s to INFINITIVEs   Somebody %s whether INFINITIVEs)   Somebody %s somebody into V-ing somethings$   Somebody %s something with somethings   Somebody %s INFINITIVEs   Somebody %s VERB-ings   It %s that CLAUSEs   Something %s INFINITIVEt   Wordc           B   s   t  Z d  Z d   Z e d  Z e d  Z d   Z d   Z d   Z	 d   Z
 e
 Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   s  An index into the database.
    
    Each word has one or more Senses, which can be accessed via
    ``word.getSenses()`` or through the index notation, ``word[n]``.

    Fields
    ------
      form : string
          The orthographic representation of the word.
      pos : string
          The part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB.
      string : string
          Same as form (for compatability with version 1.0).
      taggedSenseCount : integer
          The number of senses that are tagged.
    
    Examples
    --------
    >>> N['dog'].pos
    'noun'
    >>> N['dog'].form
    'dog'
    >>> N['dog'].taggedSenseCount
    1
    c         C   s   t  i |  } t t | t | d  d  } t  i | d d d  |  _	 t
 | d  |  _ | d |  _ | d | d d !|  _ d S(	   s1   Initialize the word from a line of a WN POS file.i   i   i    t   _t    i   i   N(   t   stringt   splitt   linet   tokenst   mapt   intt   intst   replacet   selft   formt   _normalizePOSt   post   taggedSenseCountt   _synsetOffsets(   R%   R   R    R#   (    (    tP   /afs/cs.wisc.edu/p/zhu/public/html/space2/TTP2/hybrid_image_selection/wordnet.pyt   __init__   s     !   c         C   s   |  i i  d S(   sZ   Pointers connect senses and synsets, not words.
        Try word[0].getPointers() instead.N(   R%   t   getPointerst   __doc__(   R%   t   pointerType(    (    R+   R-      s     c         C   s   |  i i  d S(   s`   Pointers connect senses and synsets, not words.
        Try word[0].getPointerTargets() instead.N(   R%   R-   R.   (   R%   R/   (    (    R+   t   getPointerTargets   s     c         C   sQ   t  |  d  p: |  i |  i d  } t t | |  i   |  _ |  ` n |  i S(   s  Return a sequence of senses.
	
	>>> N['dog'].getSenses()
	('dog' in {noun: dog, domestic dog, Canis familiaris}, 'dog' in {noun: frump, dog}, 'dog' in {noun: dog}, 'dog' in {noun: cad, bounder, blackguard, dog, hound, heel}, 'dog' in {noun: frank, frankfurter, hotdog, hot dog, dog, wiener, wienerwurst, weenie}, 'dog' in {noun: pawl, detent, click, dog}, 'dog' in {noun: andiron, firedog, dog, dog-iron})
	t   _sensesc         C   s   t  | |   | S(   N(   t	   getSynsetR(   t   offsetR&   (   R3   R(   R&   (    (    R+   t   getSense   s    N(	   t   hasattrR%   R(   R&   R4   t   tupleR!   R*   R1   (   R%   R4   (    (    R+   t	   getSenses   s     
c         C   s   d  k  } |  i   S(   N(   t   wordnetR%   R4   (   R%   R8   (    (    R+   t   senses   s    	c         C   s   |  i d j S(   s@   Return 1 if any sense is tagged.
	
	>>> N['dog'].isTagged()
	1
	i    N(   R%   R)   (   R%   (    (    R+   t   isTagged  s     c         C   s4   h  } x! |  i   D] } d | | i <q W| i   S(   s   Return a sequence of adjective positions that this word can
	appear in.  These are elements of ADJECTIVE_POSITIONS.
	
	>>> ADJ['clear'].getAdjectivePositions()
	[None, 'predicative']
	i   N(   t	   positionsR%   R7   t   senset   positiont   keys(   R%   R;   R<   (    (    R+   t   getAdjectivePositions	  s      c         C   s   t  |  | d  S(   s:   
	>>> N['cat'] < N['dog']
	1
	>>> N['dog'] < V['dog']
	1
	R(   R&   N(   s   poss   form(   t   _compareInstancesR%   t   other(   R%   RA   (    (    R+   t   __cmp__  s     c         C   sD   h  t  d <t d <t d <t d <} |  i d | |  i d S(   sI   Return a human-readable representation.
	
	>>> str(N['dog'])
	'dog(n.)'
	s   n.s   v.s   adj.s   adv.t   (t   )N(   t   NOUNt   VERBt	   ADJECTIVEt   ADVERBt   abbrsR%   R&   R(   (   R%   RI   (    (    R+   t   __str__   s     *c         C   s*   t  o t |   Sn d |  i |  i f S(   s   If ReadableRepresentations is true, return a human-readable
	representation, e.g. 'dog(n.)'.
	
	If ReadableRepresentations is false, return a machine-readable
	representation, e.g. "getWord('dog', 'noun')".
	t   getWordN(   t   ReadableRepresentationst   strR%   R&   R(   (   R%   (    (    R+   t   __repr__)  s     c         C   s   d S(   Ni   (    (   R%   (    (    R+   t   __nonzero__7  s    c         C   s   t  |  i    S(   N(   t   lenR%   R7   (   R%   (    (    R+   t   __len__:  s    c         C   s   |  i   | S(   N(   R%   R7   t   index(   R%   RR   (    (    R+   t   __getitem__=  s    c         C   s   |  i   | | !S(   N(   R%   R7   t   it   j(   R%   RT   RU   (    (    R+   t   __getslice__@  s    (   t   __name__t
   __module__R.   R,   t   NoneR-   R0   R7   R9   R:   R?   t   adjectivePositionsRB   RJ   RN   RO   RQ   RS   RV   (    (    (    R+   R      s     													t   Synsetc           B   s   t  Z d  Z d   Z d   Z e Z e d  Z e Z e d  Z	 e	 Z
 d   Z d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z RS(   s  A set of synonyms that share a common meaning.
    
    Each synonym contains one or more Senses, which represent a
    specific sense of a specific word.  Senses can be retrieved via
    synset.getSenses() or through the index notations synset[0],
    synset[string], or synset[word]. Synsets also originate zero or
    more typed pointers, which can be accessed via
    synset.getPointers() or synset.getPointers(pointerType). The
    targets of a synset pointer can be retrieved via
    synset.getPointerTargets() or
    synset.getPointerTargets(pointerType), which are equivalent to
    map(Pointer.target, synset.getPointerTargets(...)).
    
    Fields
    ------
      pos : string
          The part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB.
      offset : integer
          An integer offset into the part-of-speech file.  Together
          with pos, this can be used as a unique id.
      gloss : string
          A gloss for the sense.
      verbFrames : [integer]
          A sequence of integers that index into
          VERB_FRAME_STRINGS. These list the verb frames that any
          Sense in this synset participates in.  (See also
          Sense.verbFrames.) Defined only for verbs.

          >>> V['think'][0].synset.verbFrames
          (5, 9)
    c   
      C   s~  | |  _  | |  _ t i | t i | d    } | d |  _ t i	 | t i | d  d  |  _
 t i t | d  |  _ t | d d t i | d d   \ |  _ }	 t |	 d d t |	 d   \ |  _ }	 | t j o t |	 d d t |	 d   \ } }	 d   } g  } x: t d t |  i  d  D] } | i | | |   q5W| |  _ t | d	 |   |  _ n d	 S(
   s7   Initialize the synset from a line off a WN synset file.t   |i   i   i   i   i   i    c         C   s%   t  t d   t |  d  |    S(   Nc         C   s   t  i |  d  S(   Ni   (   R   t   atoit   t(   R^   (    (    R+   t   <lambda>u  s    c         C   s    t  i |  d d  d | f j S(   Ni   i   i    (   R   R]   R^   RT   (   R^   RT   (    (    R+   R_   u  s    (   R6   R!   t   filterRR   t   vfTuples(   RR   Ra   (    (    R+   t   extractVerbFramest  s    N(   R(   R%   R3   R   R   R   RR   R    t   ssTypet   stript   glosst   Lexnamet   lexnamesR"   t   lexnamet
   _partitionR]   t   _senseTuplest	   remaindert   _pointerTuplesRF   Ra   Rb   t   senseVerbFramest   rangeRP   t   appendt   _senseVerbFramesR6   RY   t
   verbFrames(
   R%   R(   R3   R   RR   Rb   Rm   R    Ra   Rk   (    (    R+   R,   e  s*     	 	 &/)&	 	c         C   s   t  |  d  po d |  d  } |  i t j o+ t t | |  i |  i	   |  _
 |  `	 n t t | |  i   |  _
 |  ` n |  i
 S(   sv   Return a sequence of Senses.
	
	>>> N['dog'][0].getSenses()
	('dog' in {noun: dog, domestic dog, Canis familiaris},)
	R1   c         C   s   t  | |  |  S(   N(   t   Senset   synsett
   senseTupleRq   (   Rt   Rq   Rs   (    (    R+   t	   loadSense  s    N(   R5   R%   RY   Ru   R(   RF   R6   R!   Rj   Rp   R1   (   R%   Ru   (    (    R+   R7     s     !

c         C   s}   t  |  d  p1 |  d  } t t | |  i   |  _ |  ` n | d j o |  i Sn! t	 |  t
 | d  |  i  Sd S(   s  Return a sequence of Pointers.

        If pointerType is specified, only pointers of that type are
        returned.  In this case, pointerType should be an element of
        POINTER_TYPES.
	
	>>> N['dog'][0].getPointers()[:5]
	(hypernym -> {noun: canine, canid}, member meronym -> {noun: Canis, genus Canis}, member meronym -> {noun: pack}, hyponym -> {noun: pooch, doggie, doggy, barker, bow-wow}, hyponym -> {noun: cur, mongrel, mutt})
	>>> N['dog'][0].getPointers(HYPERNYM)
	(hypernym -> {noun: canine, canid},)
	t	   _pointersc         C   s   t  | i |   S(   N(   t   PointerRs   R3   R6   (   R6   Rs   (    (    R+   t   loadPointer  s    c         C   s   |  i | j S(   N(   t   pointert   type(   Ry   Rz   (    (    R+   R_     s    N(   R5   R%   Rx   R6   R!   Rl   Rv   R/   RY   t   _requirePointerTypeR`   (   R%   R/   Rx   (    (    R+   R-     s     

c         C   s   t  t i |  i |   S(   s  Return a sequence of Senses or Synsets.
	
        If pointerType is specified, only targets of pointers of that
        type are returned.  In this case, pointerType should be an
        element of POINTER_TYPES.
	
	>>> N['dog'][0].getPointerTargets()[:5]
	[{noun: canine, canid}, {noun: Canis, genus Canis}, {noun: pack}, {noun: pooch, doggie, doggy, barker, bow-wow}, {noun: cur, mongrel, mutt}]
	>>> N['dog'][0].getPointerTargets(HYPERNYM)
	[{noun: canine, canid}]
	N(   R!   Rw   t   targetR%   R-   R/   (   R%   R/   (    (    R+   R0     s     c         C   s"   t  t t i |  i     d j S(   sb   Return 1 if any sense is tagged.
	
	>>> N['dog'][0].isTagged()
	1
	>>> N['dog'][1].isTagged()
	0
	i    N(   RP   R`   Rr   R:   R%   R7   (   R%   (    (    R+   R:     s     c         C   s5   d |  i d t i t d   |  i    d  d S(   sw   Return a human-readable representation.
	
	>>> str(N['dog'][0].synset)
	'{noun: dog, domestic dog, Canis familiaris}'
	t   {s   : c         C   s   |  i S(   N(   R<   R&   (   R<   (    (    R+   R_     s    s   , t   }N(   R%   R(   R   t
   joinfieldsR!   R7   (   R%   (    (    R+   RJ     s     c         C   s*   t  o t |   Sn d |  i |  i f S(   s   If ReadableRepresentations is true, return a human-readable
	representation, e.g. 'dog(n.)'.
	
	If ReadableRepresentations is false, return a machine-readable
	representation, e.g. "getSynset(pos, 1234)".
	R2   N(   RL   RM   R%   R(   R3   (   R%   (    (    R+   RN     s     c         C   s   t  |  | d  S(   NR(   R3   (   s   poss   offset(   R@   R%   RA   (   R%   RA   (    (    R+   RB     s    c         C   s   d S(   Ni   (    (   R%   (    (    R+   RO     s    c         C   s   t  |  i    S(   s"   
	>>> len(N['dog'][0].synset)
	3
	N(   RP   R%   R7   (   R%   (    (    R+   RQ     s     c         C   s   |  i   } t | t  o | i } n t | t  o> t | t	 d   |   p t | t	 d   |  t
  } n | | S(   s   
	>>> N['dog'][0].synset[0] == N['dog'][0]
	1
	>>> N['dog'][0].synset['dog'] == N['dog'][0]
	1
	>>> N['dog'][0].synset[N['dog']] == N['dog'][0]
	1
	>>> N['cat'][6]
	'cat' in {noun: big cat, cat}
	c         C   s   |  i S(   N(   R<   R&   (   R<   (    (    R+   R_     s    c         C   s   |  i S(   N(   R<   R&   (   R<   (    (    R+   R_     s    N(   R%   R7   R9   t
   isinstancet   idxR   R&   t
   StringTypet   _indexR!   t   _equalsIgnoreCase(   R%   R   R9   (    (    R+   RS     s    
 >c         C   s   |  i   | | !S(   N(   R%   R7   RT   RU   (   R%   RT   RU   (    (    R+   RV     s    (   RW   RX   R.   R,   R7   R9   RY   R-   t   pointersR0   t   pointerTargetsR:   RJ   RN   RB   RO   RQ   RS   RV   (    (    (    R+   R[   D  s     			
						Rr   c           B   s   t  Z d  Z e d  Z d   Z d   Z d   Z e d  Z e Z	 e d  Z
 e
 Z d   Z e Z d   Z d	   Z e Z d
   Z RS(   s  A specific meaning of a specific word -- the intersection of a Word and a Synset.
    
    Fields
    ------
      form : string
          The orthographic representation of the Word this is a Sense of.
      pos : string
          The part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB
      string : string
          The same as form (for compatability with version 1.0).
      synset : Synset
          The Synset that this Sense is a sense of.
      verbFrames : [integer]
          A sequence of integers that index into
          VERB_FRAME_STRINGS. These list the verb frames that this
          Sense partipates in.  Defined only for verbs.

          >>> decide = V['decide'][0].synset	# first synset for 'decide'
          >>> decide[0].verbFrames
          (8, 2, 26, 29)
          >>> decide[1].verbFrames
          (8, 2)
          >>> decide[2].verbFrames
          (8, 26, 29)
    c         C   s   | i |  _ | i |  _ | |  _ | \ } } d
 |  _
 d | j o t i | d  } | | d d !} | |  } | d j o t |  _
 q | d j o t |  _
 q | d j o t |  _
 q d |  n t i | d d	  |  _ d
 S(   s.   Initialize a sense from a synset's senseTuple.RC   i   it   at   pt   ips   unknown attribute R   R   N(   Rs   R(   R<   R3   t   synsetOffsetRq   Rt   R&   t   idStringRY   R=   R   RR   t   keyt   ATTRIBUTIVEt   PREDICATIVEt   IMMEDIATE_POSTNOMINALR$   (   R<   Rs   Rt   Rq   RR   R&   R   R   (    (    R+   R,     s*       	 	
c         C   sL   | d j o t |  i |  i  Sn% | d j o |  i i Sn
 t |  d  S(   NRs   Rh   (   t   nameR2   R%   R(   R   Rs   Rh   t   AttributeError(   R%   R   (    (    R+   t   __getattr__:  s
    c         C   s   |  i d t |  i  S(   sI   Return a human-readable representation.
	
	>>> str(N['dog'])
	'dog(n.)'
	s    in N(   R%   R&   RM   Rs   (   R%   (    (    R+   RJ   D  s     c         C   s+   t  o t |   Sn d |  i |  i f S(   s   If ReadableRepresentations is true, return a human-readable
	representation, e.g. 'dog(n.)'.
	
	If ReadableRepresentations is false, return a machine-readable
	representation, e.g. "getWord('dog', 'noun')".
	s   %s[%s]N(   RL   RM   R%   Rs   R&   (   R%   (    (    R+   RN   L  s     c         C   s=   t  |  |  i i    } | d  } t | |  i i |   S(   s  Return a sequence of Pointers.
	
        If pointerType is specified, only pointers of that type are
        returned.  In this case, pointerType should be an element of
        POINTER_TYPES.
	
	>>> N['dog'][0].getPointers()[:5]
	(hypernym -> {noun: canine, canid}, member meronym -> {noun: Canis, genus Canis}, member meronym -> {noun: pack}, hyponym -> {noun: pooch, doggie, doggy, barker, bow-wow}, hyponym -> {noun: cur, mongrel, mutt})
	>>> N['dog'][0].getPointers(HYPERNYM)
	(hypernym -> {noun: canine, canid},)
	c         C   s!   |  i d j p |  i d | j S(   Ni    i   (   Ry   t   sourceIndext	   selfIndex(   Ry   R   (    (    R+   t   pointsFromThisSensed  s    N(	   R   R%   Rs   R7   t
   senseIndexR   R`   R-   R/   (   R%   R/   R   R   (    (    R+   R-   W  s     c         C   s   t  t i |  i |   S(   s  Return a sequence of Senses or Synsets.
	
        If pointerType is specified, only targets of pointers of that
        type are returned.  In this case, pointerType should be an
        element of POINTER_TYPES.
	
	>>> N['dog'][0].getPointerTargets()[:5]
	[{noun: canine, canid}, {noun: Canis, genus Canis}, {noun: pack}, {noun: pooch, doggie, doggy, barker, bow-wow}, {noun: cur, mongrel, mutt}]
	>>> N['dog'][0].getPointerTargets(HYPERNYM)
	[{noun: canine, canid}]
	N(   R!   Rw   R|   R%   R-   R/   (   R%   R/   (    (    R+   R0   j  s     c         C   s   |  f S(   N(   R%   (   R%   (    (    R+   R7   z  s    c         C   s(   |  i   } t |  | i    | i j  S(   sb   Return 1 if any sense is tagged.
	
	>>> N['dog'][0].isTagged()
	1
	>>> N['dog'][1].isTagged()
	0
	N(   R%   t   wordR   R7   R)   (   R%   R   (    (    R+   R:     s     c         C   s   t  |  i |  i  S(   N(   RK   R%   R&   R(   (   R%   (    (    R+   RK     s    c         C   s;   |  i d  } t |  | d  p t | |   | |   S(   Nc         C   s   t  |  | i   d d   S(   Nt   testfnc         C   s   |  i | i j S(   N(   R   R&   t   b(   R   R   (    (    R+   R_     s    (   R   R<   Rs   R7   (   R<   Rs   (    (    R+   R     s    Rs   (   s   synset(   R%   Rs   R   R@   RA   t   cmp(   R%   RA   R   (    (    R+   RB     s    (   RW   RX   R.   RY   R,   R   RJ   RN   R-   R   R0   R   R7   R9   R:   RK   R   RB   (    (    (    R+   Rr      s    	
					Rw   c           B   s@  t  Z d  Z h  d e <d e <d e <d e <d e <d e <d e	 <d e
 <d	 e <d
 e <d e <d e <d e <d e <d e <d e <d e <d e <d e <d e <d e <d e <d e <d e <d e <d e <Z d   Z d   Z e Z  d   Z! e! Z" d   Z# d   Z$ d    Z% RS(!   s    A typed directional relationship between Senses or Synsets.
    
    Fields
    ------
      type : string
          One of POINTER_TYPES.
      pos : string
          The part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB.
    s   ~is   @it   !t   @t   ~t   =t   ^t   *t   >t   $s   #ms   #ss   #ps   %ms   %ss   %pt   &t   <s   \t   +s   ;cs   ;us   ;rs   -cs   -us   -rc         C   sy   | \ } } } } t i | |  _ | |  _ t	 |  |  _
 t |  |  _ t i | d  } | d ?|  _ | d @|  _ d  S(   Ni   i   i   (   t   pointerTupleRz   R3   R(   t   indicesRw   t   _POINTER_TYPE_TABLER%   t   sourceOffsetR"   t   targetOffsetR'   R   R]   R   t   targetIndex(   R%   R   R   R(   R3   R   Rz   (    (    R+   R,     s     	 c         C   s:   t  |  i |  i  } |  i o | |  i d Sn | Sd  S(   Ni   (   R2   R%   R(   R   Rs   R   (   R%   Rs   (    (    R+   t	   getSource  s    
c         C   s:   t  |  i |  i  } |  i o | |  i d Sn | Sd  S(   Ni   (   R2   R%   R(   R   Rs   R   (   R%   Rs   (    (    R+   t	   getTarget  s    
c         C   s   |  i d t |  i    S(   Ns    -> (   R%   Rz   RM   R|   (   R%   (    (    R+   RJ     s    c         C   s'   t  o t |   Sn d t |   d S(   NR   R   (   RL   RM   R%   (   R%   (    (    R+   RN     s    c         C   sR   t  |  | d  } | o | Sn |  i   } | d  } t | |   | |   S(   NR(   R   c         C   s   t  |  | i   d d   S(   NR   c         C   s   t  |  | d  S(   NRz   R   R   (   s   types   sourceIndexs   targetIndex(   R@   R   R   (   R   R   (    (    R+   R_     s    (   R   R<   Rs   R-   (   R<   Rs   (    (    R+   t   pointerIndex  s    (   s   poss   sourceOffset(   R@   R%   RA   t   difft   sourceRs   R   R   (   R%   RA   R   Rs   R   (    (    R+   RB     s    (&   RW   RX   R.   t   HASINSTANCEt   INSTANCEt   ANTONYMt   HYPERNYMt   HYPONYMt	   ATTRIBUTEt   ALSO_SEEt
   ENTAILMENTt   CAUSEt
   VERB_GROUPt   MEMBER_MERONYMt   SUBSTANCE_MERONYMt   PART_MERONYMt   MEMBER_HOLONYMt   SUBSTANCE_HOLONYMt   PART_HOLONYMt   SIMILARt   PARTICIPLE_OFt	   PERTAINYMt   FRAMESt   CLASSIF_CATEGORYt   CLASSIF_USAGEt   CLASSIF_REGIONALt   CLASS_CATEGORYt   CLASS_USAGEt   CLASS_REGIONALR   R,   R   R   R   R|   RJ   RN   RB   (    (    (    R+   Rw     s   	 					Rf   c           B   s&   t  Z h  Z g  Z d   Z d   Z RS(   Nc         C   s3   | |  _  | |  _ |  t i | <t i i |   d  S(   N(   R   R%   t   categoryRf   R   Rg   Ro   (   R%   R   R   (    (    R+   R,     s    		c         C   s   |  i S(   N(   R%   R   (   R%   (    (    R+   RJ     s    (   RW   RX   R   Rg   R,   RJ   (    (    (    R+   Rf     s   	c          C   sX   xQ t  t d  i   D]9 } t i |  \ } } }  t	 | t
 t |   d  q Wd  S(   Ns	   /lexnamesi   (   t   openR   t	   readlinest   lR   R   RT   R   R   Rf   t   PartsOfSpeechR"   (   R   R   RT   R   (    (    R+   t   setupLexnames  s     t
   Dictionaryc           B   s   t  Z d  Z d   Z d   Z e d  Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z e d
  Z d   Z d   Z d   Z RS(   s  A Dictionary contains all the Words in a given part of speech.
    This module defines four dictionaries, bound to N, V, ADJ, and ADV.
    
    Indexing a dictionary by a string retrieves the word named by that
    string, e.g. dict['dog'].  Indexing by an integer n retrieves the
    nth word, e.g.  dict[0].  Access by an arbitrary integer is very
    slow except in the special case where the words are accessed
    sequentially; this is to support the use of dictionaries as the
    range of a for statement and as the sequence argument to map and
    filter.

    Example
    -------
    >>> N['dog']
    dog(n.)
    
    Fields
    ------
      pos : string
          The part of speech -- one of NOUN, VERB, ADJECTIVE, ADVERB.
    c         C   s7   | |  _  t | |  |  _ t t |  t  |  _ d  S(   N(	   R(   R%   t
   _IndexFilet   filenameroott	   indexFileR   t   _dataFilePathnamet   _FILE_OPEN_MODEt   dataFile(   R%   R(   R   (    (    R+   R,      s    	 c         C   sh   h  t  d <t d <t d <t d <} | i |   o |  i d | |  Sn d |  i d |  i f S(   Nt   Nt   Vt   ADJt   ADVt   .s   <%s.%s instance for %s>R   (	   R   R   R   R   t   dictionaryVariablest   getR%   RX   R(   (   R%   R   (    (    R+   RN   &  s    *c         C   s|   t  i t  i |  d d  } |  i } | | |  i d  } t
 i | | f |  } | o | Sn t d | | f  d  S(   NR   R   c         C   s'   | p | i |   } | o
 t |  S(   N(   R   R   R   R   R   (   R   R   R   (    (    R+   t   loader/  s    s   %s is not in the %s database(   R   R$   t   lowerR&   R   R%   R(   R   R   R   t   _entityCacheR   R   t   KeyError(   R%   R&   R   R   R(   R   R   (    (    R+   RK   ,  s    	c         C   s4   |  i } | | |  i d  } t i | | f |  S(   Nc         C   s   t  |  | t | |   S(   N(   R[   R(   R3   t   _lineAtR   (   R(   R3   R   (    (    R+   R   :  s    (   R%   R(   R3   R   R   R   R   (   R%   R3   R   R(   (    (    R+   R2   8  s    	c         C   s   |  i i   d  S(   N(   R%   R   t   _buildIndexCacheFile(   R%   (    (    R+   R   >  s    c         C   s   d S(   s   Return false.  (This is to avoid scanning the whole index file
	to compute len when a Dictionary is used in test position.)
	
	>>> N and 'true'
	'true'
	i   N(    (   R%   (    (    R+   RO   D  s     c         C   s-   t  |  d  p t |  i  |  _ n |  i S(   s<   Return the number of index entries.
	
	>>> len(ADJ)
	21435
	t   lengthN(   R5   R%   RP   R   R   (   R%   (    (    R+   RQ   M  s     c         C   s   g  } t |  t d  j o# t |  t d  j o
 d  nh t |  t d  j oH t |  t d  j o/ x2 t | |  D] } | i |  |  q Wn t  | S(   Nt    t   unimplementedi   (	   t   resultsRz   R   R   Rn   RT   Ro   R%   t	   TypeError(   R%   R   R   RT   R   (    (    R+   RV   W  s    2
2 c         C   s   t  | t  o |  i |  Sn_ t  | t  o@ |  i | } |  i t i	 | t i
 | d   d d  |  Sn t d |  d S(   s   If index is a String, return the Word whose form is
	index.  If index is an integer n, return the Word
	indexed by the n'th Word in the Index file.
	
	>>> N['dog']
	dog(n.)
	>>> N[0]
	'hood(n.)
	R   R   s   %s is not a String or IntN(   R   RR   R   R%   RK   t   IntTypeR   R   R   R$   t   findR   (   R%   RR   R   (    (    R+   RS   b  s    	 3c         C   s*   y |  | SWn t j
 o | Sn Xd S(   sc   Return the Word whose form is _key_, or _default_.
	
	>>> N.get('dog')
	dog(n.)
	>>> N.get('inu')
	N(   R%   R   t   LookupErrort   default(   R%   R   R   (    (    R+   R   z  s
     c         C   s   |  i i   S(   sE   Return a sorted list of strings that index words in this
	dictionary.N(   R%   R   R>   (   R%   (    (    R+   R>     s     c         C   s   |  i i |  S(   su   Return true iff the argument indexes a word in this dictionary.
	
	>>> N.has_key('dog')
	1
	>>> N.has_key('inu')
	0
	N(   R%   R   t   has_keyR&   (   R%   R&   (    (    R+   R     s     c         C   s   d G|  GHt |  i i i t  } d } x | i   } | d j o Pn | d d j oq t	 i
 | t	 i | d   d d  } | d d j o% d | f Gd	 k } | i i   n | d } |  | q* q* W| i   d
 GHd	 S(   s>   Verify that index lookup can find each word in the index file.s	   Testing: i    i   R   R   R   i  s   %s...Ns   done.(   R%   R   R   t   fileR   R   t   countert   readlineR   R   R$   R   R   t   syst   stdoutt   flusht   close(   R%   R   R   R   R   R   (    (    R+   t	   _testKeys  s&     	   %	

(   RW   RX   R.   R,   RN   RY   RK   R2   R   RO   RQ   RV   RS   R   R>   R   R   (    (    (    R+   R     s    							
				R   c           B   sk   t  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z e d  Z	 d   Z
 d	   Z d
   Z RS(   sv   An _IndexFile is an implementation class that presents a
    Sequence and Dictionary interface to a sorted index file.c         C   s   | |  _  t t |  t  |  _ h  |  _ |  i   t	 i
 i t | d  |  _ y% d  k } | i |  i d  |  _ Wn n Xd  S(   Ns   .pyidxR	   (   R(   R%   R   t   _indexFilePathnameR   R   R   t   offsetLineCachet   rewindt   ost   patht   joinR   t	   shelfnamet   shelvet
   indexCache(   R%   R(   R   R   (    (    R+   R,     s    		
	c         C   sb   |  i i d  x9 |  i i   } |  i i   } | d d j o Pq q Wd |  _ | |  _ d  S(   Ni    i   R   (	   R%   R   t   seekt   tellR3   R   R   t	   nextIndext
   nextOffset(   R%   R   R3   (    (    R+   R     s      
	c         C   s   d S(   Ni   (    (   R%   (    (    R+   RO     s    c         C   sh   t  |  d  o t |  i  Sn |  i   d } x0 |  i i   } | d j o Pn | d } q4 W| S(   NR   i    i   R   (	   R5   R%   RP   R   R   t   linesR   R   R   (   R%   R   R  (    (    R+   RQ     s    
  c         C   s   d S(   Ni   (    (   R%   (    (    R+   RO     s    c         C   s2  t  | t  o< t |  d  o |  i | Sn t |  i | |  i d  Sn t  | t	  o t |  d  o |  i
 |  i |  Sn | |  i j  o |  i   n xs |  i | j ob |  i i |  i  |  i i   } | d j o t d  n |  i d |  _ |  i i   |  _ q W| Sn t d |  d  S(   NR   i   R   s   index out of rangei   s   %s is not a String or Int(   R   RR   R   R5   R%   R   t   binarySearchFileR   R   R   R   R>   R  R   R   R  R   R   t
   IndexErrorR  R   (   R%   RR   R   (    (    R+   RS     s&     c         C   s*   y |  | SWn t j
 o | Sn Xd  S(   N(   R%   R   R   R   (   R%   R   R   (    (    R+   R     s    c         C   s   t  |  d  o! |  i i   } | i   | Sng g  } |  i   xO |  i i   } | p Pn | i	 d d  d } | i | i d d   qD W| Sd  S(   NR   i   R   i    R   (   R5   R%   R   R>   t   sortR   R   R   R   R   R   Ro   R$   (   R%   R>   R   R   (    (    R+   R>     s    

   c         C   sI   | i d d  } t |  d  o |  i i |  Sn |  i |  d  j S(   NR   R   R   (   R   R$   R5   R%   R   R   R   RY   (   R%   R   (    (    R+   R     s    c   
      C   sh  d  k  } d  k } d |  i f G|  i d }	 z y | i |	  } Wn n X|  i   d } x |  i	 i
   |  i	 i   } } | p Pn | t i | d   } | d d j o% d | f Gd  k } | i i   n | | | <| d } q` W| i   | i |	 |  i  Wd  y | i |	  Wn n XXd GHy | i |  i d	  |  _ Wn t j
 o n Xd  S(
   Ns   Building %s:s   .tempi    i   R   i  s   %s...s   done.R	   (   R   R   R%   R   t   tempnameR   R   R   t   countR   R  R   R3   R   R   R   R   R   R   R   R   t   renamet   removet   error(
   R%   R	  R3   R   R   R   R   R   R   R  (    (    R+   R     sF    		 
   	

   (   RW   RX   R.   R,   R   RO   RQ   RS   RY   R   R>   R   R   (    (    (    R+   R     s    								
c         C   s   t  |  i |   S(   s2   Return a word with the given lexical form and pos.N(   t   _dictionaryForR(   RK   R&   (   R&   R(   (    (    R+   RK   <  s     c         C   s   t  |  |  | S(   s9   Lookup a sense by its sense number.  Used by repr(sense).N(   RK   R&   R(   t   senseno(   R&   R(   R  (    (    R+   R4   @  s     c         C   s   t  |   i |  S(   s5   Lookup a synset by its offset.  Used by repr(synset).N(   R  R(   R2   R3   (   R(   R3   (    (    R+   R2   D  s     c         C   s#   |  t j o t |  d  n |  S(   Ns    is not a pointer type(   R/   t   POINTER_TYPESR   (   R/   (    (    R+   R{   N  s    c         C   s   t  | d  p t t |   t |   Sn+ |  i | i j o t |  i | i  Sn x> | D]6 } t t |  |  t | |   } | o | Sq^ q^ Wd S(   sn   "Return -1, 0, or 1 according to a comparison first by type,
    then by class, and finally by each of fields.t	   __class__i    N(
   R5   R   R   Rz   R   R  t   fieldst   fieldt   getattrR   (   R   R   R  R  R   (    (    R+   R@   S  s      !c         C   s)   |  | j p t i |   t i |  j S(   s   Return true iff a and b have the same lowercase representation.
    
    >>> _equalsIgnoreCase('dog', 'Dog')
    1
    >>> _equalsIgnoreCase('dOg', 'DOG')
    1
    N(   R   R   R   R   (   R   R   (    (    R+   R   `  s     c         C   s_   t  i d j o8 t  i i t |  d  } t  i i |  o | SqH n t  i i t d |   S(   NR   R   s   .dats   data.(   R   R   (   R   R   R   R   R   R   t   exists(   R   R   (    (    R+   R   m  s
    c         C   s_   t  i d j o8 t  i i t |  d  } t  i i |  o | SqH n t  i i t d |   S(   NR   R   s   .idxs   index.(   s   doss   nt(   R   R   R   R   R   R   R  (   R   R   (    (    R+   R   t  s
    ic         C   s  d k  l }	 | d } t |  } d t i  |  i  |	 } } d } x| | j  o| | f } | | d } | i |  o | | \ }
 } np |  i t d | d   | d j o |  i   n |  i   |  i   }
 } | | j  o |
 | f | | <n |
 | j o) | | d j p
 t d  | d } nu | |  | j o | Sn\ | | j o) | | d j p
 t d  | d } n& | | j  o |
 t |  d } n | d } | | f } | | j o d  SqI qI Wd  S(   N(   s   ST_SIZER   i    i   i   s   infinite loop(   t   statt   ST_SIZER   RP   t   keylenR   R   R   t   startt   endt   currentDeptht	   lastStatet   middlet   cacheR   R3   R   R   t   maxR   R  t
   cacheDeptht   AssertionErrort	   thisStateRY   (   R   R   R  R  R  R  R!  R  R  R  R3   R   R  R  (    (    R+   R  {  s@    
 
c         C   s   |  i |  |  i   S(   N(   R   R   R3   R   (   R   R3   (    (    R+   R     s    c         C   sv   d } xi | D]a } | } | o | |  } n | o | |  j p | o | | |   o | Sn | d } q Wd S(   s  Return the index of key within sequence, using testfn for
    comparison and transforming items of sequence by keyfn first.
    
    >>> _index('e', 'hello')
    1
    >>> _index('E', 'hello', testfn=_equalsIgnoreCase)
    1
    >>> _index('x', 'hello')
    i    i   N(   RR   t   sequencet   elementt   valuet   keyfnR   R   RY   (   R   R"  R   R%  RR   R$  R#  (    (    R+   R     s    	  ,c         C   sQ   g  } x6 t d | | |  D] } | i |  | | | ! q W| |  | | f S(   s  Partition sequence into count subsequences of size
    length, and a remainder.
    
    Return (partitions, remainder), where partitions is a sequence of
    count subsequences of cardinality count, and
    apply(append, partitions) + remainder == sequence.i    N(   t
   partitionsRn   t   sizeR	  RR   Ro   R"  (   R"  R'  R	  RR   R&  (    (    R+   Ri     s      t	   _LRUCachec           B   s>   t  Z d  Z d   Z d   Z d   Z d   Z e d  Z RS(   s   A cache of values such that least recently used element is
    flushed when the cache fills.
    
    Private fields
    --------------
    entities
      a dict from key -> (value, timestamp)
    history
      is a dict from timestamp -> key
    nextTimeStamp
      is the timestamp to use with the next value that's added.
    oldestTimeStamp
      The timestamp of the oldest element (the next one to remove),
      or slightly lower than that.
    
      This lets us retrieve the key given the timestamp, and the
      timestamp given the key. (Also the value given either one.)
      That's necessary so that we can reorder the history given a key,
      and also manipulate the values dict given a timestamp.  #
    
      I haven't tried changing history to a List.  An earlier
      implementation of history as a List was slower than what's here,
      but the two implementations aren't directly comparable.c         C   s   | |  _  |  i   d  S(   N(   t   capacityt   thist   clear(   R*  R)  (    (    R+   R,     s    	c         C   s(   h  |  _ h  |  _ d |  _ d |  _ d  S(   Ni    i   (   R*  t   valuest   historyt   oldestTimestampt   nextTimestamp(   R*  (    (    R+   R+    s    			c         C   st   xm |  i |  i j  oY |  i i |  i  o/ |  i |  i } |  i |  i =|  i | =d  Sn |  i d |  _ q Wd  S(   Ni   (   R*  R.  R/  R-  R   R   R,  (   R*  R   (    (    R+   t   removeOldestEntry  s     
c         C   sS   | d j o |  i   n5 | |  _  x( t |  i  |  i  j o |  i   q' Wd  S(   Ni    (   R)  R*  R+  RP   R,  R0  (   R*  R)  (    (    R+   t   setCapacity  s    	 c         C   s   d  } |  i o7 |  i i |  } | o | \ } } |  i | =qG n | d  j o | o |   } n |  i d  j od |  i
 } |  i
 d |  _
 | | f |  i | <| |  i | <t |  i  |  i j o |  i   q n | S(   Ni   (   RY   R$  R*  R,  R   R   t   pairt	   timestampR-  t   loadfnR/  RP   R)  R0  (   R*  R   R4  R3  R$  R2  (    (    R+   R     s     
	(	   RW   RX   R.   R,   R+  R0  R1  RY   R   (    (    (    R+   R(    s    					t
   _NullCachec           B   s#   t  Z d  Z d   Z e d  Z RS(   sv   A NullCache implements the Cache interface (the interface that
    LRUCache implements), but doesn't store any values.c           C   s   d  S(   N(    (    (    (    R+   R+  +  s    c         C   s   | o |   S(   N(   R4  (   R*  R   R4  (    (    R+   R   .  s    (   RW   RX   R.   R+  RY   R   (    (    (    R+   R5  '  s    	i  c          C   s   t    }  d S(   s   Disable the entity cache.N(   R5  R   (   R   (    (    R+   t   disableCache5  s     c          C   s$   t  |  t  p t t  }  n d S(   s   Enable the entity cache.N(   R   R   t   LRUCacheR(  R'  (   R   (    (    R+   t   enableCache9  s     c           C   s   t  i   d S(   s   Clear the entity cache.N(   R   R+  (    (    (    R+   t
   clearCache>  s     c         C   s   t    t i |   d S(   s%   Set the capacity of the entity cache.N(   R8  R   R1  R)  (   R)  (    (    R+   t   setCacheCapacityB  s     t   adjt   advc          C   s   h  a  h  a xu t d f t d f t d f t d f f D]I \ } } t i	 |  }  x+ |  D]# } | t  | <| t  t i |  <qY Wq7 Wx( t D]  } | i t  | <| t | i <q Wd  S(   Ns	   noun n n.s	   verb v v.s   adjective adj adj. a ss   adverb adv adv. r(   t   _POSNormalizationTablet   _POStoDictionaryTableRE   RF   RG   RH   R(   t   abbreviationsR   R   R    t   tokent   uppert   DictionariesR   (   R    R?  R(   R@  R   (    (    R+   t   _initializePOSTables]  s     +  
 c         C   s0   t  i |   } | o | Sn t |  d  d  S(   Ns    is not a part of speech type(   R=  R   R(   t   normR   (   R(   RD  (    (    R+   R'   p  s    c         C   sB   t  |   }  t i |   } | d  j o t d |  d  n | S(   Ns   The s     dictionary has not been created(   R'   R(   R>  R   R   RY   t   RuntimeError(   R(   R   (    (    R+   R  v  s
    c          C   s   x t  D] }  |  i   q Wd  S(   N(   RB  R   R   (   R   (    (    R+   t   buildIndexFiles}  s     c          C   s   x t  D] }  |  i   q Wd  S(   N(   RB  t
   dictionaryR   (   RG  (    (    R+   R     s     c         C   s3   d  k  } d  k } |  o d  | _ n | i |  S(   N(   t   doctestR8   t   resetRY   t   mastert   testmod(   RI  RH  R8   (    (    R+   t   _test  s    (   s   doss   nt($   Ns   Something %ss   Somebody %ss   It is %sings   Something is %sing PPs%   Something %s something Adjective/Nouns   Something %s Adjective/Nouns   Somebody %s Adjectives   Somebody %s somethings   Somebody %s somebodys   Something %s somebodys   Something %s somethings   Something %s to somebodys   Somebody %s on somethings   Somebody %s somebody somethings!   Somebody %s something to somebodys#   Somebody %s something from somebodys#   Somebody %s somebody with somethings!   Somebody %s somebody of somethings!   Somebody %s something on somebodys   Somebody %s somebody PPs   Somebody %s something PPs   Somebody %s PPs   Somebody's (body part) %ss"   Somebody %s somebody to INFINITIVEs   Somebody %s somebody INFINITIVEs   Somebody %s that CLAUSEs   Somebody %s to somebodys   Somebody %s to INFINITIVEs   Somebody %s whether INFINITIVEs)   Somebody %s somebody into V-ing somethings$   Somebody %s something with somethings   Somebody %s INFINITIVEs   Somebody %s VERB-ings   It %s that CLAUSEs   Something %s INFINITIVE(g   R.   t
   __author__t   __version__R   R   t   environt   typesR   t   ListTypeR   t	   TupleTypeR   R   R    R   R   R   RL   t   _TraceLookupsR   RE   RF   RG   RH   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R   R   R   RY   t   ADJECTIVE_POSITIONSt   VERB_FRAME_STRINGSR   R[   Rr   Rw   Rf   R   R   R   RK   R4   R2   t   getwordt   getsenset	   getsynsetR{   R@   R   R   R   R  R   R   Ri   R(  R5  t   DEFAULT_CACHE_CAPACITYR   R6  R8  R9  R:  t   setCacheSizeR   R   R   R   RB  R=  R>  RC  R'   R  RF  R   RL  (^   RL   RS  R   R4   R   R   RV  R@   R   R9  R  R   RW  R    R   R   R   RT  R   R6  R   RQ  R   R   R   Rf   R   R   R   R   R   R   R   R   R  R   R   R   RB  R  RZ  R   R   R{   R:  RX  R'   RY  Rw   RL  R   R   R[   R   R   RE   R   R8  R   RF  R   R   R   RU  R   R2   R   R   RR  R   R   RH   R   R   RG   RC  Rr   R   RK   R   R   R   R   R5  R   RN  R   RF   R   RM  Ri   R   RO  R(  (    (    R+   t   ?%   s   		<9 N*\							+			G									