
    9i!                         S SK r S SKJr  S SKJr  S SKrS SKJrJ	r	  SSK
JrJrJrJr   " S S\\\5      r " S	 S
\\\5      rg)    N)Path)Dict)Image	ImageDraw   )BaseCVResult	HtmlMixin	JsonMixin	XlsxMixinc                      ^  \ rS rSrSrS\SS4U 4S jjrU 4S jrS\\\4   4S jr	S\\\4   4S	 jr
S\\\4   4S
 jrS\\\4   4S jrSrU =r$ )SingleTableRecognitionResult   zsingle table recognition resultdatareturnNc                 |   > [         TU ]  U5        [        R                  " U 5        [        R                  " U 5        g )Nsuper__init__r	   r   selfr   	__class__s     t/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/inference/pipelines/table_recognition/result.pyr   %SingleTableRecognitionResult.__init__   s,    4 4     c                    > [         TU ]  5       nU S   =nb+  [        U5      nUR                  UR                  pTU SU U 3$ U$ N
page_index_r   _get_input_fnr   stemsuffixr   fnpage_idxfpr!   r"   r   s         r   r    *SingleTableRecognitionResult._get_input_fn!   R    W"$\**H7bB77BII&V1XJvh//Ir   c                     SU S   0$ )Converts the prediction to its corresponding HTML representation.

Returns:
    Dict[str, str]: The str type HTML representation result.
pred	pred_html r   s    r   _to_html%SingleTableRecognitionResult._to_html*        [)**r   c                     SU S   0$ )zConverts the prediction HTML to an XLSX file path.

Returns:
    str: The path to the XLSX file containing the prediction data.
r+   r,   r-   r.   s    r   _to_xlsx%SingleTableRecognitionResult._to_xlsx2   r1   r   c                 j    0 nU S   US'   U S   US'   U S   US'   [         R                  " U/UQ70 UD6$ )H  Converts the instance's attributes to a dictionary and then to a string.

Args:
    *args: Additional positional arguments passed to the base class method.
    **kwargs: Additional keyword arguments passed to the base class method.

Returns:
    Dict[str, str]: A dictionary with the instance's attributes converted to strings.
cell_box_listr,   table_ocr_pred)r
   _to_strr   argskwargsr   s       r   r9   $SingleTableRecognitionResult._to_str:   sS      $_ 5_ -[!%&6!7  7777r   c                 j    0 nU S   US'   U S   US'   U S   US'   [         R                  " U/UQ70 UD6$ )#  
Converts the object's data to a JSON dictionary.

Args:
    *args: Positional arguments passed to the JsonMixin._to_json method.
    **kwargs: Keyword arguments passed to the JsonMixin._to_json method.

Returns:
    Dict[str, str]: A dictionary containing the object's data in JSON format.
r7   r,   r8   )r
   _to_jsonr:   s       r   r@   %SingleTableRecognitionResult._to_jsonJ   sS      $_ 5_ -[!%&6!7!!$8888r   r-   )__name__
