
    rhF                         d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 ddlmZ  G d	 d
      Zd Z ed      Z ed      Z e       Z G d d      Z	 	 	 	 	 	 	 	 	 ddZd Z	 	 	 ddZd Zy)    N)closing)isclass)StringIO)Path)Template   )config_contextc                       e Zd ZdZd Zd Zy)
_IDCounterz&Generate sequential ids with a prefix.c                      || _         d| _        y )Nr   )prefixcount)selfr   s     u/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/sklearn/utils/_repr_html/estimator.py__init__z_IDCounter.__init__   s    
    c                 b    | xj                   dz  c_         | j                   d| j                    S )N   -)r   r   r   s    r   get_idz_IDCounter.get_id   s(    

a
++a

|,,r   N)__name__
__module____qualname____doc__r   r    r   r   r   r      s    0-r   r   c                      t        t              j                  dz  } t        t              j                  dz  }| j                  d      }|j                  d      }| d| S )Nzestimator.cssz
params.csszutf-8)encoding
)r   __file__parent	read_text)estimator_css_fileparams_css_fileestimator_css
params_csss       r   _get_css_styler'      sb    h..@8n++l:O&00'0BM **G*<J_Bzl++r   zsk-container-idzsk-estimator-idc                   *    e Zd ZdZdddddddZd Zy)_VisualBlockac  HTML Representation of Estimator

    Parameters
    ----------
    kind : {'serial', 'parallel', 'single'}
        kind of HTML block

    estimators : list of estimators or `_VisualBlock`s or a single estimator
        If kind != 'single', then `estimators` is a list of
        estimators.
        If kind == 'single', then `estimators` is a single estimator.

    names : list of str, default=None
        If kind != 'single', then `names` corresponds to estimators.
        If kind == 'single', then `names` is a single string corresponding to
        the single estimator.

    name_details : list of str, str, or None, default=None
        If kind != 'single', then `name_details` corresponds to `names`.
        If kind == 'single', then `name_details` is a single string
        corresponding to the single estimator.

    name_caption : str, default=None
        The caption below the name. `None` stands for no caption.
        Only active when kind == 'single'.

    doc_link_label : str, default=None
        The label for the documentation link. If provided, the label would be
        "Documentation for {doc_link_label}". Otherwise it will look for `names`.
        Only active when kind == 'single'.

    dash_wrapped : bool, default=True
        If true, wrapped HTML element will be wrapped with a dashed border.
        Only active when kind != 'single'.
    NT)namesname_detailsname_captiondoc_link_labeldash_wrappedc                    || _         || _        || _        || _        || _        | j                   dv r |dt        |      z  }|dt        |      z  }|| _        || _        y )N)parallelserialN)kind
estimatorsr.   r,   r-   lenr*   r+   )r   r3   r4   r*   r+   r,   r-   r.   s           r   r   z_VisualBlock.__init__N   sm     	$((,99..}#j/1#&Z8
(r   c                     | S r2   r   r   s    r   _sk_visual_block_z_VisualBlock._sk_visual_block_h   s    r   )r   r   r   r   r   r7   r   r   r   r)   r)   )   s#    "R )4r   r)   c                    | j                  d| d| d|
 d       t        j                  |      }|t        j                  t        |            }|rdnd}t        j                         }|	rd}|d	| d
}n|d	| d
}d|
 d|	 d| d}	|dndt        j                  |       d}d| d| d}|	s|rd|	 | dnd}d| d|
 d| | d}d| d| d| d|
 dt        j                  |       d}|rdj                  || dg      }n|rd|vrdj                  |d| dg      }| j                  |       n| j                  d | d       | j                  d!       y)"a!	  Write labeled html with or without a dropdown with named details.

    Parameters
    ----------
    out : file-like object
        The file to write the HTML representation to.
    params: str
        If estimator has `get_params` method, this is the HTML representation
        of the estimator's parameters and their values. When the estimator
        does not have `get_params`, it is an empty string.
    name : str
        The label for the estimator. It corresponds either to the estimator class name
        for a simple estimator or in the case of a `Pipeline` and `ColumnTransformer`,
        it corresponds to the name of the step.
    name_details : str
        The details to show as content in the dropdown part of the toggleable label. It
        can contain information such as non-default parameters or column information for
        `ColumnTransformer`.
    name_caption : str, default=None
        The caption below the name. If `None`, no caption will be created.
    doc_link_label : str, default=None
        The label for the documentation link. If provided, the label would be
        "Documentation for {doc_link_label}". Otherwise it will look for `name`.
    outer_class : {"sk-label-container", "sk-item"}, default="sk-label-container"
        The CSS class for the outer container.
    inner_class : {"sk-label", "sk-estimator"}, default="sk-label"
        The CSS class for the inner container.
    checked : bool, default=False
        Whether the dropdown is folded or not. With a single estimator, we intend to
        unfold the content.
    doc_link : str, default=""
        The link to the documentation for the estimator. If an empty string, no link is
        added to the diagram. This can be generated for an estimator if it uses the
        `_HTMLDocumentationLinkMixin`.
    is_fitted_css_class : {"", "fitted"}
        The CSS class to indicate whether or not the estimator is fitted. The
        empty string means that the estimator is not fitted and "fitted" means that the
        estimator is fitted.
    is_fitted_icon : str, default=""
        The HTML representation to show the fitted information in the diagram. An empty
        string means that no information is shown.
    param_prefix : str, default=""
        The prefix to prepend to parameter names for nested estimators.
    z<div class="z"><div class=" z sk-toggleable">Nchecked z!<span>Online documentation</span>z<span>Documentation for </span>z <a class="sk-estimator-doc-link z)" rel="noreferrer" target="_blank" href="z">?z</a>z<div class="caption"></div>z
