Ë
    çÍ:jT*  ã                   ó~   — d dl Z d dlmZ  G d„ d«      Z G d„ de«      Zd„ Zd„ Zd	„ Z ed
ddg«      Z	 G d„ d«      Z
y)é    N)Ú
namedtuplec                   ót   — e Zd ZdZdd„Zed„ «       Zed„ «       Zd„ Zd„ Z	 eee	«      Z
d„ Zd	„ Zd
„ Zd„ Zd„ Zy)ÚAlignedSenta#  
    Return an aligned sentence object, which encapsulates two sentences
    along with an ``Alignment`` between them.

    Typically used in machine translation to represent a sentence and
    its translation.

        >>> from nltk.translate import AlignedSent, Alignment
        >>> algnsent = AlignedSent(['klein', 'ist', 'das', 'Haus'],
        ...     ['the', 'house', 'is', 'small'], Alignment.fromstring('0-3 1-2 2-0 3-1'))
        >>> algnsent.words
        ['klein', 'ist', 'das', 'Haus']
        >>> algnsent.mots
        ['the', 'house', 'is', 'small']
        >>> algnsent.alignment
        Alignment([(0, 3), (1, 2), (2, 0), (3, 1)])
        >>> from nltk.corpus import comtrans
        >>> print(comtrans.aligned_sents()[54])
        <AlignedSent: 'Weshalb also sollten...' -> 'So why should EU arm...'>
        >>> print(comtrans.aligned_sents()[54].alignment)
        0-0 0-1 1-0 2-2 3-4 3-5 4-7 5-8 6-3 7-9 8-9 9-10 9-11 10-12 11-6 12-6 13-13

    :param words: Words in the target language sentence
    :type words: list(str)
    :param mots: Words in the source language sentence
    :type mots: list(str)
    :param alignment: Word-level alignments between ``words`` and ``mots``.
        Each alignment is represented as a 2-tuple (words_index, mots_index).
    :type alignment: Alignment
    Nc                 óz   — || _         || _        |€t        g «      | _        y t	        |«      t        u sJ ‚|| _        y ©N)Ú_wordsÚ_motsÚ	AlignmentÚ	alignmentÚtype)ÚselfÚwordsÚmotsr   s       úg/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/nltk/translate/api.pyÚ__init__zAlignedSent.__init__/   s:   € ØˆŒØˆŒ
ØÐÜ& r›]ˆD�Nä˜	“?¤iÑ/Ð/Ð/Ø&ˆD�Nó    c                 ó   — | j                   S r   )r   ©r   s    r   r   zAlignedSent.words8   s   € à�{‰{Ðr   c                 ó   — | j                   S r   )r	   r   s    r   r   zAlignedSent.mots<   s   € à�z‰zÐr   c                 ó   — | j                   S r   )Ú
_alignmentr   s    r   Ú_get_alignmentzAlignedSent._get_alignment@   s   € Ø�‰Ðr   c                 óx   — t        t        | j                  «      t        | j                  «      |«       || _        y r   )Ú_check_alignmentÚlenr   r   r   )r   r   s     r   Ú_set_alignmentzAlignedSent._set_alignmentC   s%   € Üœ˜TŸZ™Z›¬#¨d¯i©i«.¸)ÔDØ#ˆ�r   c                 óÂ   — ddj                  d„ | j                  D «       «      z  }ddj                  d„ | j                  D «       «      z  }d|› d|› d| j                  ›d�S )z_
        Return a string representation for this ``AlignedSent``.

        :rtype: str
        z[%s]z, c              3   ó&   K  — | ]	  }d |z  –— Œ y­w©z'%s'N© ©Ú.0Úws     r   ú	<genexpr>z'AlignedSent.__repr__.<locals>.<genexpr>O   s   è ø€ Ò#D°1 F¨Q¥JÑ#Dùó   ‚c              3   ó&   K  — | ]	  }d |z  –— Œ y­wr   r    r!   s     r   r$   z'AlignedSent.__repr__.<locals>.<genexpr>P   s   è ø€ Ò"B°! 6¨A¥:Ñ"Bùr%   zAlignedSent(ú))Újoinr   r	   r   )r   r   r   s      r   Ú__repr__zAlignedSent.__repr__I   s^   € ð ˜$Ÿ)™)Ñ#D¸¿¹Ô#DÓDÑEˆØ˜Ÿ™Ñ"B°t·z±zÔ"BÓBÑCˆà˜e˜W B t f¨B¨t¯©Ð.AÀÐCÐCr   c                 ó®  — d}|dz  }|dj                  | j                  D �cg c]  }d|› d|› d�‘Œ c}«      z  }|dj                  | j                  D �cg c]  }d|› d|› d�‘Œ c}«      z  }|dj                  | j                  D ��cg c](  \  }}d| j                  |   › d| j                  |   › d	�‘Œ* c}}«      z  }t	        t        | j                  «      d
