
    Of`                     F    S r SSKrSSKrSSKJr  SSKJr   " S S\5      rg)z
An NLTK interface to the VerbNet verb lexicon

For details about VerbNet see:
https://verbs.colorado.edu/~mpalmer/projects/verbnet.html
    N)defaultdict)XMLCorpusReaderc                   j   \ rS rSrSrS$S jr\R                  " S5      r \R                  " S5      r	 \R                  " S5      r
 S%S jrS%S	 jrS&S
 jrS rS%S jrS rS rS rS rS rS rS rS rS rS rS rS rS rS'S jrS'S jrS'S jrS'S jr S'S jr!S'S jr"S'S  jr#S'S! jr$S'S" jr%S#r&g)(VerbnetCorpusReader   a  
An NLTK interface to the VerbNet verb lexicon.

From the VerbNet site: "VerbNet (VN) (Kipper-Schuler 2006) is the largest
on-line verb lexicon currently available for English. It is a hierarchical
domain-independent, broad-coverage verb lexicon with mappings to other
lexical resources such as WordNet (Miller, 1990; Fellbaum, 1998), XTAG
(XTAG Research Group, 2001), and FrameNet (Baker et al., 1998)."

For details about VerbNet see:
https://verbs.colorado.edu/~mpalmer/projects/verbnet.html
c                     [         R                  " XX#5        [        [        5      U l         [        [        5      U l         0 U l         0 U l        U R                  5         g N)	r   __init__r   list_lemma_to_class_wordnet_to_class_class_to_fileid_shortid_to_longid_quick_index)selfrootfileids
wrap_etrees       </usr/lib/python3/dist-packages/nltk/corpus/reader/verbnet.pyr
   VerbnetCorpusReader.__init__%   s`      WA*40	& "-T!2	/ !#	B #%
 	    z([^\-\.]*)-([\d+.\-]+)$z
