
    '[fpE                        d dl Z d dlmZ d dlmZ d dlT d dlT d dlmZ d dl	m
Z
  G d de          Z G d	 d
          Z G d d          Z G d de          Z G d de          Ze G d de                      Z G d d          ZdS )    N)total_ordering)ElementTree)*)raise_unorderable_types)Treec                   R    e Zd ZdZ	 	 	 	 	 ddZddZd Zd Zdd	Zd
 Z	d fdZ
dS )PropbankCorpusReadera  
    Corpus reader for the propbank corpus, which augments the Penn
    Treebank with information about the predicate argument structure
    of every verb instance.  The corpus consists of two parts: the
    predicate-argument annotations themselves, and a set of "frameset
    files" which define the argument labels used by the annotations,
    on a per-verb basis.  Each "frameset file" contains one or more
    predicates, such as ``'turn'`` or ``'turn_on'``, each of which is
    divided into coarse-grained word senses called "rolesets".  For
    each "roleset", the frameset file provides descriptions of the
    argument roles, along with examples.
     Nutf8c                     t          |t                    rt          ||          }t          |          }t                              | |||g|z   |           || _        || _        || _        || _	        || _
        dS )a  
        :param root: The root directory for this corpus.
        :param propfile: The name of the file containing the predicate-
            argument annotations (relative to ``root``).
        :param framefiles: A list or regexp specifying the frameset
            fileids for this corpus.
        :param parse_fileid_xform: A transform that should be applied
            to the fileids in this corpus.  This should be a function
            of one argument (a fileid) that returns a string (the new
            fileid).
        :param parse_corpus: The corpus containing the parse trees
            corresponding to this corpus.  These parse trees are
            necessary to resolve the tree pointers used by propbank.
        N)
isinstancestrfind_corpus_fileidslistCorpusReader__init__	_propfile_framefiles
_verbsfile_parse_fileid_xform_parse_corpus)selfrootpropfile
framefiles	verbsfileparse_fileid_xformparse_corpusencodings           O/var/www/piapp/venv/lib/python3.11/site-packages/nltk/corpus/reader/propbank.pyr   zPropbankCorpusReader.__init__    s    2 j#&& 	?,T:>>J*%%
dD8Y*?**LhWWW "%##5 )    c                      i fdd<   t                                j                   fd                      j                            S )z
        :return: a corpus view that acts as a list of
            ``PropBankInstance`` objects, one for each noun in the corpus.
        Nc                     | j         k    S N)baseform)instr%   s    r    <lambda>z0PropbankCorpusReader.instances.<locals>.<lambda>M   s    T]h5N r!   instance_filterc                       j         | fi S r$   )_read_instance_block)streamkwargsr   s    r    r'   z0PropbankCorpusReader.instances.<locals>.<lambda>P   s    444VFFvFF r!   r   )StreamBackedCorpusViewabspathr   r   )r   r%   r,   s   ``@r    	instanceszPropbankCorpusReader.instancesF   sn    
 (N(N(N(NF$%%LL((FFFFF]]4>22
 
 
 	
r!   c                     t          |                     | j                  t          |                     | j                            S )z
        :return: a corpus view that acts as a list of strings, one for
            each line in the predicate-argument annotation file.
        r-   )r.   r/   r   read_line_blockr   r   s    r    lineszPropbankCorpusReader.linesT   s@    
 &LL((]]4>22
 
 
 	
r!   c                    |                     d          d         }d|z  }|| j        vrt          d|z            |                     |                                          5 }t          j        |                                          }ddd           n# 1 swxY w Y   |                    d          D ]}|j	        d         |k    r|c S t          d| d	|           )
zE
        :return: the xml description for the given roleset.
        .r   frames/%s.xmlFrameset file for %s not foundNpredicate/rolesetidzRoleset z not found in )
