
    Mi              	         S SK Jr  S SKrS SKrS SKJrJrJrJr  S SK	J
r
  S SKJrJr  S SKJr  S SKJrJrJrJrJrJrJrJrJrJr  S SKJr  S S	KJr  S S
KJ r J!r!  S SK"J#r#  S SK$J%r%J&r&  S SK'J(r(J)r)J*r*J+r+J,r,J-r-  \%" \R\                  5      \
 SSSSSSS.               SS jjj5       5       r/  S       SS jjr0      SS jr1SS jr2 S       SS jjr3 S       SS jjr4S S jr5g)!    )annotationsN)IOAnyCallableLiteral)add_chunking_strategy)auto_paragraph_grouperclean_bullets)CoordinateSystem)
AddressElementElementMetadataEmailAddressFooterHeaderListItemNarrativeTextTextTitle)read_txt_file)FileType)PARAGRAPH_PATTERNUNICODE_BULLETS_RE)exactly_one)apply_metadataget_last_modified_date)is_bulleted_textis_email_addressis_possible_narrative_textis_possible_numbered_listis_possible_titleis_us_city_state_ziptext)fileencodingr#   paragraph_grouperdetection_originc               0   Ub$  UR                  5       S:X  a  U(       d	  U (       d  / $ [        XUS9  SnU b  [        XS9u  p'OUb  [        XS9u  p'OUb  [        U5      nUSL a  OUb	  U" U5      nO[	        U5      n[        U5      n/ n	[        U (       a  [        U 5      OSS9n
XZl        U He  nUR                  5       nU(       d  M  [        U5      (       a  M.  [        U5      n[        R                  " U
5      Ul        U	R                  U5        Mg     U	$ )a  Partition a .txt documents into its constituent paragraph elements.

If paragraphs are below "min_partition" or above "max_partition" boundaries,
they are combined or split.
Parameters
----------
filename
    A string defining the target filename path.
file
    A file-like object using "rb" mode --> open(filename, "rb").
encoding
    The encoding method used to decode the input bytes when drawn from `filename` or `file`.
    Defaults to "utf-8".
text
    The string representation of the .txt document.
paragrapher_grouper
    A str -> str function for fixing paragraphs that are interrupted by line breaks
    for formatting purposes.
N )filenamer$   r#   )r*   r%   )r$   r%   F)last_modified)stripr   r   strr	   _split_by_paragraphr   r   r'   _is_empty_bulletelement_from_textcopydeepcopymetadataappend)r*   r$   r%   r#   r&   r'   kwargs	file_textfile_contentelementsr3   ctextelements                u/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/unstructured/partition/text.pypartition_textr<   (   s   > DJJLB.tH	 48I+XQ)		+I)		I	E!		&%i0	*95	&y1L H:B,X6H !15)%00'.G#}}X6GOOG$  O    c                   [        X5      (       a  [        U UUS9$ [        X5      (       a  [        U UUS9$ [	        U 5      (       a  [        U 5      n[        UUUS9$ [        U 5      (       a	  [        U S9$ [        U 5      (       a  [        U UUS9$ [        U 5      (       a  [        U UUS9$ [        U 5      (       a  [        U UUS9$ [        U 5      (       a  [        U UUS9$ [!        U UUS9$ )N)r#   coordinatescoordinate_systemr#   )_is_in_header_positionr   _is_in_footer_positionr   r   r
   r   r   r   r"   r   r    r   r   r!   r   r   )r#   r?   r@   
clean_texts       r;   r0   r0   o   s/   
 k==#/
 	

 
 	?	?#/
 	

 
$		"4(
#/
 	

 
$		&&	d	#	##/
 	

 
#4	(	(#/
 	

 
$D	)	)#/
 	

 
4	 	 #/
 	
 #/
 	
r=   c                Z    [        S U  5       5      [        U 5      -  nX!R                  -  $ )Nc              3  *   #    U  H	  oS    v   M     g7f)   N ).0
coordinates     r;   	<genexpr>)_get_height_percentage.<locals>.<genexpr>   s     <*1s   )sumlenheight)r?   r@   avg_ys      r;   _get_height_percentagerQ      s-     <<<s;?OOE++++r=   c                j    [        [        R                  " U 5      =(       a    [        U 5      S:H  5      $ )z(Checks if input text is an empty bullet.rG   )boolr   matchrN   rA   s    r;   r/   r/      s&    "((.A3t9>BBr=   c                .    U b  Uc  g[        X5      nX2:  $ )zVChecks to see if the position of the text indicates that the text belongs
to a footer.FrQ   r?   r@   	thresholdheight_percentages       r;   rC   rC      s'     /7.{N((r=   c                .    U b  Uc  g[        X5      nX2:  $ )zVChecks to see if the position of the text indicates that the text belongs to a header.FrV   rW   s       r;   rB   rB      s'     /7.{N((r=   c                T    [         R                  " [        U R                  5       5      $ )zSplit text into paragraphs.)resplitr   r,   )r6   s    r;   r.   r.      s    88%y'899r=   )N)r*   
str | Noner$   zIO[bytes] | Noner%   r^   r#   r^   r&   z,Callable[[str], str] | Literal[False] | Noner'   r^   r5   r   returnzlist[Element])NN)r#   r-   r?   &tuple[tuple[float, float], ...] | Noner@   CoordinateSystem | Noner_   r   )r?   ztuple[tuple[float, float], ...]r@   r   r_   float)r#   r-   r_   rS   )g(\?)r?   r`   r@   ra   rX   rb   r_   rS   )gQ?)r6   r-   r_   z	list[str])6
__future__r   r1   r\   typingr   r   r   r   unstructured.chunkingr   unstructured.cleaners.corer	   r
   "unstructured.documents.coordinatesr   unstructured.documents.elementsr   r   r   r   r   r   r   r   r   r    unstructured.file_utils.encodingr   unstructured.file_utils.modelr   unstructured.nlp.patternsr   r   $unstructured.partition.common.commonr   &unstructured.partition.common.metadatar   r    unstructured.partition.text_typer   r   r   r    r!   r"   TXTr<   r0   rQ   r/   rC   rB   r.   rH   r=   r;   <module>rp      s   "  	 - - 7 @   ; 2 K < Y  B "FJ#)BB B 	B
 B DB !B B B  BN ;?157

7
77
 /7
 	7
~,0,', ,C )7).) ) 
	)" 
)7
).
) 
) 
	
):r=   