[\d+.\-]+$zH<MEMBER name="\??([^"]+)" wn="([^"]*)"[^>]+>|<VNSUBCLASS ID="([^"]+)"/?>Nc                    Uc#  [        U R                  R                  5       5      $ [        U[        5      (       a  U R                  U5      nUR                  S5       Vs/ s H  o"R                  S5      PM     sn$ s  snf )z`
Return a list of all verb lemmas that appear in any class, or
in the ``classid`` if specified.
MEMBERS/MEMBERname)sortedr   keys
isinstancestrvnclassfindallget)r   r   members      r   lemmasVerbnetCorpusReader.lemmasH   sk    
 ?$..33566 '3'',,w/5<__EU5VW5V6JJv&5VWWWs    A=c                     Uc#  [        U R                  R                  5       5      $ [        U[        5      (       a  U R                  U5      n[        S UR                  S5       5       / 5      $ )zd
Return a list of all wordnet identifiers that appear in any
class, or in ``classid`` if specified.
c              3   b   #    U  H%  nUR                  S S5      R                  5       v   M'     g7f)wn N)r!   split).0r"   s     r   	<genexpr>1VerbnetCorpusReader.wordnetids.<locals>.<genexpr>a   s.      "C JJtR(..00"Cs   -/r   )r   r   r   r   r   r   sumr    )r   r   s     r   
wordnetidsVerbnetCorpusReader.wordnetidsU   si    
 ?$0055788 '3'',,w/")//2B"C  r   c                    Ub6  U R                   R                  5        VVs/ s H  u  pVXc:X  d  M  UPM     snn$ Ub  U R                  U   $ Ub  U R                  U   $ UbB  U R	                  U5      nUR                  S5       Vs/ s H  nUR                  S5      PM     sn$ [        U R                   R                  5       5      $ s  snnf s  snf )a?  
Return a list of the VerbNet class identifiers.  If a file
identifier is specified, then return only the VerbNet class
identifiers for classes (and subclasses) defined by that file.
If a lemma is specified, then return only VerbNet class
identifiers for classes that contain that lemma as a member.
If a wordnetid is specified, then return only identifiers for
classes that contain that wordnetid as a member.  If a classid
is specified, then return only identifiers for subclasses of
the specified VerbNet class.
If nothing is specified, return all classids within VerbNet
SUBCLASSES/VNSUBCLASSID)	r   itemsr   r   r   r    r!   r   r   )	r   lemma	wordnetidfileidclassidcfxmltreesubclasss	            r   classidsVerbnetCorpusReader.classidsh   s     $($9$9$?$?$AQ$A&1Q[A$AQQ''..")))44 ll7+G !(0G H HH T" H 
 $//44677 Rs   CCCc                    XR                   ;   a  U R                  U5      $ U R                  U5      nX R                  ;   aw  U R                  U R                  U5         nU R                  U5      nX$R	                  S5      :X  a  U$ UR                  S5       H  nX%R	                  S5      :X  d  M  Us  $     e[        SU 35      e)aw  Returns VerbNet class ElementTree

Return an ElementTree containing the xml for the specified
VerbNet class.

:param fileid_or_classid: An identifier specifying which class
    should be returned.  Can be a file identifier (such as
    ``'put-9.1.xml'``), or a VerbNet class identifier (such as
    ``'put-9.1'``) or a short VerbNet class identifier (such as
    ``'9.1'``).
r2   z.//VNSUBCLASSzUnknown identifier )_fileidsxmllongidr   r!   r    
ValueError)r   fileid_or_classidr7   r6   treer;   s         r   r   VerbnetCorpusReader.vnclass   s     -88-.. ++/0+++**4;;w+?@F88F#D((4.( $_ =H,,t"44' !> !5 23D2EFGGr   c                     Uc  U R                   $ [        U[        5      (       a  U R                  U R	                  U5         /$ U Vs/ s H!  nU R                  U R	                  U5         PM#     sn$ s  snf )z
Return a list of fileids that make up this corpus.  If
``vnclass_ids`` is specified, then return the fileids that make
up the specified VerbNet class(es).
)r?   r   r   r   rA   )r   vnclass_ids
vnclass_ids      r   r   VerbnetCorpusReader.fileids   sy     == S))))$++k*BCDD #."-J %%dkk*&=>"-  s   (A3c           	      .   [        U[        5      (       a  U R                  U5      n/ nUR                  S5      nU HU  nUR	                  U R                  U5      U R                  U5      U R                  U5      U R                  U5      S.5        MW     U$ )a(  Given a VerbNet class, this method returns VerbNet frames

The members returned are:
1) Example
2) Description
3) Syntax
4) Semantics

:param vnclass: A VerbNet class identifier; or an ElementTree
    containing the xml contents of a VerbNet class.
:return: frames - a list of frame dictionaries
zFRAMES/FRAME)exampledescriptionsyntax	semantics)	r   r   r   r    append_get_example_within_frame_get_description_within_frame _get_syntactic_list_within_frame_get_semantics_within_frame)r   r   framesvnframesvnframes        r   rT   VerbnetCorpusReader.frames   s     gs##ll7+G??>2GMM#==gF#'#E#Eg#N"CCGL!%!A!A'!J	   r   c                     [        U[        5      (       a  U R                  U5      nUR                  S5       Vs/ s H  o"R	                  S5      PM     nnU$ s  snf )a  Returns subclass ids, if any exist

Given a VerbNet class, this method returns subclass ids (if they exist)
in a list of strings.

:param vnclass: A VerbNet class identifier; or an ElementTree
    containing the xml contents of a VerbNet class.
:return: list of subclasses
r1   r2   )r   r   r   r    r!   )r   r   r;   
subclassess       r   rY   VerbnetCorpusReader.subclasses   s\     gs##ll7+G 07?V/W
/W8LL/W 	 
 
s   Ac                 X   [        U[        5      (       a  U R                  U5      n/ nUR                  S5       Hg  nUR	                  UR                  S5      UR                  S5       Vs/ s H&  nUR                  S5      UR                  S5      S.PM(     snS.5        Mi     U$ s  snf )a*  Returns thematic roles participating in a VerbNet class

Members returned as part of roles are-
1) Type
2) Modifiers

:param vnclass: A VerbNet class identifier; or an ElementTree
    containing the xml contents of a VerbNet class.
:return: themroles: A list of thematic roles in the VerbNet class
zTHEMROLES/THEMROLEtypeSELRESTRS/SELRESTRValuevaluer\   )r\   	modifiers)r   r   r   r    rO   r!   )r   r   	themrolestrolerestrs        r   rb   VerbnetCorpusReader.themroles   s     gs##ll7+G	__%9:E!IIf- &+]]3G%H"%HE #())G"4eii>OP%H" ; "s   +-B'c                 l    U R                    H$  nU R                  U R                  U5      U5        M&     g)a  
Initialize the indexes ``_lemma_to_class``,
``_wordnet_to_class``, and ``_class_to_fileid`` by scanning
through the corpus fileids.  This is fast if ElementTree
uses the C implementation (<0.1 secs), but quite slow (>10 secs)
if only the python implementation is available.
N)r?   _index_helperr@   )r   r6   s     r   _indexVerbnetCorpusReader._index  s+     mmFtxx/8 $r   c                    UR                  S5      nX R                  U'   X0R                  U R                  U5      '   UR	                  S5       Hu  nU R
                  UR                  S5         R                  U5        UR                  SS5      R                  5        H!  nU R                  U   R                  U5        M#     Mw     UR	                  S5       H  nU R                  Xb5        M     g)zHelper for ``_index()``r2   r   r   r'   r(   r1   N)
r!   r   r   shortidr    r   rO   r)   r   rg   )r   r:   r6   r   r"   r'   r;   s          r   rg   !VerbnetCorpusReader._index_helper  s    ++d#)/g&9@W 56oo&67F  F!34;;GDjjr*002&&r*11': 3 8  (?@Hx0 Ar   c                    U R                    GH/  nUSS nXR                  U'   X R                  U R                  U5      '   U R	                  U5       nU R
                  R                  UR                  5       5       H  nUR                  5       nUS   b[  U R                  US      R                  U5        US   R                  5        H!  nU R                  U   R                  U5        M#     Mt  US   b5  XR                  US   '   US   nX R                  U R                  U5      '   M   S5       e   SSS5        GM2     g! , (       d  f       GME  = f)a  
Initialize the indexes ``_lemma_to_class``,
``_wordnet_to_class``, and ``_class_to_fileid`` by scanning
through the corpus fileids.  This doesn't do proper xml parsing,
but is good enough to find everything in the standard VerbNet
corpus -- and it runs about 30 times faster than xml parsing
(with the python ElementTree; only 2-3 times faster
if ElementTree uses the C implementation).
Nr         zunexpected match condition)r?   r   r   rk   open	_INDEX_REfinditerreadgroupsr   rO   r)   r   )r   r6   r   fpmru   r'   s          r   r    VerbnetCorpusReader._quick_index  s'    mmFSbkG-3!!'*=D##DLL$9:6"b00;AXXZFay,,,VAY7>>wG"()//"3B 2226==gF #4.;A--fQi8"()IP//W0EFB&BBu < #"	 $ #"s   C"E
E	c                    U R                   R                  U5      (       a  U$ U R                  R                  U5      (       d  [        SU-  5      e U R                  U   $ ! [
         a  n[        SU-  5      UeSnAff = f)zReturns longid of a VerbNet class

Given a short VerbNet class identifier (eg '37.10'), map it
to a long id (eg 'confess-37.10').  If ``shortid`` is already a
long id, then return it as-isvnclass identifier %r not foundN)
_LONGID_REmatch_SHORTID_RErB   r   KeyError)r   rk   es      r   rA   VerbnetCorpusReader.longid;  s     ??  ))N!!''00>HII	Q**733 	Q>HIqP	Qs   A! !
A?+A::A?c                     U R                   R                  U5      (       a  U$ U R                  R                  U5      nU(       a  UR                  S5      $ [	        SU-  5      e)zReturns shortid of a VerbNet class

Given a long VerbNet class identifier (eg 'confess-37.10'),
map it to a short id (eg '37.10').  If ``longid`` is already a
short id, then return it as-is.rp   rz   )r}   r|   r{   grouprB   )r   rA   rw   s      r   rk   VerbnetCorpusReader.shortidJ  sV     !!&))MOO!!&)771:>GHHr   c                 4   / nUR                  S5       H{  nUR                  S5       Vs/ s H&  nUR                  S5      UR                  S5      S.PM(     nnUR                  UR                  S5      UUR                  S5      S:H  S.5        M}     U$ s  snf )	a.  Returns semantics within a single frame

A utility function to retrieve semantics within a frame in VerbNet
Members of the semantics dictionary:
1) Predicate value
2) Arguments

:param vnframe: An ElementTree containing the xml contents of
    a VerbNet frame.
:return: semantics: semantics dictionary
zSEMANTICS/PREDzARGS/ARGr\   r`   )r\   r`   bool!)predicate_value	argumentsnegated)r    r!   rO   )r   rV   semantics_within_single_framepredargr   s         r   rS   /VerbnetCorpusReader._get_semantics_within_frame\  s     )+%OO$45D  <<
33C 37773CD3   *00'+xx'8!*#xx/36 6 -,s   -Bc                 N    UR                  S5      nUb  UR                  nU$ SnU$ )zReturns example within a frame

A utility function to retrieve an example within a frame in VerbNet.

:param vnframe: An ElementTree containing the xml contents of
    a VerbNet frame.
:return: example_text: The example sentence for this particular frame
zEXAMPLES/EXAMPLEr(   )findtext)r   rV   example_elementexample_texts       r   rP   -VerbnetCorpusReader._get_example_within_framew  s9     ",,'9:&*//L  Lr   c                 h    UR                  S5      nUR                  S   UR                  SS5      S.$ )a2  Returns member description within frame

A utility function to retrieve a description of participating members
within a frame in VerbNet.

:param vnframe: An ElementTree containing the xml contents of
    a VerbNet frame.
:return: description: a description dictionary with members - primary and secondary
DESCRIPTIONprimary	secondaryr(   )r   r   )r   attribr!   )r   rV   description_elements      r   rQ   1VerbnetCorpusReader._get_description_within_frame  s;     &ll=9*11)<,00bA
 	
r   c                    / nUR                  S5       H  nUR                  n[        5       nSUR                  ;   a  UR	                  S5      OSUS'   UR                  S5       Vs/ s H&  nUR	                  S5      UR	                  S5      S.PM(     snUS'   UR                  S	5       Vs/ s H&  nUR	                  S5      UR	                  S5      S.PM(     snUS
'   UR                  XES.5        M     U$ s  snf s  snf )a  Returns semantics within a frame

A utility function to retrieve semantics within a frame in VerbNet.
Members of the syntactic dictionary:
1) POS Tag
2) Modifiers

:param vnframe: An ElementTree containing the xml contents of
    a VerbNet frame.
:return: syntax_within_single_frame
SYNTAXr`   r(   r]   r^   r\   r_   	selrestrszSYNRESTRS/SYNRESTR	synrestrs)pos_tagra   )r   tagdictr   r!   r    rO   )r   rV   syntax_within_single_frameeltr   ra   rd   s          r   rR   4VerbnetCorpusReader._get_syntactic_list_within_frame  s     &("<<)CggGI5<

5J!1PRIg ![[)=>&>E  ))G,eii6GH>&Ik" ![[)=>&>E  ))G,eii6GH>&Ik" '--#< * *)&&s   &-C8,-C=c                 0   [        U[        5      (       a  U R                  U5      nUR                  S5      S-   nX R	                  USS9S-   -  nX R                  USS9S-   -  nUS-  nX R                  USS9S-   -  nUS-  nX R                  USS9-  nU$ )zReturns pretty printed version of a VerbNet class