__module____qualname____firstlineno____doc__r   r   r    strr/   r3   r9   r@   __static_attributes____classcell__r   s   @r   r   r      ss    )!T !d !
+$sCx. ++$sCx. +8$sCx. 8 94S> 9 9r   r   c                      ^  \ rS rSrSrS\SS4U 4S jjrU 4S jrS\\\	R                  4   4S jrS\\\4   4S	 jrS\\\4   4S
 jrS\\\4   4S jrS\\\4   4S jrSrU =r$ )TableRecognitionResult\   zTable Recognition Resultr   r   Nc                    > [         TU ]  U5        [        R                  " U 5        [        R                  " U 5        U S   c  0 U S'   g g )Nlayout_det_resr   r   s     r   r   TableRecognitionResult.__init___   sH    4 4  !)%'D!" *r   c                    > [         TU ]  5       nU S   =nb+  [        U5      nUR                  UR                  pTU SU U 3$ U$ r   r   r#   s         r   r    $TableRecognitionResult._get_input_fnf   r(   r   c           
         0 nU S   n[        U5      S:  a  UR                  S   US'   U S   nUS   (       a  UR                  " S0 U S   R                  D6  UR                  " S0 U S   R                  D6  [        U S   5      S:  a  [        R                  " [
        R                  " U S   S	   S S 2S S 2S S S
24   5      5      n[        R                  " U5      nSn[        [        U S   5      5       HK  nU S   U   nUS   n	U	 H5  n
U
 Vs/ s H  n[        U5      PM     snu  ppUR                  XX/USS9  M7     MM     XAS'   U$ s  snf )NrO   r   resmodel_settingsuse_doc_preprocessordoc_preprocessor_resoverall_ocr_restable_res_list
output_img)   r   r   r7      )outlinewidthtable_cell_imgr-   )lenimgupdater   	fromarraycopydeepcopyr   Drawrangeint	rectangle)r   res_img_dictrO   rU   r`   
table_drawrectangle_colorsno	table_resr7   boxposx1y1x2y2s                   r   _to_imgTableRecognitionResult._to_imgo   so   ./~"-;-?-?-FL)*./01C$'=">"B"BC:d#4599:t$%&*"__d#9:<HAtQStTUN #7J)OS&6!789 !1237	 )/ :(C:=%>#3c#h#%>NBB(((/ )  ) : .<)* &?s   E	c                    0 nU S   US'   U S   US'   U S   US'   U S   S   (       a  U S   R                   S   US'   [        U S   5      S:  a  U S   R                   S   US'   U S	   R                   S   US	'   / US
'   [        [        U S
   5      5       H,  nU S
   U   nUS
   R                  UR                   S   5        M.     [        R
                  " U/UQ70 UD6$ )r6   
input_pathr   rU   rV   rW   rT   rO   r   rX   rY   )rG   ra   rh   appendr
   r9   r   r;   r<   r   rn   ro   s         r   r9   TableRecognitionResult._to_str   s    !,/\!,/\!%&6!7 !"89+/0F+G+K+KE+RD'(t$%&*%)*:%;%?%?%FD!""&'8"9"="=e"D!#T"2345C-.s3I!")))--*>? 6   7777r   c                    0 nU S   US'   U S   US'   U S   US'   U S   S   (       a  U S   R                   S   US'   [        U S   5      S:  a  U S   R                   S   US'   U S	   R                   S   US	'   / US
'   [        [        U S
   5      5       H,  nU S
   U   nUS
   R                  UR                   S   5        M.     [        R
                  " U/UQ70 UD6$ )r?   ry   r   rU   rV   rW   rT   rO   r   rX   rY   )jsonra   rh   rz   r
   r@   r{   s         r   r@   TableRecognitionResult._to_json   s    !,/\!,/\!%&6!7 !"89+/0F+G+L+LU+SD'(t$%&*%)*:%;%@%@%GD!""&'8"9">">u"E!#T"2345C-.s3I!")))..*?@ 6 !!$8888r   c                     0 n[        [        U S   5      5       H<  nU S   U   nUS   nSU 3nUR                  S   X'   X   R                  SS5      X'   M>     U$ )r*   rY   table_region_idtable_r+   z<table>z<table border="1">)rh   ra   htmlreplace)r   res_html_dictrn   ro   r   keys         r   r/   TableRecognitionResult._to_html   s     T"2345C-.s3I'(9:O?+,C!*!7M!.!3!;!;/"M 6 r   c                     0 n[        [        U S   5      5       H&  nU S   U   nUS   nSU 3nUR                  S   X'   M(     U$ )zzConverts the prediction HTML to an XLSX file path.

Returns:
    Dict[str, str]: The str type XLSX representation result.
rY   r   r   r+   )rh   ra   xlsx)r   res_xlsx_dictrn   ro   r   r   s         r   r3   TableRecognitionResult._to_xlsx   sd     T"2345C-.s3I'(9:O?+,C!*!7M	 6
 r   r-   )rB   rC   rD   rE   rF   r   r   r    rG   npndarrayrv   r9   r@   r/   r3   rH   rI   rJ   s   @r   rL   rL   \   s    "(T (d (c2::o. :8$sCx. 8294S> 94$sCx. "$sCx.  r   rL   )re   pathlibr   typingr   numpyr   PILr   r   common.resultr   r	   r
   r   r   rL   r-   r   r   <module>r      sA          J J@9<I @9F@\9i @r   