o
    –h  ã                   @   sD   d dl mZ G dd„ dedg d¢ƒƒZG dd„ dedg d¢ƒƒZdS )	é    )Ú
namedtuplec                   @   sˆ   e Zd ZdZdd„ Zdd„ Zdd„ Zedd	„ ƒZd
d„ Z	edd„ ƒZ
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚStatea  
    Represents a partially completed transition parse

    Includes stack/buffers for unused words, already executed transitions, and partially build constituents
    At training time, also keeps track of the gold data we are reparsing

    num_opens is useful for tracking
       1) if the parser is in a stuck state where it is making infinite opens
       2) if a close transition is impossible because there are no previous opens

    sentence_length tracks how long the sentence is so we abort if we go infinite

    non-stack information such as sentence_length and num_opens
    will be copied from the original_state if possible, with the
    exact arguments overriding the values in the original_state

    gold_tree: the original tree, if made from a gold tree.  might be None
    gold_sequence: the original transition sequence, if available
    Note that at runtime, gold values will not be available

    word_position tracks where in the word queue we are.  cheaper than
      manipulating the list itself.  this can be handled differently
      from transitions and constituents as it is processed once
      at the start of parsing

    The word_queue should have both a start and an end word.
    Those can be None in the case of the endpoints if they are unused.
    c                 C   s   | j | jkS ©N)Úword_positionÚsentence_length©Úself© r	   ú[/var/www/html/env_mimamsha/lib/python3.10/site-packages/stanza/models/constituency/state.pyÚempty_word_queue!   ó   zState.empty_word_queuec                 C   ó   | j jd u S r   )ÚtransitionsÚparentr   r	   r	   r
   Úempty_transitions&   r   zState.empty_transitionsc                 C   s   | j jdkS )Né   ©ÚconstituentsÚlengthr   r	   r	   r
   Úhas_one_constituent+   ó   zState.has_one_constituentc                 C   r   r   )r   r   r   r	   r	   r
   Úempty_constituents/   r   zState.empty_constituentsc                 C   ó   | j jd S ©Né   r   r   r	   r	   r
   Únum_constituents3   ó   zState.num_constituentsc                 C   r   r   )r   r   r   r	   r	   r
   Únum_transitions6   r   zState.num_transitionsc                 C   s   | j |d  S r   ©Ú
word_queue)r   Úposr	   r	   r
   Úget_word;   s   zState.get_wordc                 C   s$   |   ¡ o|  ¡ o| | j¡j|jv S r   )r   r   Úget_top_constituentr   ÚlabelÚroot_labels©r   Úmodelr	   r	   r
   Úfinished@   s   $zState.finishedc                 C   s   |  | j¡S r   )r"   r   r%   r	   r	   r
   Úget_treeC   r   zState.get_treec                 C   ó@   g }| j }|jd ur| | |¡¡ |j}|jd us
tt|ƒƒS r   )r   r   ÚappendÚget_top_transitionÚlistÚreversed)r   r&   Úall_transitionsr   r	   r	   r
   r.   F   ó   

þzState.all_transitionsc                 C   r)   r   )r   r   r*   r"   r,   r-   )r   r&   Úall_constituentsr   r	   r	   r
   r0   O   r/   zState.all_constituentsc                    s   ‡ fdd„| j D ƒS )Nc                    s   g | ]}ˆ   |¡‘qS r	   )r!   )Ú.0Úx©r&   r	   r
   Ú
<listcomp>Y   s    z#State.all_words.<locals>.<listcomp>r   r%   r	   r3   r
   Ú	all_wordsX   ó   zState.all_wordsc                 C   s4   dt |  |¡ƒt |  |¡ƒt |  |¡ƒ| j| jf S )NzVState(
  buffer:%s
  transitions:%s
  constituents:%s
  word_position:%d num_opens:%d))Ústrr5   r.   r0   r   Ú	num_opensr%   r	   r	   r
   Ú	to_string[   s   4zState.to_stringc                 C   s    dt | jƒt | jƒt | jƒf S )Nz6State(
  buffer:%s
  transitions:%s
  constituents:%s))r7   r   r   r   r   r	   r	   r
   Ú__str__^   s    zState.__str__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úpropertyr   r   r   r!   r'   r(   r.   r0   r5   r9   r:   r	   r	   r	   r
   r      s$    

		r   )	r   r   r   Ú	gold_treeÚgold_sequencer   r8   r   Úscorec                   @   s|   e Zd Zdd„ Zdd„ Zedd„ ƒZdd„ Zed	d
„ ƒZedd„ ƒZ	edd„ ƒZ
dd„ Zdd„ Zedd„ ƒZedd„ ƒZdS )Ú
MultiStatec                 C   ó   | j d  |jd ¡S ©Nr   )Ústatesr'   Úmodels©r   Úensembler	   r	   r
   r'   b   ó   zMultiState.finishedc                 C   rD   rE   )rF   r(   rG   rH   r	   r	   r
   r(   e   rJ   zMultiState.get_treec                 C   ó   | j d jS rE   )rF   r   r   r	   r	   r
   r   h   r   zMultiState.empty_constituentsc                 C   ó   t | jd jƒd S ©Nr   r   )ÚlenrF   r   r   r	   r	   r
   r   l   r6   zMultiState.num_constituentsc                 C   rL   rM   )rN   rF   r   r   r	   r	   r
   r   o   s   zMultiState.num_transitionsc                 C   rK   rE   )rF   r8   r   r	   r	   r
   r8   t   r   zMultiState.num_opensc                 C   rK   rE   )rF   r   r   r	   r	   r
   r   x   r   zMultiState.sentence_lengthc                 C   ó   | j d  ¡ S rE   )rF   r   r   r	   r	   r
   r   |   ó   zMultiState.empty_word_queuec                 C   rO   rE   )rF   r   r   r	   r	   r
   r      rP   zMultiState.empty_transitionsc                 C   rK   rE   )rF   r   r   r	   r	   r
   r   ‚   ó   zMultiState.constituentsc                 C   rK   rE   )rF   r   r   r	   r	   r
   r   Š   rQ   zMultiState.transitionsN)r;   r<   r=   r'   r(   r?   r   r   r   r8   r   r   r   r   r   r	   r	   r	   r
   rC   a   s$    




rC   )rF   r@   rA   rB   N)Úcollectionsr   r   rC   r	   r	   r	   r
   Ú<module>   s    ^