Return a string containing a pretty-printed representation of
the given VerbNet class.

:param vnclass: A VerbNet class identifier; or an ElementTree
    containing the xml contents of a VerbNet class.
r2   
  )indentz  Thematic roles:
    z
  Frames:
)r   r   r   r!   pprint_subclassespprint_memberspprint_themrolespprint_frames)r   r   ss      r   pprintVerbnetCorpusReader.pprint  s     gs##ll7+GKK$	##GD#9D@@	   6==	""	""76":TAA	]	77r   c                     [        U[        5      (       a  U R                  U5      nU R                  U5      nU(       d  S/nSSR	                  U5      -   n[
        R                  " USX"S-   S9$ )a  Returns pretty printed version of subclasses of VerbNet class

Return a string containing a pretty-printed representation of
the given VerbNet class's subclasses.

:param vnclass: A VerbNet class identifier; or an ElementTree
    containing the xml contents of a VerbNet class.
(none)zSubclasses:  F   r   initial_indentsubsequent_indent)r   r   r   rY   jointextwrapfill)r   r   r   rY   r   s        r   r   %VerbnetCorpusReader.pprint_subclasses  sf     gs##ll7+G__W-
"JSXXj11}}r&TM
 	
r   c                     [        U[        5      (       a  U R                  U5      nU R                  U5      nU(       d  S/nSSR	                  U5      -   n[
        R                  " USX"S-   S9$ )a  Returns pretty printed version of members in a VerbNet class

Return a string containing a pretty-printed representation of
the given VerbNet class's member verbs.

:param vnclass: A VerbNet class identifier; or an ElementTree
    containing the xml contents of a VerbNet class.
r   z	Members: r   r   r   r   )r   r   r   r#   r   r   r   )r   r   r   membersr   s        r   r   "VerbnetCorpusReader.pprint_members  sf     gs##ll7+G++g&jG#((7++}}r&TM
 	
r   c                    [        U[        5      (       a  U R                  U5      n/ nU R                  U5       Hs  nUS-   UR	                  S5      -   nUS    Vs/ s H  nUS   US   -   PM     nnU(       a#  USR                  SR                  U5      5      -  nUR                  U5        Mu     SR                  U5      $ s  snf )a   Returns pretty printed version of thematic roles in a VerbNet class

Return a string containing a pretty-printed representation of
the given VerbNet class's thematic roles.

:param vnclass: A VerbNet class identifier; or an ElementTree
    containing the xml contents of a VerbNet class.
* r\   ra   r`   [{}]r   r   )r   r   r   rb   r!   formatr   rO   )r   r   r   piecesthemrolepiecemodifierra   s           r   r   $VerbnetCorpusReader.pprint_themroles  s     gs##ll7+Gw/HTMHLL$88E !) 5 5H !HV$44 5   sxx	':;;MM%  0 yy  s   Cc                     [        U[        5      (       a  U R                  U5      n/ nU R                  U5       H#  nUR	                  U R                  XB5      5        M%     SR                  U5      $ )a  Returns pretty version of all frames in a VerbNet class

Return a string containing a pretty-printed representation of
the list of frames within the VerbNet class.

:param vnclass: A VerbNet class identifier; or an ElementTree
    containing the xml contents of a VerbNet class.
r   )r   r   r   rT   rO   _pprint_single_framer   )r   r   r   r   rV   s        r   r   !VerbnetCorpusReader.pprint_frames  s]     gs##ll7+G{{7+GMM$33GDE ,yy  r   c                     U R                  X5      S-   nX0R                  XS-   5      S-   -  nUU R                  XS-   5      S-   -  nX2S-   -  nX0R                  XS-   5      -  nU$ )zReturns pretty printed version of a single frame in a VerbNet class

Returns a string containing a pretty-printed representation of
the given frame.

:param vnframe: An ElementTree containing the xml contents of
    a VerbNet frame.
r   r   z
  Syntax: z  Semantics:
r   ) _pprint_description_within_frame_pprint_example_within_frame_pprint_syntax_within_frame_pprint_semantics_within_frame)r   rV   r   frame_strings       r   r   (VerbnetCorpusReader._pprint_single_frame  s     <<WMPTT99'C<PSWWW,,W|6KLtS	
 	!111;;Gf_UUr   c                 .    US   (       a  US-   US   -   $ g)zReturns pretty printed version of example within frame in a VerbNet class

Return a string containing a pretty-printed representation of
the given VerbNet frame example.

:param vnframe: An ElementTree containing the xml contents of
    a Verbnet frame.
rK   z
 Example: N )r   rV   r   s      r   r   0VerbnetCorpusReader._pprint_example_within_frame0  s&     9L(79+=== r   c                 h    X!S   S   -   nUS   S   (       a  USR                  US   S   5      -  nU$ )zReturns pretty printed version of a VerbNet frame description

Return a string containing a pretty-printed representation of
the given VerbNet frame description.

:param vnframe: An ElementTree containing the xml contents of
    a VerbNet frame.
rL   r   r   z ({}))r   )r   rV   r   rL   s       r   r   4VerbnetCorpusReader._pprint_description_within_frame<  sF     }5i@@=!+.7>>'-*@*MNNKr   c           
         / nUS    H  nUS   n/ nSUS   ;   a$  US   S   (       a  UR                  US   S   5        UUS   S   US   S   -    Vs/ s H  nSR                  US   US   5      PM     sn-  nU(       a#  US	R                  S
R                  U5      5      -  nUR                  U5        M     US
R                  U5      -   $ s  snf )zReturns pretty printed version of syntax within a frame in a VerbNet class

Return a string containing a pretty-printed representation of
the given VerbNet frame syntax.

:param vnframe: An ElementTree containing the xml contents of
    a VerbNet frame.
rM   r   r`   ra   r   r   z{}{}r\   r   r   )rO   r   r   )r   rV   r   r   elementr   modifier_listrd   s           r   r   /VerbnetCorpusReader._pprint_syntax_within_frameJ  s     x(GI&EM'+..7;3G3P$$W[%9'%BC K(5k*;788  eGneFm<8 M sxx'>??MM%  )  (((s   "Cc           	         ^ / nUS    HQ  nUS    Vs/ s H  oUS   PM	     nnUR                  US   (       a  SOS US    SS	R                  U5       S
35        MS     SR                  U4S jU 5       5      $ s  snf )a  Returns a pretty printed version of semantics within frame in a VerbNet class

Return a string containing a pretty-printed representation of
the given VerbNet frame semantics.

:param vnframe: An ElementTree containing the xml contents of
    a VerbNet frame.
rN   r   r`   r      ¬r(   r   (z, )r   c              3   2   >#    U  H  nT S U 3v   M     g7f)r   Nr   )r*   r   r   s     r   r+   EVerbnetCorpusReader._pprint_semantics_within_frame.<locals>.<genexpr>u  s     B6%F82eW-6s   )rO   r   )r   rV   r   r   	predicateargumentr   s     `    r   r   2VerbnetCorpusReader._pprint_semantics_within_framef  s      -I;D[;QR;Qx'*;QIRMM$Y/4R8CT9U8VVWX\XaXabkXlWmmno .
 yyB6BBB	 Ss   A9)r   r   r   r   )Fr	   )NNNN)r(   )'__name__
__module____qualname____firstlineno____doc__r
   recompiler{   r}   rr   r#   r.   r<   r   r   rT   rY   rb   rh   rg   r   rA   rk   rS   rP   rQ   rR   r   r   r   r   r   r   r   r   r   r   __static_attributes__r   r   r   r   r      s    . 67JB**]+K2

WI!X&88HB 8$>	9
1CDQI$-6 
 *D*
(
(!0! $
>)8Cr   r   )r   r   r   collectionsr   nltk.corpus.reader.xmldocsr   r   r   r   r   <module>r      s(    
  # 6_	C/ _	Cr   