§
    'ê[fe+  ã                   ó˜   — 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
dS )é    N)Ú
namedtuplec                   óˆ   — 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dS )Ú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                 ó�   — || _         || _        |€t          g ¦  «        | _        d S t	          |¦  «        t          u sJ ‚|| _        d S ©N)Ú_wordsÚ_motsÚ	AlignmentÚ	alignmentÚtype)ÚselfÚwordsÚmotsr   s       úF/var/www/piapp/venv/lib/python3.11/site-packages/nltk/translate/api.pyÚ__init__zAlignedSent.__init__/   sI   € ØˆŒØˆŒ
ØÐÝ& r™]œ]ˆDŒNˆNˆNå˜	‘?”?¥iÐ/Ð/Ð/Ð/Ø&ˆDŒNˆNˆ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Ðr   c                 ó   — | j         S r   )Ú
_alignmentr   s    r   Ú_get_alignmentzAlignedSent._get_alignment@   s
   € ØŒÐr   c                 ó~   — t          t          | j        ¦  «        t          | j        ¦  «        |¦  «         || _        d S r   )Ú_check_alignmentÚlenr   r   r   )r   r   s     r   Ú_set_alignmentzAlignedSent._set_alignmentC   s/   € Ý�˜TœZ™œ­#¨d¬i©.¬.¸)ÑDÔDÐDØ#ˆŒˆˆr   c                 óÀ   — dd                      d„ | j        D ¦   «         ¦  «        z  }dd                      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  V — Œ
dS ©z'%s'N© ©Ú.0Úws     r   ú	<genexpr>z'AlignedSent.__repr__.<locals>.<genexpr>O   s&   è è € Ð#DÐ#D°1 F¨Q¡JÐ#DÐ#DÐ#DÐ#DÐ#DÐ#Dr   c              3   ó    K  — | ]	}d |z  V — Œ
dS r   r    r!   s     r   r$   z'AlignedSent.__repr__.<locals>.<genexpr>P   s&   è è € Ð"BÐ"B°! 6¨A¡:Ð"BÐ"BÐ"BÐ"BÐ"BÐ"Br   zAlignedSent(ú))Újoinr   r	   r   )r   r   r   s      r   Ú__repr__zAlignedSent.__repr__I   su   € ð ˜$Ÿ)š)Ð#DÐ#D¸¼Ð#DÑ#DÔ#DÑDÔDÑEˆØ˜ŸšÐ"BÐ"B°t´zÐ"BÑ"BÔ"BÑBÔBÑCˆàC˜eÐCÐC tÐCÐC¨t¬ÐCÐCÐCÐCr   c                 óà  — d}|dz  }| j         D ]}|d|› d|› d�z  }Œ| j        D ]}|d|› d|› d�z  }Œ| j        D ]'\  }}|d| j         |         › d| j        |         › d�z  }Œ(t          t	          | j         ¦  «        d	z
  ¦  «        D ]4}|d
                     | j         |         | j         |d	z            ¦  «        z  }Œ5t          t	          | j        ¦  «        d	z
  ¦  «        D ]4}|d                     | j        |         | j        |d	z            ¦  «        z  }Œ5|dd                     d„ | j         D ¦   «         ¦  «        z  z  }|dd                     d„ | j        D ¦   «         ¦  «        z  z  }|dz  }|S )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  V — Œ
