3
ญdR  ใ               @   s~   d dl mZ d dlmZmZ d dlmZ G dd deZG dd deeZG dd	 d	eeZ	G d
d deeZ
ddd	dgZdS )้    )ฺProbabilisticMixIn)ฺMultiParentedTreeฺParentedTree)ฺTreec                   s   e Zd Zd  f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!ddZdd Zdd Zdd Zdd Zdd Z  ZS )"ฺImmutableTreeNc                sf   t  j|| yt| jt| f| _W n: ttfk
r` } ztdt| j	 |W Y d d }~X nX d S )Nz-%s: node value and children must be immutable)
ฺsuperฺ__init__ฺhashฺ_labelฺtupleฺ_hashฺ	TypeErrorฺ
ValueErrorฺtypeฺ__name__)ฺselfฺnodeฺchildrenฺe)ฺ	__class__ฉ ๚3/tmp/pip-build-v9q4h5k9/nltk/nltk/tree/immutable.pyr      s    zImmutableTree.__init__c             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   ฺindexฺvaluer   r   r   ฺ__setitem__   s    zImmutableTree.__setitem__c             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   ฺiฺjr   r   r   r   ฺ__setslice__   s    zImmutableTree.__setslice__c             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   r   r   r   r   ฺ__delitem__"   s    zImmutableTree.__delitem__c             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   r   r   r   r   r   ฺ__delslice__%   s    zImmutableTree.__delslice__c             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   ฺotherr   r   r   ฺ__iadd__(   s    zImmutableTree.__iadd__c             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   r    r   r   r   ฺ__imul__+   s    zImmutableTree.__imul__c             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   ฺvr   r   r   ฺappend.   s    zImmutableTree.appendc             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   r#   r   r   r   ฺextend1   s    zImmutableTree.extendc             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   r#   r   r   r   ฺpop4   s    zImmutableTree.popc             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   r#   r   r   r   ฺremove7   s    zImmutableTree.removec             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   r   r   r   ฺreverse:   s    zImmutableTree.reversec             C   s   t dt| j d S )Nz%s may not be modified)r   r   r   )r   r   r   r   ฺsort=   s    zImmutableTree.sortc             C   s   | j S )N)r   )r   r   r   r   ฺ__hash__@   s    zImmutableTree.__hash__c             C   s&   t | drtdt| j || _dS )z
        Set the node label.  This will only succeed the first time the
        node label is set, which should occur in ImmutableTree.__init__().
        r
   z%s may not be modifiedN)ฺhasattrr   r   r   r
   )r   r   r   r   r   ฺ	set_labelC   s    
zImmutableTree.set_label)N)N)r   ฺ
__module__ฺ__qualname__r   r   r   r   r   r!   r"   r$   r%   r&   r'   r(   r)   r*   r,   ฺ__classcell__r   r   )r   r   r      s   
r   c               @   sD   e Zd ZdddZdd Zdd Zdd	 ZdddZedd Z	dS )ฺImmutableProbabilisticTreeNc             K   s:   t j| || tj| f| t| jt| | j f| _d S )N)r   r   r   r	   r
   r   ฺprobr   )r   r   r   Zprob_kwargsr   r   r   r   N   s    z#ImmutableProbabilisticTree.__init__c             C   s   t S )N)r0   )r   r   r   r   ฺ_frozen_classT   s    z(ImmutableProbabilisticTree._frozen_classc             C   s   t j|  d| j  dS )Nz [๚])r   ฺ__repr__r1   )r   r   r   r   r4   W   s    z#ImmutableProbabilisticTree.__repr__c             C   s   | j dd d| j  dS )N้<   )ฺmarginz [r3   )ฺpformatr1   )r   r   r   r   ฺ__str__Z   s    z"ImmutableProbabilisticTree.__str__Fc             C   s.   |st | | j| | j dS t | j| S d S )N)r1   )r   r
   r1   ฺconvert)r   ฺdeepr   r   r   ฺcopy]   s    zImmutableProbabilisticTree.copyc                sT   t |trL fdd|D }t |tr: |j||j dS  |j|ddS n|S d S )Nc                s   g | ]} j |qS r   )r9   )ฺ.0ฺchild)ฺclsr   r   ๚
<listcomp>f   s    z6ImmutableProbabilisticTree.convert.<locals>.<listcomp>)r1   g      ๐?)ฺ
isinstancer   r   r
   r1   )r>   ฺvalr   r   )r>   r   r9   c   s    

z"ImmutableProbabilisticTree.convert)N)F)
r   r-   r.   r   r2   r4   r8   r;   ฺclassmethodr9   r   r   r   r   r0   M   s   

r0   c               @   s   e Zd ZdS )ฺImmutableParentedTreeN)r   r-   r.   r   r   r   r   rC   o   s   rC   c               @   s   e Zd ZdS )ฺImmutableMultiParentedTreeN)r   r-   r.   r   r   r   r   rD   s   s   rD   N)Znltk.probabilityr   Znltk.tree.parentedr   r   Znltk.tree.treer   r   r0   rC   rD   ฺ__all__r   r   r   r   ฺ<module>   s   ="