<div><div>z<div>z<label for="z" class="sk-toggleable__label z sk-toggleable__label-arrow">z</label>z><input class="sk-toggleable__control sk-hidden--visually" id="z" type="checkbox" >z#<div class="sk-toggleable__content z" data-param-prefix="">Pipelinez<pre>z</pre></div>z<label></div></div>)writehtmlescapestr_ESTIMATOR_ID_COUNTERr   join)outparamsnamer+   r,   r-   outer_classinner_classr:   doc_linkis_fitted_css_classis_fitted_iconparam_prefixchecked_strest_id	doc_labelname_caption_div	links_div
label_htmlfmt_strs                       r   _write_label_htmlrX   l   s   v II
{m $-q!4 55E	G ;;tD{{3|#45#*i&--/;I)6~6FgN	!6tfGD	23F2G H;;C*C	{RVX  # (\)B(C6J 	
 (vV4D3EVL > H:n-V4 	 6("@AT@U V++;*<YKxQ 	 MVH U*m1ZL 9--@,A B""&++l";!<B@ 	 ggw6(&(9:;Gz5ggw%~\(JKLG		'		GD6*+IInr   c                 N   t        | d      r	 | j                         S t        | t              rt        d| | |       S | t        d| dd      S t        | d      rt        |       s| j                  d      j                         D cg c],  \  }}t        |d      rt        |d      rt        |      s||f. }}}|rjt        d	|D cg c]  \  }}|	 c}}|D cg c]   \  }}| d
|j                  j
                   " c}}|D cg c]  \  }}t        |       c}}      S t        d| | j                  j
                  t        |             S # t        $ r/ t        d| | j                  j
                  t        |             cY S w xY wc c}}w c c}}w c c}}w c c}}w )z7Generate information about how to display an estimator.r7   single)r*   r+   None
get_paramsFdeepfitr0   z: )hasattrr7   	Exceptionr)   	__class__r   rE   
isinstancer   r\   items)	estimatorkeyestr4   _s        r   _get_visual_blockri      s   y-.	..00 )S!iyy
 	
 
	HivFSS y,'	0B &00e0<BBD
SsL)gc5.A'RU, #J

 

 #-.C.JTUhc3#b!7!7 89U5?@61cc#h@	  !!**^	 =  	))22 ^	 	"
 /U@s)   E 1F	F%F
F!5FFc                    |rt        |      }n"d}t        d      5  t        |      }ddd       t        |d      r|j                         }	nd}	j                  dv r|xs |j
                  }
