
    Mi                     ~   S SK r S SKrS SKJrJr  S SKJrJrJrJ	r	J
r
JrJr  SS\S\S\S\R                  4S jjrSS\S\S\S	\S\4
S
 jjrSS\S\S\S	\S\4
S jjrS\S\\   4S jrS\S\\   4S jrS\S\\   4S jrS\S\\   4S jrS\S\\ R                      4S jrS\4S jrS\4S jrS\S\\   4S jrg)    N)ListOptional)EMAIL_ADDRESS_PATTERNEMAIL_DATETIMETZ_PATTERNIMAGE_URL_PATTERNIP_ADDRESS_NAME_PATTERNIP_ADDRESS_PATTERN_REMAPI_ID_PATTERNUS_PHONE_NUMBERS_REtextpatternindexreturnc                     [        U[        5      (       a  US:  a  [        SU S35      eS n[        [        R
                  " X5      5       H  u  pEXB:X  d  M  UnM     Uc  [        SU SW S35      eU$ )Nr   zThe index is z'. Index must be a non-negative integer.zResult with index z& was not found. The largest index was .)
isinstanceint
ValueError	enumeraterefinditer)r   r   r   regex_matchiresults         w/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/unstructured/cleaners/extract.py_get_indexed_matchr      s    eS!!UQY=/VWXXKr{{79:	: K ; -eW4Z[\Z]]^_``    stripc                 z    [        XU5      nUR                  5       u  pVU SU nU(       a  UR                  5       $ U$ )a  Extracts texts that occurs before the specified pattern. By default, it will use
the first occurrence of the pattern (index 0). Use the index kwarg to choose a different
index.

Input
-----
strip: If True, removes trailing whitespace from the extracted string
N)r   spanrstrip)r   r   r   r   r   start_before_texts           r   extract_text_beforer%      sA     %TE:K!HEv,K#(;9k9r   c                 x    [        XU5      nUR                  5       u  pVXS nU(       a  UR                  5       $ U$ )a  Extracts texts that occurs before the specified pattern. By default, it will use
the first occurrence of the pattern (index 0). Use the index kwarg to choose a different
index.

Input
-----
strip: If True, removes leading whitespace from the extracted string
N)r   r    lstrip)r   r   r   r   r   r#   endr$   s           r   extract_text_afterr)   .   s?     %TE:KFAt*K#(;9k9r   c                 T    [         R                  " [        U R                  5       5      $ N)r   findallr   lowerr   s    r   extract_email_addressr/   =   s    ::+TZZ\::r   c                 8    [         R                  " [        U 5      $ r+   )r   r,   r	   r.   s    r   extract_ip_addressr1   A   s    ::+T22r   c                 8    [         R                  " [        U 5      $ r+   )r   r,   r   r.   s    r   extract_ip_address_namer3   E   s    ::-t44r   c                     [         R                  " [        U 5      nU Vs/ s H  o"R                  SS5      PM     nnU$ s  snf )N; )r   r,   r
   replace)r   mapi_idsmids      r   extract_mapi_idr:   I   s9    zz/40H089C$H9O :s   ?c                     [         R                  " [        U 5      n[        U5      S:  a#  [        R                  R                  US   S5      $ g )Nr   z%a, %d %b %Y %H:%M:%S %z)r   r,   r   lendatetimestrptime)r   date_extractionss     r   extract_datetimetzr@   O   sE    zz":DA
q   ))*:1*=?YZZr   c                     [         R                  " U 5      nUc  gUR                  5       u  p#XU nUR                  5       $ )zExtracts a US phone number from a section of text that includes a phone number. If there
is no phone number present, the result will be an empty string.

Example
-------
extract_phone_number("Phone Number: 215-867-5309") -> "215-867-5309"
r6   )r   searchr    r   )r   r   r"   r(   phone_numbers        r   extract_us_phone_numberrD   W   sE     &,,T2K!!#JEc?Lr   c                    Su  pp4U R                  5       n[        SUS   ;  SUS   ;   /5      (       a  XU4$ [        R                   " SUS   S9nUS   (       d  US	 [        US   5      S:  a  XU4$ UtpU(       a0   Utp#nS	R                  U5      nU(       a  S	R                  U5      OS
nXU4$ ! [         a    Un N=f = f)a  Extracts the start of bulleted text sections bullets
accounting numeric and alphanumeric types.

Output
-----
tuple(section, sub_section, sub_sub_section): Each bullet partition
is a string or None if not present.

Example
-------
This is a very important point -> (None, None, None)
1.1 This is a very important point -> ("1", "1", None)
a.1 This is a very important point -> ("a", "1", None)
)NNNNr   r   z..z[\.])r   string   r6   N)splitanyr   r<   r   join)r   abctemptext_spbulletr#   s           r   extract_ordered_bulletsrR   h   s     +MA!jjlG
Cwqz!471:#5677QwXXggaj9F":2J
6!9~QwHA	HA1 GGAJBGGAJ7N	  	A	s   >B1 1C ?C c                 8    [         R                  " [        U 5      $ r+   )r   r,   r   r.   s    r   extract_image_urls_from_htmlrT      s    ::'..r   )r   )r   T)r=   r   typingr   r   unstructured.nlp.patternsr   r   r   r   r	   r
   r   strr   Matchr   boolr%   r)   r/   r1   r3   r:   r@   rD   tuplerR   rT    r   r   <module>r\      s>    	 !  S 3 s 288 :c :C : : :X[ ::S :3 :s :t :WZ :; ;S	 ;3S 3T#Y 35# 5$s) 5# $s) S Xh.?.?%@  #  "#U #L/s /tCy /r   