z
  «      D ]4  }|dj                  | j                  |   | j                  |d
z      «      z  }Œ6 t	        t        | j                  «      d
z
  «      D ]4  }|dj                  | j                  |   | j                  |d
z      «      z  }Œ6 |ddj                  d„ | j                  D «       «      z  z  }|ddj                  d„ | j                  D «       «      z  z  }|dz  }|S c c}w c c}w c c}}w )z<
        Dot representation of the aligned sentence
        zgraph align {
znode[shape=plaintext]
Ú ú"z_source" [label="z"] 
z_target" [label="z_source" -- "z
_target" 
é   z)"{}_source" -- "{}_source" [style=invis]
z)"{}_target" -- "{}_target" [style=invis]
z{rank = same; %s}
ú c              3   ó&   K  — | ]	  }d |z  –— Œ y­w)z"%s_source"Nr    r!   s     r   r$   z&AlignedSent._to_dot.<locals>.<genexpr>v   s   è ø€ Ò.VÀQ¨}¸qÕ/@Ñ.Vùr%   c              3   ó&   K  — | ]	  }d |z  –— Œ y­w)z"%s_target"Nr    r!   s     r   r$   z&AlignedSent._to_dot.<locals>.<genexpr>w   s   è ø€ Ò.UÀQ¨}¸qÕ/@Ñ.Uùr%   ú})r(   r   r	   r   Úranger   Úformat)r   Úsr#   ÚuÚvÚis         r   Ú_to_dotzAlignedSent._to_dotT   sâ  € ð ˆØ	Ð&Ñ&ˆð 	
ˆR�W‰WÀÇÁÖL¸1˜˜!˜Ð-¨a¨S°Ò6ÒLÓMÑMˆØ	ˆR�W‰WÀÇ
Á
ÖK¸1˜˜!˜Ð-¨a¨S°Ò6ÒKÓLÑLˆð 	
ˆR�W‰Wð !ŸO™O÷á�A�qð �D—K‘K ‘NÐ# =°·±¸A±°¸{ÒKóó
ñ 	
ˆô ”s˜4Ÿ;™;Ó'¨!Ñ+Ó,ò 	ˆAØÐ=×DÑDØ—‘˜A‘Ø—‘˜A ™EÑ"óñ ‰Að	ô ”s˜4Ÿ:™:“¨Ñ*Ó+ò 	ˆAØÐ=×DÑDØ—
‘
˜1‘Ø—
‘
˜1˜q™5Ñ!óñ ‰Að	ð 	
Ð" c§h¡hÑ.VÈ$Ï+É+Ô.VÓ&VÑWÑWˆØ	Ð" c§h¡hÑ.UÈ$Ï*É*Ô.UÓ&UÑVÑVˆà	ˆS‰ˆàˆùò? MùÚKùós   ¢G
ÁG
Â	-Gc                 óZ  — | j                  «       j                  d«      }d}	 t        j                  dd|z  gt        j                  t        j                  t        j                  ¬«      }|j                  |«      \  }}|j                  d«      S # t
        $ r}t        d«      |‚d}~ww xY w)zR
        Ipython magic : show SVG representation of this ``AlignedSent``.
        Úutf8ÚsvgÚdotz-T%s)ÚstdinÚstdoutÚstderrz0Cannot find the dot binary from Graphviz packageN)	r8   ÚencodeÚ