|
rdnd}| j                  d| d	       |rNt        |d
      r-t        |d      r!|j                  d      j                         }nd}t        | ||||	|||       |j                  }| j                  d| d	       t        |j                  |j                  |j                        }|D ]  \  }}}|r&t        |d      r| |j                  d      d    d}n*t        |d      r|r|j                  d      d    dnd}n|}|dk(  rt        | |||||       p| j                  d       t!        d|gd      }t        | |||||       | j                  d        | j                  d       y|j                  dk(  rnt        |d      r|j                         j                         }nd}t        | ||j                  |j                  |j"                  |j$                  dd||	|||       yy# 1 sw Y   ExY w)aj  Write estimator to html in serial, parallel, or by itself (single).

    For multiple estimators, this function is called recursively.

    Parameters
    ----------
    out : file-like object
        The file to write the HTML representation to.
    estimator : estimator object
        The estimator to visualize.
    estimator_label : str
        The label for the estimator. It corresponds either to the estimator class name
        for simple estimator or in the case of `Pipeline` and `ColumnTransformer`, it
        corresponds to the name of the step.
    estimator_label_details : str
        The details to show as content in the dropdown part of the toggleable label.
        It can contain information as non-default parameters or column information for
        `ColumnTransformer`.
    is_fitted_css_class : {"", "fitted"}
        The CSS class to indicate whether or not the estimator is fitted or not. The
        empty string means that the estimator is not fitted and "fitted" means that the
        estimator is fitted.
    is_fitted_icon : str, default=""
        The HTML representation to show the fitted information in the diagram. An empty
        string means that no information is shown. If the estimator to be shown is not
        the first estimator (i.e. `first_call=False`), `is_fitted_icon` is always an
        empty string.
    first_call : bool, default=False
        Whether this is the first time this function is called.
    param_prefix : str, default=""
        The prefix to prepend to parameter names for nested estimators.
        For example, in a pipeline this might be "pipeline__stepname__".
    r;   T)print_changed_onlyN_get_doc_link)r1   r0   z sk-dashed-wrappedz<div class="sk-itemr?   r\   _get_params_htmlFr]   )rM   rN   rO   rP   z<div class="sk-split:r   __r1   )rN   rP   z<div class="sk-parallel-item">)r.   r=   rA   rZ   zsk-itemzsk-estimator)rK   rL   r:   rM   rN   rO   rP   )ri   r	   r`   rl   r3   r.   rB   rm   _repr_html_innerrX   zipr4   r*   r+   rn   _write_estimator_htmlr)   r,   r-   )rH   re   estimator_labelestimator_label_detailsrN   rO   
first_callrP   	est_blockrM   dashed_wrappeddash_clsrI   r3   	est_infosrg   rJ   r+   
new_prefixserial_blocks                       r   rs   rs   
  s   V %i0	t4 	5))4I	5 y/***,~~//#=y'='=+9'r		'z45y,/G-5 #333?PPR'!$7-)	 ~~		OD6,-	,,iooy?U?UV	'0 !	$#C| g 6 ,~djjoa.@-AD
w':>

3 2326B
)
x% (;!+ 		:;+Hse%P%  (;!+ 		(#C!	$F 			.!	8	#901//1BBDFFOO""""$$!& 3)%	
 
$O	5 	5s   I,,I6c           
      
   ddl m} ddlm} t	        | d      sd}d}n	  ||        d}d}d	| d
| d}t        t                     5 }t        j                         }t        t              }|j                  |      }	t        |       }
d}d|	 d| dt        j                  |
       d| d	}|j                  |       t!        || | j"                  j$                  |
d||       t'        t        t)        t*              j,                  dz        d      5 }|j/                         }ddd       d d}|j                  |       |j1                         }|cddd       S # |$ r d}d}Y >w xY w# 1 sw Y   KxY w# 1 sw Y   yxY w)a'  Build a HTML representation of an estimator.

    Read more in the :ref:`User Guide <visualizing_composite_estimators>`.

    Parameters
    ----------
    estimator : estimator object
        The estimator to visualize.

    Returns
    -------
    html: str
        HTML representation of estimator.

    Examples
    --------
    >>> from sklearn.utils._repr_html.estimator import estimator_html_repr
    >>> from sklearn.linear_model import LogisticRegression
    >>> estimator_html_repr(LogisticRegression())
    '<style>#sk-container-id...'
    r   )NotFittedError)check_is_fittedr_   z<span>Not fitted</span>r;   z<span>Fitted</span>fittedz#<span class="sk-estimator-doc-link z">ir<   )idzIn a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.z<style>z</style><body><div id="zC" class="sk-top-container"><div class="sk-text-repr-fallback"><pre>z	</pre><b>z+</b></div><div class="sk-container" hidden>T)rv   rN   rO   zestimator.jsrNz</div></div><script>z</script></body>)sklearn.exceptionsr~   sklearn.utils.validationr   r`   r   r   _CONTAINER_ID_COUNTERr   r   
_CSS_STYLE
substituterE   rC   rD   rB   rs   rb   r   openr   r    r!   readgetvalue)re   r~   r   status_labelrN   rO   rH   container_idstyle_templatestyle_with_idestimator_strfallback_msghtml_templatefscripthtml_endhtml_outputs                    r   estimator_html_reprr     s   , 289e$0 	%I&0L"* ..A-B C>	"  
	 1,335!*-&11\1BI" 	 m_ %$~ &KK./y G0	0 	 			- (( 3)	
 #d8n++n<=sC 	qVVXF	 *&1AB		(llnc1 1  	%4L"$	%b	 	S1 1s6   E CE9E-#0E9	E*)E*-E6	2E99F)	NNzsk-label-containerzsk-labelFr;   r;   r;   r;   )r;   Fr;   )rC   
contextlibr   inspectr   ior   pathlibr   stringr   r;   r	   r   r'   r   rF   r   r)   rX   ri   rs   r   r   r   r   <module>r      s          	- 	-, ##45 "#45 
@ @P $pf(b J
ZZr   