dS )z"%s_source"Nr    r!   s     r   r$   z&AlignedSent._to_dot.<locals>.<genexpr>u   s'   è è € Ð.VÐ.VÀQ¨}¸qÑ/@Ð.VÐ.VÐ.VÐ.VÐ.VÐ.Vr   c              3   ó    K  — | ]	}d |z  V — Œ
dS )z"%s_target"Nr    r!   s     r   r$   z&AlignedSent._to_dot.<locals>.<genexpr>v   s'   è è € Ð.UÐ.UÀQ¨}¸qÑ/@Ð.UÐ.UÐ.UÐ.UÐ.UÐ.Ur   ú})r   r	   r   Úranger   Úformatr'   )r   Úsr#   ÚuÚvÚis         r   Ú_to_dotzAlignedSent._to_dotT   sá  € ð ˆØ	Ð&Ñ&ˆð ”ð 	2ð 	2ˆAØÐ1�QÐ1Ð1¨Ð1Ð1Ð1Ñ1ˆAˆAà”ð 	2ð 	2ˆAØÐ1�QÐ1Ð1¨Ð1Ð1Ð1Ñ1ˆAˆAð ”Oð 	Mð 	M‰DˆAˆqØÐL�T”[ ”^ÐLÐL°$´*¸Q´-ÐLÐLÐLÑLˆAˆAõ •s˜4œ;Ñ'Ô'¨!Ñ+Ñ,Ô,ð 	ð 	ˆAØÐ=×DÒDØ”˜A”Ø”˜A ™EÔ"ñô ñ ˆAˆAõ •s˜4œ:‘”¨Ñ*Ñ+Ô+ð 	ð 	ˆAØÐ=×DÒDØ”
˜1”Ø”
˜1˜q™5Ô!ñô ñ ˆAˆAð 	
Ð" c§h¢hÐ.VÐ.VÈ$Ì+Ð.VÑ.VÔ.VÑ&VÔ&VÑWÑWˆØ	Ð" c§h¢hÐ.UÐ.UÈ$Ì*Ð.UÑ.UÔ.UÑ&UÔ&UÑVÑVˆà	ˆS‰ˆàˆr   c                 ól  — |                       ¦   «                              d¦  «        }d}	 t          j        dd|z  gt          j        t          j        t          j        ¬¦  «        }n"# t
          $ r}t          d¦  «        |‚d}~ww xY w|                     |¦  «        \  }}|                     d¦  «        S )zR
        Ipython magic : show SVG representation of this ``AlignedSent``.
        Úutf8ÚsvgÚdotz-T%s)ÚstdinÚstdoutÚstderrz0Cannot find the dot binary from Graphviz packageN)	r6   Ú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Ô2ˆ
Øˆð	WÝ Ô&Ø˜ Ñ.Ð/Ý ”oÝ!”Ý!”ð	ñ ô ˆGˆGøõ ð 	Wð 	Wð 	WÝÐNÑOÔOÐUVÐVøøøøð	Wøøøà×&Ò& zÑ2Ô2‰ˆˆSà�zŠz˜&Ñ!Ô!Ð!s   «;A' Á'
BÁ1BÂBc                 ó¨   — d                      | j        ¦  «        dd…         dz   }d                      | 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__�   s_   € ð —’˜$œ+Ñ&Ô& s¨ sÔ+¨eÑ3ˆØ—’˜$œ*Ñ%Ô% c r cÔ*¨UÑ2ˆØ9 Ð9Ð9¨vÐ9Ð9Ð9Ð9r   c                 óf   — t          | j        | j        | j                             ¦   «         ¦  «        S )zm
        Return the aligned sentence pair, reversing the directionality

        :rtype: AlignedSent
        )r   r	   r   r   Úinvertr   s    r   rS   zAlignedSent.invert™   s(   € õ ˜4œ: t¤{°D´O×4JÒ4JÑ4LÔ4LÑMÔMÐMr   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r   r   r(   r6   rL   rQ   rS   r    r   r   r   r      sí   € € € € € ðð ð>'ð 'ð 'ð 'ð ðð ñ „Xðð ðð ñ „Xððð ð ð$ð $ð $ð �˜¨Ñ8Ô8€Ið	Dð 	Dð 	Dð&ð &ð &ðP"ð "ð "ð&:ð :ð :ðNð Nð Nð Nð Nr   r   c                   óT   — e Zd ZdZd„ Zed„ ¦   «         Zd„ Zd„ Zdd„Z	d„ Z
d	„ Zd
„ ZdS )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                                | |¦  «        }|t          g ¦  «        k    rt          d„ |D ¦   «         ¦  «        nd|_        d |_        |S )Nc              3   ó&   K  — | ]}|d          V — ŒdS ©r   Nr    ©r"   Úps     r   r$   z$Alignment.__new__.<locals>.<genexpr>¾   s&   è è € Ð+Ð+ ˜˜!œÐ+Ð+Ð+Ð+Ð+Ð+r   r   )Ú	frozensetÚ__new__ÚmaxÚ_lenÚ_index)ÚclsÚpairsr   s      r   r`   zAlignment.__new__¼   sV   € Ý× Ò   eÑ,Ô,ˆØ/3µyÀ±}´}Ò/DÐ/D•CÐ+Ð+ dÐ+Ñ+Ô+Ñ+Ô+Ð+È!ˆŒ	ØˆŒØˆr   c                 óX   — t          d„ |                     ¦   «         D ¦   «         ¦  «        S )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``.
        c                 ó,   — g | ]}t          |¦  «        ‘ŒS r    )Ú
