
    sgwO                        d dl Z 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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 G d d      Zy)    N)closing)isclass)StringIO)Path)Template   )__version__config_context   )parse_versionc                       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/venv/lib/python3.12/site-packages/sklearn/utils/_estimator_html_repr.py__init__z_IDCounter.__init__   s    
    c                 b    | xj                   dz  c_         | j                   d| j                    S )Nr   -)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      j                  d      S )Nz.csszutf-8)encoding)r   __file__with_suffix	read_textr   r   r   _get_css_styler$      s%    >%%f-777IIr   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   r0   r1   r'   r(   r)   r*   r+   s           r   r   z_VisualBlock.__init__J   sm     	$((,99..}#j/1#&Z8
(r   c                     | S r/   r   r   s    r   _sk_visual_block_z_VisualBlock._sk_visual_block_d   s    r   )r   r   r   r   r   r4   r   r   r   r&   r&   %   s#    "R )4r   r&   c                 2   | 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| d}| 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.
    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.
    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"><pre>z</pre></div> z<label></div></div>)writehtmlescapestr_ESTIMATOR_ID_COUNTERr   )outnamer(   r)   r*   outer_classinner_classr7   doc_linkis_fitted_css_classis_fitted_iconchecked_strest_id	doc_labelname_caption_div	links_div
label_htmlfmt_strs                     r   _write_label_htmlrP   h   s   f 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 	 			'		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.r4   single)r'   r(   None
get_paramsF)deepfitr-   z: )hasattrr4   	Exceptionr&   	__class__r   r@   
isinstancer   rT   items)	estimatorkeyestr1   _s        r   _get_visual_blockr`      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                 p   |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	       |rt        | |||||
       |j                  }| j                  d| d	       t        |j                  |j                  |j                        }|D ]]  \  }}}|dk(  rt        | ||||       | j                  d       t        d|gd      }t        | ||||       | j                  d       _ | j                  d       y|j                  dk(  r?t        | |j                  |j                  |j                  |j                  dd||||       yy# 1 sw Y   xY w)a  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.
    r8   T)print_changed_onlyN_get_doc_link)r.   r-   z sk-dashed-wrappedz<div class="sk-itemz">)rF   rG   rH   z<div class="sk-r.   )rG   z<div class="sk-parallel-item">F)r+   r:   r<   rR   zsk-itemzsk-estimator)rD   rE   r7   rF   rG   rH   )r`   r
   rW   rc   r0   r+   r=   rP   zipr1   r'   r(   _write_estimator_htmlr&   r)   r*   )rB   r\   estimator_labelestimator_label_detailsrG   rH   