subprocessÚPopenÚPIPEÚOSErrorÚ	ExceptionÚcommunicateÚdecode)r   Ú
dot_stringÚoutput_formatÚprocessÚeÚoutÚerrs          r   Ú
_repr_svg_zAlignedSent._repr_svg_}   sŸ   € ð —\‘\“^×*Ñ*¨6Ó2ˆ
Øˆð	WÜ ×&Ñ&Ø˜ Ñ.Ð/Ü —o‘oÜ!—‘Ü!—‘ô	ˆGð ×&Ñ& zÓ2‰ˆˆSà�z‰z˜&Ó!Ð!øô	 ò 	WÜÐNÓOÐUVÐVûð	Wús   £AB Â	B*ÂB%Â%B*c                 ó˜   — dj                  | j                  «      dd dz   }dj                  | j                  «      dd dz   }d|› d|› d�S )zn
        Return a human-readable string representation for this ``AlignedSent``.

        :rtype: str
        r.   Né   z...z<AlignedSent: 'z' -> 'z'>)r(   r   r	   )r   ÚsourceÚtargets      r   Ú__str__zAlignedSent.__str__�   sU   € ð —‘˜$Ÿ+™+Ó& s¨Ð+¨eÑ3ˆØ—‘˜$Ÿ*™*Ó% c rÐ*¨UÑ2ˆØ   ¨¨v¨h°bÐ9Ð9r   c                 ót   — t        | j                  | j                  | j                  j	                  «       «      S )zm
        Return the aligned sentence pair, reversing the directionality

        :rtype: AlignedSent
        )r   r	   r   r   Úinvertr   s    r   rU   zAlignedSent.invertš   s(   € ô ˜4Ÿ:™: t§{¡{°D·O±O×4JÑ4JÓ4LÓMÐMr   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r   r   r)   r8   rN   rS   rU   r    r   r   r   r      sh   „ ñó>'ð ñó ðð ñó ðòò$ñ ˜¨Ó8€Iò	Dò'òR"ò&:óNr   r   c                   óL   — e Zd ZdZd„ Zed„ «       Zd„ Zd„ Zdd„Z	d„ Z
d	„ Zd
„ Zy)r
   ac  
    A storage class for representing alignment between two sequences, s1, s2.
    In general, an alignment is a set of tuples of the form (i, j, ...)
    representing an alignment between the i-th element of s1 and the
    j-th element of s2.  Tuples are extensible (they might contain
    additional data, such as a boolean to indicate sure vs possible alignments).

        >>> from nltk.translate import Alignment
        >>> a = Alignment([(0, 0), (0, 1), (1, 2), (2, 2)])
        >>> a.invert()
        Alignment([(0, 0), (1, 0), (2, 1), (2, 2)])
        >>> print(a.invert())
        0-0 1-0 2-1 2-2
        >>> a[0]
        [(0, 1), (0, 0)]
        >>> a.invert()[2]
        [(2, 1), (2, 2)]
        >>> b = Alignment([(0, 0), (0, 1)])
        >>> b.issubset(a)
        True
        >>> c = Alignment.fromstring('0-0 0-1')
        >>> b == c
        True
    c                 óŽ   — t         j                  | |«      }|t        g «      k7  rt        d„ |D «       «      nd|_        d |_        |S )Nc              3   ó&   K  — | ]	  }|d    –— Œ y­w©r   Nr    ©r"   Úps     r   r$   z$Alignment.__new__.<locals>.<genexpr>¿   s   è ø€ Ò+ ˜˜!�Ñ+ùr%   r   )Ú	frozensetÚ__new__ÚmaxÚ_lenÚ_index)ÚclsÚpairsr   s      r   rb   zAlignment.__new__½   s?   € Ü× Ñ   eÓ,ˆØ/3´yÀ³}Ò/D”CÑ+ dÔ+Ô+È!ˆŒ	ØˆŒØˆr   c                 ól   — t        |j                  «       D �cg c]  }t        |«      ‘Œ c}«      S c c}w )a�  
        Read a giza-formatted string and return an Alignment object.

            >>> Alignment.fromstring('0-0 2-1 9-2 21-3 10-4 7-5')
            Alignment([(0, 0), (2, 1), (7, 5), (9, 2), (10, 4), (21, 3)])

        :type s: str
        :param s: the positional alignments in giza format
        :rtype: Alignment
        :return: An Alignment object corresponding to the string representation ``s``.
        )r
   ÚsplitÚ