_giza2pair)r"   Úas     r   ú
<listcomp>z(Alignment.fromstring.<locals>.<listcomp>Ð   s   € Ð;Ð;Ð;¨A�* Q™-œ-Ð;Ð;Ð;r   )r
   Úsplit)rd   r2   s     r   Ú
fromstringzAlignment.fromstringÂ   s)   € õ Ð;Ð;°·²±´Ð;Ñ;Ô;Ñ<Ô<Ð<r   c                 ól   — | j         s|                      ¦   «          | j                              |¦  «        S )zN
        Look up the alignments that map from a given index or slice.
        )rc   Ú_build_indexÚ__getitem__)r   Úkeys     r   ro   zAlignment.__getitem__Ò   s6   € ð Œ{ð 	 Ø×ÒÑÔÐØŒ{×&Ò& sÑ+Ô+Ð+r   c                 ó4   — t          d„ | D ¦   «         ¦  «        S )zI
        Return an Alignment object, being the inverted mapping.
        c              3   óL   K  — | ]}|d          |d         f|dd…         z   V — Œ dS )r+   r   é   Nr    r]   s     r   r$   z#Alignment.invert.<locals>.<genexpr>Þ   s;   è è € Ð>Ð>°A˜1˜Qœ4  1¤˜,¨¨1¨2¨2¬Ñ.Ð>Ð>Ð>Ð>Ð>Ð>r   )r
   r   s    r   rS   zAlignment.invertÚ   s!   € õ Ð>Ð>¸Ð>Ñ>Ô>Ñ>Ô>Ð>r   Nc                 ó0  — t          ¦   «         }| j        s|                      ¦   «          |s.t          t	          t          | j        ¦  «        ¦  «        ¦  «        }|D ],}|                     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  — | ]	\  }}|V — Œ
d S r   r    )r"   Ú_Úfs      r   r$   z"Alignment.range.<locals>.<genexpr>ë   s&   è è € Ð6Ð6™t˜q !˜Ð6Ð6Ð6Ð6Ð6Ð6r   )Úsetrc   rn   Úlistr0   r   ÚupdateÚsorted)r   Ú	positionsÚimager^   s       r   r0   zAlignment.rangeà   s•   € õ
 ‘”ˆØŒ{ð 	 Ø×ÒÑÔÐØð 	6Ý�U¥3 t¤{Ñ#3Ô#3Ñ4Ô4Ñ5Ô5ˆIØð 	7ð 	7ˆAØ�LŠLÐ6Ð6 t¤{°1¤~Ð6Ñ6Ô6Ñ6Ô6Ð6Ð6Ý�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                 óZ   — d                      d„ t          | ¦  «        D ¦   «         ¦  «        S )r   r,   c              3   ó0   K  — | ]}d |dd…         z  V — ŒdS )z%d-%dNrs   r    r]   s     r   r$   z$Alignment.__str__.<locals>.<genexpr>ø   s.   è è € Ð>Ð>¨A˜ ! B Q B¤%™Ð>Ð>Ð>Ð>Ð>Ð>r   )r'   r{   r   s    r   rQ   zAlignment.__str__ô   s+   € ð �xŠxÐ>Ð>µ¸±´Ð>Ñ>Ô>Ñ>Ô>Ð>r   c                 ó¨   — d„ t          | j        dz   ¦  «        D ¦   «         | _        | D ](}| j        |d                                       |¦  «         Œ)dS )z€
        Build a list self._index such that self._index[i] is a list
        of the alignments originating from word i.
        c                 ó   — g | ]}g ‘ŒS r    r    )r"   rv   s     r   rj   z*Alignment._build_index.<locals>.<listcomp>ÿ   s   € Ð8Ð8Ð8˜a�rÐ8Ð8Ð8r   r+   r   N)r0   rb   rc   Úappend)r   r^   s     r   rn   zAlignment._build_indexú   sb   € ð
 9Ð8¥5¨¬°Q©Ñ#7Ô#7Ð8Ñ8Ô8ˆŒØð 	(ð 	(ˆAØŒK˜˜!œÔ×$Ò$ QÑ'Ô'Ð'Ð'ð	(ð 	(r   r   )rT   rU   rV   rW   r`   Úclassmethodrl   ro   rS   r0   r(   rQ   rn   r    r   r   r
   r
   ¢   s§   € € € € € ðð ð2ð ð ð ð=ð =ñ „[ð=ð,ð ,ð ,ð?ð ?ð ?ðð ð ð ð.ð .ð .ð?ð ?ð ?ð(ð (ð (ð (ð (r   r
   c                 ón   — |                       d¦  «        \  }}t          |¦  «        t          |¦  «        fS ©NÚ-©rk   Úint)Úpair_stringr5   Újs      r   rh   rh     s/   € Ø×Ò˜SÑ!Ô!�D€A€qÝˆq‰6Œ6•3�q‘6”6ˆ>Ðr   c                 óp   — |                       d¦  «        \  }}}t          |¦  «        t          |¦  «        fS r‡   r‰   )r‹   r5   rŒ   r^   s       r   Ú_naacl2pairrŽ   	  s1   € Ø×Ò Ñ$Ô$�G€A€qˆ!Ýˆq‰6Œ6•3�q‘6”6ˆ>Ðr   c                 óâ   ‡ ‡— t          |¦  «        t          u sJ ‚t          ˆ fd„|D ¦   «         ¦  «        st          d¦  «        ‚t          ˆfd„|D ¦   «         ¦  «        st          d¦  «        ‚dS )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    o‰k     nc V — ŒdS r\   r    )r"   ÚpairÚ	num_wordss     €r   r$   z#_check_alignment.<locals>.<genexpr>  sC   øè è € Ð>Ð>¨Dˆq�D˜”GÐ'Ð'Ò'Ð'˜iÒ'Ð'Ð'Ð'Ð>Ð>Ð>Ð>Ð>Ð>r   z&Alignment is outside boundary of wordsc              3   óX   •K  — | ]$}|d          du pd|d          cxk    o‰k     nc V — Œ%dS )r+   Nr   r    )r"   r‘   Únum_motss     €r   r$   z#_check_alignment.<locals>.<genexpr>  sP   øè è € ÐPÐP¸dˆt�AŒw˜$ˆÐ9 ! t¨A¤wÐ"9Ð"9Ò"9Ð"9°Ò"9Ð"9Ð"9Ð"9ÐPÐPÐPÐPÐPÐPr   z%Alignment is outside boundary of motsN)r   r
   ÚallÚ