splitr   
ValueErrorr/   openr   parsegetrootfindallattrib)r   
roleset_idr%   	framefilefpetreerolesets          r    rF   zPropbankCorpusReader.roleset_   s1    ##C((+#h.	D,,,=
JKKK \\)$$))++ 	4r%b))1133E	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4}}%899 	 	G~d#z11 2IJIIiIIJJJs   #'BBBc                    |$d|z  }|| j         vrt          d|z            |g}n| j         }g }|D ]}|                     |                                          5 }t	          j        |                                          }ddd           n# 1 swxY w Y   |                    |                    d                     t          |          S )zA
        :return: list of xml descriptions for rolesets.
        Nr7   r8   r9   )
r   r<   r/   r=   r   r>   r?   appendr@   LazyConcatenation)r   r%   rC   r   rsetsrD   rE   s          r    rolesetszPropbankCorpusReader.rolesetsq   s    '(2I 000 !AH!LMMM#JJ)J# 	= 	=I i((--// 82#)"--55778 8 8 8 8 8 8 8 8 8 8 8 8 8 8LL':;;<<<< '''s   'BB	B	c                     t          |                     | j                  t          |                     | j                            S )z
        :return: a corpus view that acts as a list of all verb lemmas
            in this corpus (from the verbs.txt file).
        r-   )r.   r/   r   r2   r   r3   s    r    verbszPropbankCorpusReader.verbs   s@    
 &LL))]]4?33
 
 
 	
r!   c                     dS )NT )r&   s    r    r'   zPropbankCorpusReader.<lambda>   s     r!   c                 
   g }t          d          D ]p}|                                                                }|rFt                              || j        | j                  } ||          r|                    |           q|S )Nd   )rangereadlinestripPropbankInstancer>   r   r   rH   )r   r+   r(   blockiliner&   s          r    r*   z)PropbankCorpusReader._read_instance_block   s     s 	' 	'A??$$**,,D ''--$2D4F  #?4(( 'LL&&&r!   )r
   NNNr   r$   )__name__
__module____qualname____doc__r   r0   r4   rF   rK   rM   r*   rO   r!   r    r	   r	      s         " $* $* $* $*L
 
 
 
	
 	
 	
K K K$( ( ( (*	
 	
 	
 <M;L      r!   r	   c                       e Zd Z	 ddZed             Zed             Zed             Zd Zd Z	d Z
 ee
d	
          Zedd            ZdS )rU   Nc
                     || _         	 || _        	 || _        	 || _        	 || _        	 || _        	 || _        	 t          |          | _        	 |	| _	        d S r$   )
fileidsentnumwordnumtaggerrF   
inflection	predicatetuple	argumentsr   )
r   r_   r`   ra   rb   rF   rc   rd   rf   r   s
             r    r   zPropbankInstance.__init__   s     	  	& 	D 	: 	2 %	& #	@ y))	 )	. 	.r!   c                 B    | j                             d          d         S )zThe baseform of the predicate.r6   r   rF   r;   r3   s    r    r%   zPropbankInstance.baseform        |!!#&&q))r!   c                 B    | j                             d          d         S )z"The sense number of the predicate.r6      rh   r3   s    r    sensenumberzPropbankInstance.sensenumber   ri   r!   c                     dS )zIdentifier of the predicate.relrO   r3   s    r    predidzPropbankInstance.predid   s	     ur!   c                 N    d                     | j        | j        | j                  S )Nz(<PropbankInstance: {}, sent {}, word {}>)formatr_   r`   ra   r3   s    r    __repr__zPropbankInstance.__repr__   s)    9@@KLL
 
 	
r!   c                     d                     | j        | j        | j        | j        | j        | j                  }| j        | j        dffz   }t          |          D ]\  }}|d| d| z  }|S )Nz{} {} {} {} {} {}rn    -)
rq   r_   r`   ra   rb   rF   rc   rf   rd   sorted)r   sitemsarglocargids        r    __str__zPropbankInstance.__str__   s    &&KLLKLO
 
 4>5"9!;;%e}} 	& 	&OVU%V%%e%%%AAr!   c                     | j         d S | j        | j                                         vrd S | j                             | j                  | j                 S r$   )r   r_   fileidsparsed_sentsr`   r3   s    r    	_get_treezPropbankInstance._get_tree  sQ    $4;d/7799994 --dk::4<HHr!   zs
        The parse tree corresponding to this instance, or None if
        the corresponding tree is not available.)docc                    |                                  }t          |          dk     rt          d| z            |d d         \  }}}}}}	d |dd          D             }
d |dd          D             }t          |
          dk    rt          d| z            | ||          }t          |          }t          |          }t                              |	          }	t                              |
d         d d                   }g }|D ]J}|                     d	d          \  }}|                    t                              |          |f           Kt          ||||||	|||	  	        S )
N   z!Badly formatted propbank line: %r   c                 <    g | ]}|                     d           |S z-relendswith.0ps     r    
<listcomp>z*PropbankInstance.parse.<locals>.<listcomp>  s)    ;;;Q

6(:(:;q;;;r!   c                 <    g | ]}|                     d           |S r   r   r   s     r    r   z*PropbankInstance.parse.<locals>.<listcomp>  s)    @@@aQZZ-?-?@@@@r!   rk   r   ru   )	r;   lenr<   intPropbankInflectionr>   PropbankTreePointerrH   rU   )rw   r   r   piecesr_   r`   ra   rb   rF   rc   rn   argsrd   rf   argry   rz   s                    r    r>   zPropbankInstance.parse  s   v;;??@1DEEE CI!*?'67J;;&*;;;@@6!"":@@@s88q==@1DEEE )''//F g,,g,, (--j99
 (--c!fSbSk::	 	 	I 	ICIIc1--MFE177??GHHHH  

 

 
	
r!   r$   )NN)rY   rZ   r[   r   propertyr%   rl   ro   rr   r{   r   treestaticmethodr>   rO   r!   r    rU   rU      s         4. 4. 4. 4.l * * X* * * X*   X
 
 
  I I I 84  D +
 +
 +
 \+
 +
 +
r!   rU   c                       e Zd ZdZd ZdS )PropbankPointera  
    A pointer used by propbank to identify one or more constituents in
    a parse tree.  ``PropbankPointer`` is an abstract base class with
    three concrete subclasses:

      - ``PropbankTreePointer`` is used to point to single constituents.
      - ``PropbankSplitTreePointer`` is used to point to 'split'
        constituents, which consist of a sequence of two or more
        ``PropbankTreePointer`` pointers.
      - ``PropbankChainTreePointer`` is used to point to entire trace
        chains in a tree.  It consists of a sequence of pieces, which
        can be ``PropbankTreePointer`` or ``PropbankSplitTreePointer`` pointers.
    c                 B    | j         t          k    rt                      d S r$   )	__class__r   NotImplementedErrorr3   s    r    r   zPropbankPointer.__init__M  s#    >_,,%''' -,r!   N)rY   rZ   r[   r\   r   rO   r!   r    r   r   >  s-         ( ( ( ( (r!   r   c                   &    e Zd Zd Zd Zd Zd ZdS )PropbankChainTreePointerc                     || _         d S r$   r   r   r   s     r    r   z!PropbankChainTreePointer.__init__S  s    	0 	0r!   c                 J    d                     d | j        D                       S )Nr   c              3       K   | ]	}d |z  V  
dS z%sNrO   r   s     r    	<genexpr>z3PropbankChainTreePointer.__str__.<locals>.<genexpr>Z  &      66Qq666666r!   joinr   r3   s    r    r{   z PropbankChainTreePointer.__str__Y  %    xx66$+666666r!   c                     d| z  S )Nz<PropbankChainTreePointer: %s>rO   r3   s    r    rr   z!PropbankChainTreePointer.__repr__\      /$66r!   c                 h    t          d          t          dfd| j        D                       S )NParse tree not availablez*CHAIN*c                 :    g | ]}|                               S rO   selectr   r   r   s     r    r   z3PropbankChainTreePointer.select.<locals>.<listcomp>b  #    DDD1DDDr!   r<   r   r   r   r   s    `r    r   zPropbankChainTreePointer.select_  >    <7888IDDDDDDDEEEr!   NrY   rZ   r[   r   r{   rr   r   rO   r!   r    r   r   R  sU        0 0 07 7 77 7 7F F F F Fr!   r   c                   &    e Zd Zd Zd Zd Zd ZdS )PropbankSplitTreePointerc                     || _         d S r$   r   r   s     r    r   z!PropbankSplitTreePointer.__init__f  s    	4 	4r!   c                 J    d                     d | j        D                       S )N,c              3       K   | ]	}d |z  V  
dS r   rO   r   s     r    r   z3PropbankSplitTreePointer.__str__.<locals>.<genexpr>l  r   r!   r   r3   s    r    r{   z PropbankSplitTreePointer.__str__k  r   r!   c                     d| z  S )Nz<PropbankSplitTreePointer: %s>rO   r3   s    r    rr   z!PropbankSplitTreePointer.__repr__n  r   r!   c                 h    t          d          t          dfd| j        D                       S )Nr   z*SPLIT*c                 :    g | ]}|                               S rO   r   r   s     r    r   z3PropbankSplitTreePointer.select.<locals>.<listcomp>t  r   r!   r   r   s    `r    r   zPropbankSplitTreePointer.selectq  r   r!   Nr   rO   r!   r    r   r   e  sU        4 4 4
7 7 77 7 7F F F F Fr!   r   c                   X    e Zd ZdZd Zed             Zd Zd Zd Z	d Z
d Zd	 Zd
 ZdS )r   z@
    wordnum:height*wordnum:height*...
    wordnum:height,

    c                 "    || _         || _        d S r$   ra   height)r   ra   r   s      r    r   zPropbankTreePointer.__init__  s    r!   c                    |                      d          }t          |          dk    rt          d |D                       S |                      d          }t          |          dk    rt          d |D                       S |                      d          }t          |          dk    rt	          d| z            t          t          |d	                   t          |d                             S )
Nr   rk   c                 B    g | ]}t                               |          S rO   r   r>   r   elts     r    r   z-PropbankTreePointer.parse.<locals>.<listcomp>  '    BBBC$**3//BBBr!   r   c                 B    g | ]}t                               |          S rO   r   r   s     r    r   z-PropbankTreePointer.parse.<locals>.<listcomp>  r   r!   :   zbad propbank pointer %rr   )r;   r   r   r   r<   r   r   )rw   r   s     r    r>   zPropbankTreePointer.parse  s     v;;??+BB6BBB  
 v;;??+BB6BBB  
 v;;!6:;;;"3vay>>3vay>>BBBr!   c                 $    | j          d| j         S )Nr   r   r3   s    r    r{   zPropbankTreePointer.__str__  s    ,.....r!   c                 $    d| j         | j        fz  S )NzPropbankTreePointer(%d, %d)r   r3   s    r    rr   zPropbankTreePointer.__repr__  s    ,dk/JJJr!   c                     t          |t          t          f          r)|j        d         }t          |t          t          f          )t          |t                    s| |u S | j        |j        k    o| j        |j        k    S Nr   )r   r   r   r   r   ra   r   r   others     r    __eq__zPropbankTreePointer.__eq__  s}    !9;S TUU 	$LOE !9;S TUU 	$ %!455 	!5= |u},L1LLr!   c                     | |k     S r$   rO   r   s     r    __ne__zPropbankTreePointer.__ne__  s    5=  r!   c                 6   t          |t          t          f          r)|j        d         }t          |t          t          f          )t          |t                    s t          |           t          |          k     S | j        | j         f|j        |j         fk     S r   )r   r   r   r   r   r:   ra   r   r   s     r    __lt__zPropbankTreePointer.__lt__  s    !9;S TUU 	$LOE !9;S TUU 	$ %!455 	(d88bii''t{l+u}u|m.LLLr!   c                 Z    |t          d          ||                     |                   S )Nr   )r<   treeposr   s     r    r   zPropbankTreePointer.select  s-    <7888DLL&&''r!   c                    |t          d          |g}g }d}	 t          |d         t                    rt          |          t          |          k     r|                    d           n|dxx         dz  cc<   |d         t          |d                   k     r(|                    |d         |d                             n||                                 |                                 nS|| j        k    r/t          |dt          |          | j        z
  dz
                     S |dz  }|                                 &)z}
        Convert this pointer to a standard 'tree position' pointer,
        given that it points to the given tree.
        Nr   r   Trk   )	r<   r   r   r   rH   popra   re   r   )r   r   stackr   ra   s        r    r   zPropbankTreePointer.treepos  s4   
 <7888	 %)T**  w<<#e**,,NN1%%%%BKKK1$KKK2;U2Y//LLr72;!78888 IIKKKKKMMMM dl** )I3w<<$++E+I)I!JKKKqLGIIKKK+	 r!   N)rY   rZ   r[   r\   r   r   r>   r{   rr   r   r   r   r   r   rO   r!   r    r   r   w  s            C C \C*/ / /K K KM M M! ! !M M M( ( (
              r!   r   c                       e 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dZd Zd Z ej        d          Zed             ZdS )r   rW   gr   vfnob3aru   c                 L    || _         || _        || _        || _        || _        d S r$   formtenseaspectpersonvoice)r   r   r   r   r   r   s         r    r   zPropbankInflection.__init__  s)    	



r!   c                 P    | j         | j        z   | j        z   | j        z   | j        z   S r$   r   r3   s    r    r{   zPropbankInflection.__str__  s&    y4:%3dkADJNNr!   c                     d| z  S )Nz<PropbankInflection: %s>rO   r3   s    r    rr   zPropbankInflection.__repr__  s    )D00r!   z"[igpv\-][fpn\-][pob\-][3\-][ap\-]$c                     t          | t                    st          d          t          |           dk    st          j                            |           st          d| z            t	          |  S )Nzexpected a string   z!Bad propbank inflection string %r)r   r   	TypeErrorr   r   	_VALIDATEmatchr<   )rw   s    r    r>   zPropbankInflection.parse  sg    !S!! 	1/000q66Q;;0:@@CC;@1DEEE!1%%r!   N)ru   ru   ru   ru   ru   )rY   rZ   r[   
INFINITIVEGERUND
PARTICIPLEFINITEFUTUREPASTPRESENTPERFECTPROGRESSIVEPERFECT_AND_PROGRESSIVETHIRD_PERSONACTIVEPASSIVENONEr   r{   rr   recompiler   r   r>   rO   r!   r    r   r     s        JFJFFDGGK!LFGD   O O O1 1 1 
@AAI& & \& & &r!   r   )r  	functoolsr   	xml.etreer   nltk.corpus.reader.apinltk.corpus.reader.utilnltk.internalsr   	nltk.treer   r   r	   rU   r   r   r   r   r   rO   r!   r    <module>r     s   
			 $ $ $ $ $ $ ! ! ! ! ! ! $ $ $ $ % % % % 2 2 2 2 2 2      L L L L L< L L LhU
 U
 U
 U
 U
 U
 U
 U
p( ( ( ( ( ( ( ((F F F F F F F F&F F F F F F F F$ a  a  a  a  a / a  a  a H,& ,& ,& ,& ,& ,& ,& ,& ,& ,&r!   