
    /h<'                     ^    S SK Jr  S SKJrJr  S rS rS r " S S5      rS r	S	 r
S
 rS rg)    )finditer)escapeunescapec              #      #    [        U5      S:X  a  [        S5      eSn  U R                  X5      nUS:w  a  X#4v   U[        U5      -   nM-  ! [         a!    U[        U 5      :w  a  U[        U 5      4v    gf = f7f)aw  
Return the offsets of the tokens in *s*, as a sequence of ``(start, end)``
tuples, by splitting the string at each occurrence of *sep*.

    >>> from nltk.tokenize.util import string_span_tokenize
    >>> s = '''Good muffins cost $3.88\nin New York.  Please buy me
    ... two of them.\n\nThanks.'''
    >>> list(string_span_tokenize(s, " ")) # doctest: +NORMALIZE_WHITESPACE
    [(0, 4), (5, 12), (13, 17), (18, 26), (27, 30), (31, 36), (37, 37),
    (38, 44), (45, 48), (49, 55), (56, 58), (59, 73)]

:param s: the string to be tokenized
:type s: str
:param sep: the token separator
:type sep: str
:rtype: iter(tuple(int, int))
r   z!Token delimiter must not be emptyN)len
ValueErrorindex)ssepleftrights       J/var/www/auris/envauris/lib/python3.13/site-packages/nltk/tokenize/util.pystring_span_tokenizer      s     $ 3x1}<==D
	GGC&Ezk! s3x 
  	s1v~CFl"	s'   A;A A;(A85A;7A88A;c              #      #    Sn[        X5       H!  nUR                  5       u  pEXB:w  a  X$4v   UnM#     U[        U 5      4v   g7f)a  
Return the offsets of the tokens in *s*, as a sequence of ``(start, end)``
tuples, by splitting the string at each successive match of *regexp*.

    >>> from nltk.tokenize.util import regexp_span_tokenize
    >>> s = '''Good muffins cost $3.88\nin New York.  Please buy me
    ... two of them.\n\nThanks.'''
    >>> list(regexp_span_tokenize(s, r'\s')) # doctest: +NORMALIZE_WHITESPACE
    [(0, 4), (5, 12), (13, 17), (18, 23), (24, 26), (27, 30), (31, 36),
    (38, 44), (45, 48), (49, 51), (52, 55), (56, 58), (59, 64), (66, 73)]

:param s: the string to be tokenized
:type s: str
:param regexp: regular expression that matches token separators (must not be empty)
:type regexp: str
:rtype: iter(tuple(int, int))
r   N)r   spanr   )r
   regexpr   mr   nexts         r   regexp_span_tokenizer   .   sJ     $ Df ffh=+	 !
 A,s   AAc              #   >   #    SnU  H  u  p#X!-
  X2-
  4v   UnM     g7f)a{  
Return a sequence of relative spans, given a sequence of spans.

    >>> from nltk.tokenize import WhitespaceTokenizer
    >>> from nltk.tokenize.util import spans_to_relative
    >>> s = '''Good muffins cost $3.88\nin New York.  Please buy me
    ... two of them.\n\nThanks.'''
    >>> list(spans_to_relative(WhitespaceTokenizer().span_tokenize(s))) # doctest: +NORMALIZE_WHITESPACE
    [(0, 4), (1, 7), (1, 4), (1, 5), (1, 2), (1, 3), (1, 5), (2, 6),
    (1, 3), (1, 2), (1, 3), (1, 2), (1, 5), (2, 7)]

:param spans: a sequence of (start, end) offsets of the tokens
:type spans: iter(tuple(int, int))
:rtype: iter(tuple(int, int))
r   N )spansprevr   r   s       r   spans_to_relativer   I   s,       Dk5<'' s   c                   L    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
r\\\\\	\
\\/rSrg)CJKChars_   aJ  
An object that enumerates the code points of the CJK characters as listed on
https://en.wikipedia.org/wiki/Basic_Multilingual_Plane#Basic_Multilingual_Plane