IndexError)r’   r”   r   s   `` r   r   r     s“   øø€ õ �	‰?Œ?�iÐ'Ð'Ð'Ð'åÐ>Ð>Ð>Ð>°IÐ>Ñ>Ô>Ñ>Ô>ð CÝÐAÑBÔBÐBÝÐPÐPÐPÐPÀiÐPÑPÔPÑPÔPð BÝÐ@ÑAÔAÐAðBð Br   ÚPhraseTableEntryÚ
trg_phraseÚlog_probc                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )ÚPhraseTablezs
    In-memory store of translations for a given phrase, and the log
    probability of the those translations
    c                 ó,   — t          ¦   «         | _        d S r   )ÚdictÚsrc_phrasesr   s    r   r   zPhraseTable.__init__,  s   € Ý™6œ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_for/  s   € ð Ô 
Ô+Ð+r   c                 óÔ   — t          ||¬¦  «        }|| j        vr
g | j        |<   | j        |                              |¦  «         | j        |                              d„ d¬¦  «         dS )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™   )rI   s    r   ú<lambda>z!PhraseTable.add.<locals>.<lambda>K  s   € ¸¼
€ r   T)rp   ÚreverseN)r—   rž   r„   Úsort)r   r¢   r˜   r™   Úentrys        r   ÚaddzPhraseTable.add>  sx   € õ !¨JÀÐJÑJÔJˆØ˜TÔ-Ð-Ð-Ø+-ˆDÔ˜ZÑ(ØÔ˜Ô$×+Ò+¨EÑ2Ô2Ð2ØÔ˜Ô$×)Ò)Ð.BÐ.BÈDÐ)ÑQÔQÐQÐQÐQr   c                 ó   — || j         v S r   r    r¡   s     r   Ú__contains__zPhraseTable.__contains__M  s   € Ø˜TÔ-Ð-Ð-r   N)rT   rU   rV   rW   r   r£   rª   r¬   r    r   r   r›   r›   &  s]   € € € € € ðð ð
"ð "ð "ð,ð ,ð ,ðRð Rð Rð.ð .ð .ð .ð .r   r›   )r?   Úcollectionsr   r   r_   r
   rh   rŽ   r   r—   r›   r    r   r   ú<module>r®      s  ðð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "ðPNð PNð PNð PNð PNñ PNô PNð PNðf_(ð _(ð _(ð _(ð _(�	ñ _(ô _(ð _(ðDð ð ð
ð ð ð
Bð Bð Bð* �:Ð0°<ÀÐ2LÑMÔMÐ ð(.ð (.ð (.ð (.ð (.ñ (.ô (.ð (.ð (.ð (.r   