_giza2pair)rf   r4   Úas      r   Ú
fromstringzAlignment.fromstringÃ   s'   € ô °·±³Ö;¨Aœ* Q�-Ò;Ó<Ð<ùÒ;s   ˜1c                 óp   — | j                   s| j                  «        | j                   j                  |«      S )zN
        Look up the alignments that map from a given index or slice.
        )re   Ú_build_indexÚ__getitem__)r   Úkeys     r   ro   zAlignment.__getitem__Ó   s,   € ð �{Š{Ø×ÑÔØ�{‰{×&Ñ& sÓ+Ð+r   c                 ó&   — t        d„ | D «       «      S )zI
        Return an Alignment object, being the inverted mapping.
        c              3   ó<   K  — | ]  }|d    |d   f|dd z   –— Œ y­w)r-   r   é   Nr    r_   s     r   r$   z#Alignment.invert.<locals>.<genexpr>ß   s'   è ø€ Ò>°A˜1˜Q™4  1¡˜,¨¨1¨2¨Õ.Ñ>ùs   ‚)r
   r   s    r   rU   zAlignment.invertÛ   s   € ô Ñ>¸Ô>Ó>Ð>r   Nc                 ó  — t        «       }| j                  s| j                  «        |s't        t	        t        | j                  «      «      «      }|D ]'  }|j                  d„ | j                  |   D «       «       Œ) t        |«      S )z�
        Work out the range of the mapping from the given positions.
        If no positions are specified, compute the range of the entire mapping.
        c              3   ó&   K  — | ]	  \  }}|–— Œ y ­wr   r    )r"   Ú_Úfs      r   r$   z"Alignment.range.<locals>.<genexpr>ì   s   è ø€ Ò6™t˜q !œÑ6ùr%   )Úsetre   rn   Úlistr2   r   ÚupdateÚsorted)r   Ú	positionsÚimager`   s       r   r2   zAlignment.rangeá   sl   € ô
 “ˆØ�{Š{Ø×ÑÔÙÜœU¤3 t§{¡{Ó#3Ó4Ó5ˆIØò 	7ˆAØ�L‰LÑ6 t§{¡{°1¡~Ô6Õ6ð	7ä�e‹}Ðr   c                 ó   — dt        | «      z  S )úM
        Produce a Giza-formatted string representing the alignment.
        zAlignment(%r))r{   r   s    r   r)   zAlignment.__repr__ï   s   € ð ¤¨£Ñ-Ð-r   c                 óD   — dj                  d„ t        | «      D «       «      S )r   r.   c              3   ó,   K  — | ]  }d |dd z  –— Œ y­w)z%d-%dNrs   r    r_   s     r   r$   z$Alignment.__str__.<locals>.<genexpr>ù   s   è ø€ Ò>¨A˜ ! B Q %�Ñ>ùs   ‚)r(   r{   r   s    r   rS   zAlignment.__str__õ   s   € ð �x‰xÑ>´¸³Ô>Ó>Ð>r   c                 ó´   — t        | j                  dz   «      D �cg c]  }g ‘Œ c}| _        | D ]#  }| j                  |d      j                  |«       Œ% yc c}w )z€
        Build a list self._index such that self._index[i] is a list
        of the alignments originating from word i.
        r-   r   N)r2   rd   re   Úappend)r   rv   r`   s      r   rn   zAlignment._build_indexû   sR   € ô
 $)¨¯©°Q©Ó#7Ö8˜a’rÒ8ˆŒØò 	(ˆAØ�K‰K˜˜!™Ñ×$Ñ$ QÕ'ñ	(ùò 9s   ›	Ar   )rV   rW   rX   rY   rb   Úclassmethodrl   ro   rU   r2   r)   rS   rn   r    r   r   r
   r
   £   s>   „ ñò2ð ñ=ó ð=ò,ò?óò.ò?ó(r   r
   c                 óV   — | j                  d«      \  }}t        |«      t        |«      fS ©Nú-©ri   Úint)Úpair_stringr7   Újs      r   rj   rj     s(   € Ø×Ñ˜SÓ!�D€A€qÜˆq‹6”3�q“6ˆ>Ðr   c                 óX   — | j                  d«      \  }}}t        |«      t        |«      fS r†   rˆ   )rŠ   r7   r‹   r`   s       r   Ú_naacl2pairr�   
  s*   € Ø×Ñ Ó$�G€A€qˆ!Üˆq‹6”3�q“6ˆ>Ðr   c                 óª   ‡ ‡— t        |«      t        u sJ ‚t        ˆ fd„|D «       «      st        d«      ‚t        ˆfd„|D «       «      st        d«      ‚y)ab  
    Check whether the alignments are legal.

    :param num_words: the number of source language words
    :type num_words: int
    :param num_mots: the number of target language words
    :type num_mots: int
    :param alignment: alignment to be checked
    :type alignment: Alignment
    :raise IndexError: if alignment falls outside the sentence
    c              3   óD   •K  — | ]  }d |d    cxk  xr ‰k  nc –— Œ y­wr^   r    )r"   ÚpairÚ	num_wordss     €r   r$   z#_check_alignment.<locals>.<genexpr>  s"   øè ø€ Ò>¨Dˆq�D˜‘GÖ'˜i×'Ð'Ñ>ùs   ƒ z&Alignment is outside boundary of wordsc              3   óV   •K  — | ]   }|d    du xs d|d    cxk  xr ‰k  nc –— Œ" y­w)r-   Nr   r    )r"   r�   Únum_motss     €r   r$   z#_check_alignment.<locals>.<genexpr>   s/   øè ø€ ÒP¸dˆt�A‰w˜$ˆÒ9 ! t¨A¡wÖ"9°Ô"9Ó9ÑPùs   ƒ&)z%Alignment is outside boundary of motsN)r   r
   ÚallÚ
IndexError)r‘   r“   r   s   `` r   r   r     sQ   ù€ ô �	‹?œiÑ'Ð'Ð'äÓ>°IÔ>Ô>ÜÐAÓBÐBÜÓPÀiÔPÔPÜÐ@ÓAÐAð Qr   ÚPhraseTableEntryÚ
trg_phraseÚlog_probc                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚPhraseTablezs
    In-memory store of translations for a given phrase, and the log
    probability of the those translations
    c                 ó"   — t        «       | _        y r   )ÚdictÚsrc_phrasesr   s    r   r   zPhraseTable.__init__-  s   € Ü›6ˆÕr   c                 ó    — | j                   |   S )aÅ  
        Get the translations for a source language phrase

        :param src_phrase: Source language phrase of interest
        :type src_phrase: tuple(str)

        :return: A list of target language phrases that are translations
            of ``src_phrase``, ordered in decreasing order of
            likelihood. Each list element is a tuple of the target
            phrase and its log probability.
        :rtype: list(PhraseTableEntry)
        ©r�   ©r   Ú
src_phrases     r   Útranslations_forzPhraseTable.translations_for0  s   € ð ×Ñ 
Ñ+Ð+r   c                 óÖ   — t        ||¬«      }|| j                  vrg | j                  |<   | j                  |   j                  |«       | j                  |   j                  d„ d¬«       y)zä
        :type src_phrase: tuple(str)
        :type trg_phrase: tuple(str)

        :param log_prob: Log probability that given ``src_phrase``,
            ``trg_phrase`` is its translation
        :type log_prob: float
        )r—   r˜   c                 ó   — | j                   S r   )r˜   )rK   s    r   ú<lambda>z!PhraseTable.add.<locals>.<lambda>L  s
   € ¸¿
¹
€ r   T)rp   ÚreverseN)r–   r�   rƒ   Úsort)r   r¡   r—   r˜   Úentrys        r   ÚaddzPhraseTable.add?  sf   € ô !¨JÀÔJˆØ˜T×-Ñ-Ñ-Ø+-ˆD×Ñ˜ZÑ(Ø×Ñ˜Ñ$×+Ñ+¨EÔ2Ø×Ñ˜Ñ$×)Ñ)Ñ.BÈDÐ)ÕQr   c                 ó   — || j                   v S r   rŸ   r    s     r   Ú__contains__zPhraseTable.__contains__N  s   € Ø˜T×-Ñ-Ð-Ð-r   N)rV   rW   rX   rY   r   r¢   r©   r«   r    r   r   rš   rš   '  s   „ ñò
"ò,òRó.r   rš   )rA   Úcollectionsr   r   ra   r
   rj   r�   r   r–   rš   r    r   r   ú<module>r­      sZ   ðó Ý "÷QNñ QNôh_(�	ô _(òDò
ò
Bñ* Ð0°<ÀÐ2LÓMÐ ÷(.ò (.r   