This is a Python port of the CJK code point enumerations of Moses tokenizer:
https://github.com/moses-smt/mosesdecoder/blob/master/scripts/tokenizer/detokenizer.perl#L309
i   i  i.  iϤ  i@  i  i   i  i   i  i0  iO  ie  i  i   i r   N)__name__
__module____qualname____firstlineno____doc__Hangul_JamoCJK_RadicalsPhags_PaHangul_SyllablesCJK_Compatibility_IdeographsCJK_Compatibility_FormsKatakana_Hangul_HalfwidthSupplementary_Ideographic_Planeranges__static_attributes__r       r   r   r   _   se     K* "L H & $2  - !/'# 	$!'	Fr5   r   c           
          [        S VVs/ s H#  u  pU[        U 5      s=:*  =(       a    U:*  Os  PM%     snn5      $ s  snnf )u`  
Python port of Moses' code to check for CJK character.

>>> CJKChars().ranges
[(4352, 4607), (11904, 42191), (43072, 43135), (44032, 55215), (63744, 64255), (65072, 65103), (65381, 65500), (131072, 196607)]
>>> is_cjk(u'㏾')
True
>>> is_cjk(u'﹟')
False

:param character: The character that needs to be checked.
:type character: char
:return: bool
)r   r   r    r!   r"   r#   r$   r%   )anyord)	characterstartends      r   is_cjkr<      sJ     		
	
 S^**s*		
 	
s   *=
c           	      "    [        U SSSSSS.S9$ )aP  
This function transforms the input text into an "escaped" version suitable
for well-formed XML formatting.

Note that the default xml.sax.saxutils.escape() function don't escape
some characters that Moses does so we have to manually add them to the
entities dictionary.

    >>> input_str = ''')| & < > ' " ] ['''
    >>> expected_output =  ''')| &amp; &lt; &gt; ' " ] ['''
    >>> escape(input_str) == expected_output
    True
    >>> xml_escape(input_str)
    ')&#124; &amp; &lt; &gt; &apos; &quot; &#93; &#91;'

:param text: The text that needs to be escaped.
:type text: str
:rtype: str
&apos;&quot;&#124;&#91;&#93;)'"|[]entities)r   texts    r   
xml_escaperL      s(    ( 
	 	r5   c           	      "    [        U SSSSSS.S9$ )a2  
This function transforms the "escaped" version suitable
for well-formed XML formatting into humanly-readable string.

Note that the default xml.sax.saxutils.unescape() function don't unescape
some characters that Moses does so we have to manually add them to the
entities dictionary.

    >>> from xml.sax.saxutils import unescape
    >>> s = ')&#124; &amp; &lt; &gt; &apos; &quot; &#93; &#91;'
    >>> expected = ''')| & < > ' " ] ['''
    >>> xml_unescape(s) == expected
    True

:param text: The text that needs to be unescaped.
:type text: str
:rtype: str
rC   rD   rE   rF   rG   )r>   r?   r@   rA   rB   rH   )r   rJ   s    r   xml_unescaperN      s(    & 
	 	r5   c           	          Sn/ nU  H5  n UR                  XB5      nU[        U5      -   nUR                  XR45        M7     U$ ! [         a  n[        SU SU S35      UeSnAff = f)a]  
This module attempt to find the offsets of the tokens in *s*, as a sequence
of ``(start, end)`` tuples, given the tokens and also the source string.

    >>> from nltk.tokenize import TreebankWordTokenizer
    >>> from nltk.tokenize.util import align_tokens
    >>> s = str("The plane, bound for St Petersburg, crashed in Egypt's "
    ... "Sinai desert just 23 minutes after take-off from Sharm el-Sheikh "
    ... "on Saturday.")
    >>> tokens = TreebankWordTokenizer().tokenize(s)
    >>> expected = [(0, 3), (4, 9), (9, 10), (11, 16), (17, 20), (21, 23),
    ... (24, 34), (34, 35), (36, 43), (44, 46), (47, 52), (52, 54),
    ... (55, 60), (61, 67), (68, 72), (73, 75), (76, 83), (84, 89),
    ... (90, 98), (99, 103), (104, 109), (110, 119), (120, 122),
    ... (123, 131), (131, 132)]
    >>> output = list(align_tokens(tokens, s))
    >>> len(tokens) == len(expected) == len(output)  # Check that length of tokens and tuples are the same.
    True
    >>> expected == list(align_tokens(tokens, s))  # Check that the output is as expected.
    True
    >>> tokens == [s[start:end] for start, end in output]  # Check that the slices of the string corresponds to the tokens.
    True

:param tokens: The list of strings that are the result of tokenization
:type tokens: list(str)
:param sentence: The original string
:type sentence: str
:rtype: list(tuple(int,int))
r   zsubstring "z" not found in "rD   N)r	   r   r   append)tokenssentencepointoffsetstokenr:   es          r   align_tokensrW      s    < EG	VNN50E E
"~&  N	  	V{5'1A(1MNTUU	Vs   A
A$AA$N)rer   xml.sax.saxutilsr   r   r   r   r   r   r<   rL   rN   rW   r   r5   r   <module>rZ      s>     - D6,? ?D@@>'r5   