o
    xi.                      @   s   d Z ddlZddlZddlZddlmZmZmZmZm	Z	 ddl
mZmZ ddlmZ ddlmZ ddlmZ ddlmZ ed	d
dZG dd
 d
eZdS )z/
The abstract class used by all textgrid tiers
    N)ListOptionalTypeTypeVarUnion)ABCabstractmethod)Literal)	constants)errors)utilsTTextgridTier)boundc                   @   s  e Zd ZU eed< eeej eej	 f ed< 	dPdede
dededed	 f
d
dZdd Zdd Zdd Zedd Zeede
e fddZdQddZ		dRdededede
e fddZ	 	 	 	 dSd!edee dee d"ee d#ee defd$d%ZdTd&d'ZdQd(d)Ze	dPd*ed+ed	 dd fd,d-Ze	.	dUd/ed0 d1ed2 dd fd3d4Z e	5dVd6d d7edd fd8d9Z!e	.	:dWd;ed<ed/ed= d>edd f
d?d@Z"edAedBedCedD dEedd f
dFdGZ#ed;edHed/edI dd fdJdKZ$edTdLdMZ%edefdNdOZ&d S )Xr   tierType	entryTypewarningnameentriesminTmaxT	errorMode)silencer   errorc                 C   sB   t d|tj 	 |  || _|| _|| _|| _t 	|| _
dS )zBA container that stores and operates over interval and point tiersr   N)r   validateOptionr
   ErrorReportingModesortr   _entriesminTimestampmaxTimestampgetErrorReportererrorReporter)selfr   r   r   r   r    r#   e/home/ubuntu/maya3_transcribe/venv/lib/python3.10/site-packages/praatio/data_classes/textgrid_tier.py__init__   s   	zTextgridTier.__init__c                 C   
   t | jS N)lenr   r"   r#   r#   r$   __len__3   s   
zTextgridTier.__len__c                 c   s    | j D ]}|V  qd S r'   )r   r"   entryr#   r#   r$   __iter__6   s   
zTextgridTier.__iter__c              
   C   s   t | t|s	dS d}|| j|jkM }|t| j|jM }|t| j|jM }|t| jt|jkM }|rdt	| j|jD ]'\}}t	||D ]\}}z
|t||M }W qE t
yb   |||kM }Y qEw q<|S )NFT)
isinstancetyper   mathiscloser   r   r(   r   zip	TypeError)r"   otherisEqual	selfEntry
otherEntryselfSubEntryotherSubEntryr#   r#   r$   __eq__:   s"   zTextgridTier.__eq__c                 C   r&   r'   )tupler   r)   r#   r#   r$   r   Q   s   
zTextgridTier.entriesreturnc                 C      d S r'   r#   r)   r#   r#   r$   
timestampsU   s   zTextgridTier.timestampstierc                 C   st   | j |j krtdt|  dt| d| j|j }|| jtjj}| j	|j	 }|
  | j| j|| j|dS )zAppend a tier to the end of this one.

        This tier's maxtimestamp will be lengthened by the amount in the passed in tier.
        zCannot append a tier of type z to a tier of type .)r   r   )r   r   ArgumentErrorr/   r   editTimestampsr
   r   SILENCEr   r   newr   r   )r"   r?   maxTime
appendTierr   r#   r#   r$   rF   Z   s   
zTextgridTier.appendTierF
matchLabelsubstrMatchFlagusingREc                 C   s   g }|du r$t | jD ]\}}t||jtj}|g kr!|| q|S t | jD ]\}}|s:|j|kr9|| q)||jv rD|| q)|S )a  Returns the index of all intervals that match the given label

        Args:
            matchLabel: the label to search for
            substrMatchFlag: if True, match any label containing matchLabel.
                if False, label must be the same as matchLabel.
            usingRE: if True, matchLabel is interpreted as a regular expression

        Returns:
            A list of indicies
        T)	enumerater   refindalllabelIappend)r"   rG   rH   rI   
returnListir,   	matchListr#   r#   r$   findt   s"   





zTextgridTier.findNr"   r   r   c                    sb   |du r j }|du rt j} fdd|D }|du r! j}|du r( j}t ||||S )z,Make a new tier derived from the current oneNc                    s.   g | ]}t |tst |tr j| n|qS r#   )r.   r;   listr   .0r,   r)   r#   r$   
<listcomp>   s    z$TextgridTier.new.<locals>.<listcomp>)r   copydeepcopyr   r   r   r/   )r"   r   r   r   r   r#   r)   r$   rD      s   
zTextgridTier.newc                    s$    fdd j D  _ j  dS )z(Sorts the entries in the list of entriesc                    s&   g | ]}t | jr|n j| qS r#   )r.   r   rU   r)   r#   r$   rW      s    z%TextgridTier.sort.<locals>.<listcomp>N)r   r   r   r)   r#   r)   r$   r      s   
zTextgridTier.sortc                 C   s8   |   }|jD ]}|j|tjjtjjd q|  |S )zThe given tier is set unioned to this tier.

        All entries in the given tier are added to the current tier.
        Overlapping entries are merged.
        )collisionModecollisionReportingMode)	rD   r   insertEntryr
   IntervalCollisionMERGEr   rC   r   )r"   r?   retTierr,   r#   r#   r$   union   s   
zTextgridTier.unionoffsetreportingModec                 C   r=   r'   r#   )r"   ra   rb   r#   r#   r$   rB         zTextgridTier.editTimestampsr   rZ   )replacemerger   r[   )r   r   c                 C   r=   r'   r#   )r"   r,   rZ   r[   r#   r#   r$   r\         zTextgridTier.insertEntryMbP?referenceTiermaxDifferencec                 C   r=   r'   r#   )r"   rh   ri   r#   r#   r$   dejitter   rc   zTextgridTier.dejitterTstartend)truncatecategoricalr   doShrinkc                 C   r=   r'   r#   )r"   rk   rl   rZ   ro   r#   r#   r$   eraseRegion      zTextgridTier.eraseRegion	cropStartcropEndmode)strictlax	truncatedrebaseToZeroc                 C   r=   r'   r#   )r"   rr   rs   rt   rx   r#   r#   r$   crop   rq   zTextgridTier.cropduration)stretchsplit	no_changer   c                 C   r=   r'   r#   )r"   rk   rz   rZ   r#   r#   r$   insertSpace   rf   zTextgridTier.insertSpacec                 C   r=   r'   r#   r+   r#   r#   r$   deleteEntry     zTextgridTier.deleteEntryc                 C   r=   r'   r#   )r"   rb   r#   r#   r$   validate  r   zTextgridTier.validate)r   )r?   r   r<   r   )FF)NNNN)r<   N)r   r   )rg   )r   T)'__name__
__module____qualname__str__annotations__r   r   r
   PointIntervalr   floatr	   r%   r*   r-   r:   propertyr   r   r>   rF   boolintrS   r   r   rT   rD   r   r`   rB   r\   rj   rp   ry   r~   r   r   r#   r#   r#   r$   r      s   
 



$


		)__doc__rK   rX   r0   typingr   r   r   r   r   abcr   r   typing_extensionsr	   praatio.utilitiesr
   r   r   r   r   r#   r#   r#   r$   <module>   s    