first_call	est_blockrF   dashed_wrappeddash_clsr0   	est_infosr^   rC   r(   serial_blocks                    r   re   re      s   N %i0	t4 	5))4I	5 y/***,~~//#=y'='=+9'r		'z45'!$7- ~~		OD6,-	,,iooy?U?UV	'0 	$#C|x% (; 		:;+Hse%P%  (; 		(#)	$, 			.!	8	#OO""""$$!& 3)	
 
$c	5 	5s   F++F5c           
      T   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||       |j                  d       |j'                         }|cddd       S # |$ r d}d}Y w x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._estimator_html_repr import estimator_html_repr
    >>> from sklearn.linear_model import LogisticRegression
    >>> estimator_html_repr(LogisticRegression())
    '<style>...</div>'
    r   )NotFittedError)check_is_fittedrV   z<span>Not fitted</span>r8   z<span>Fitted</span>fittedz#<span class="sk-estimator-doc-link z">ir9   )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><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)rh   rG   rH   r<   N)sklearn.exceptionsro   sklearn.utils.validationrp   rW   r   r   _CONTAINER_ID_COUNTERr   r   
_CSS_STYLE
substituter@   r>   r?   r=   re   rY   r   getvalue)r\   ro   rp   status_labelrG   rH   rB   container_idstyle_templatestyle_with_idestimator_strfallback_msghtml_templatehtml_outputs                 r   estimator_html_reprr   e  sl   , 289e$0 	%I&0L"* ..A-B C>	"  
	 ,,335!*-&11\1BI" 	 m_ %$~ &KK./y G00 	 			- (( 3)	
 			.!llnY, ,  	%4L"$	%, ,s   D B>D	DDD'c                   R    e Zd ZdZdZdZed        Zej                  d        Zd Z	y)_HTMLDocumentationLinkMixina3	  Mixin class allowing to generate a link to the API documentation.

    This mixin relies on three attributes:
    - `_doc_link_module`: it corresponds to the root module (e.g. `sklearn`). Using this
      mixin, the default value is `sklearn`.
    - `_doc_link_template`: it corresponds to the template used to generate the
      link to the API documentation. Using this mixin, the default value is
      `"https://scikit-learn.org/{version_url}/modules/generated/
      {estimator_module}.{estimator_name}.html"`.
    - `_doc_link_url_param_generator`: it corresponds to a function that generates the
      parameters to be used in the template when the estimator module and name are not
      sufficient.

    The method :meth:`_get_doc_link` generates the link to the API documentation for a
    given estimator.

    This useful provides all the necessary states for
    :func:`sklearn.utils.estimator_html_repr` to generate a link to the API
    documentation for the estimator HTML diagram.

    Examples
    --------
    If the default values for `_doc_link_module`, `_doc_link_template` are not suitable,
    then you can override them and provide a method to generate the URL parameters:
    >>> from sklearn.base import BaseEstimator
    >>> doc_link_template = "https://address.local/{single_param}.html"
    >>> def url_param_generator(estimator):
    ...     return {"single_param": estimator.__class__.__name__}
    >>> class MyEstimator(BaseEstimator):
    ...     # use "builtins" since it is the associated module when declaring
    ...     # the class in a docstring
    ...     _doc_link_module = "builtins"
    ...     _doc_link_template = doc_link_template
    ...     _doc_link_url_param_generator = url_param_generator
    >>> estimator = MyEstimator()
    >>> estimator._get_doc_link()
    'https://address.local/MyEstimator.html'

    If instead of overriding the attributes inside the class definition, you want to
    override a class instance, you can use `types.MethodType` to bind the method to the
    instance:
    >>> import types
    >>> estimator = BaseEstimator()
    >>> estimator._doc_link_template = doc_link_template
    >>> estimator._doc_link_url_param_generator = types.MethodType(
    ...     url_param_generator, estimator)
    >>> estimator._get_doc_link()
    'https://address.local/BaseEstimator.html'
    sklearnNc                     t        t              }|j                  |j                   d|j                   }nd}t        | dd| d      S )N.dev__doc_link_templatezhttps://scikit-learn.org/z;/modules/generated/{estimator_module}.{estimator_name}.html)r   r	   r   majorminorgetattr)r   sklearn_versionversion_urls      r   _doc_link_templatez._HTMLDocumentationLinkMixin._doc_link_template  s_    '4&,2231_5J5J4KLKK!+K= 9; ;	
 	
r   c                     t        | d|       y )Nr   )setattr)r   values     r   r   z._HTMLDocumentationLinkMixin._doc_link_template  s    +U3r   c                    | j                   j                  j                  d      d   | j                  k7  ry| j                  || j                   j
                  }dj                  t        j                  d | j                   j                  j                  d                  }| j                  j                  ||      S  | j                  j                  di | j	                         S )a  Generates a link to the API documentation for a given estimator.

        This method generates the link to the estimator's documentation page
        by using the template defined by the attribute `_doc_link_template`.

        Returns
        -------
        url : str
            The URL to the API documentation for this estimator. If the estimator does
            not belong to module `_doc_link_module`, the empty string (i.e. `""`) is
            returned.
        r   r   r8   c                 &    | j                  d       S )Nr_   )
startswith)parts    r   <lambda>z;_HTMLDocumentationLinkMixin._get_doc_link.<locals>.<lambda>  s    T__S%9!9 r   )estimator_moduleestimator_namer   )rY   r   split_doc_link_module_doc_link_url_param_generatorr   join	itertools	takewhiler   format)r   r   r   s      r   rc   z)_HTMLDocumentationLinkMixin._get_doc_link  s     >>$$**3/2d6K6KK--5!^^44N  #xx##9NN--33C8  **11!1. 2   .t&&--U0R0R0TUUr   )
r   r   r   r   r   r   propertyr   setterrc   r   r   r   r   r     sH    0d !$(!
 
 4 4Vr   r   )NNzsk-label-containerzsk-labelFr8   r8   r8   )r8   F)r>   r   
contextlibr   inspectr   ior   pathlibr   stringr   r8   r	   r
   fixesr   r   r$   ru   rA   rv   r&   rP   r`   re   r   r   r   r   r   <module>r      s           *  	- 	-J ##45 "#45 
@ @N $cL(b i
XUphV hVr   