
    :Sh8                         d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
  G d de
          Z G d d	e          Z G d
 d          Zd ZdefdZd Zd ZdS )aV  
This module borrows and adapts `Pipeline` from `sklearn.pipeline` and
`TransformerMixin` from `sklearn.base` in the scikit-learn framework
(commit hash d205638475ca542dc46862652e3bb0be663a8eac) to be precise).
Both are BSD licensed and allow for this sort of thing; attribution
is given as a comment above each class. License reproduced below:

BSD 3-Clause License

Copyright (c) 2007-2022 The scikit-learn developers.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    )defaultdict)islice)AnyCallableOptional)Protocolc                   B    e Zd ZU ed         ed<   eegef         ed<   dS )TransformerProtocol).r
   fit	transformN)__name__
__module____qualname__r   __annotations__r        \/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/ffsubsync/sklearn_shim.pyr
   r
   -   s;         	,	----s
######r   r
   c            	       8    e Zd ZdZddedee         dedefdZdS )	TransformerMixinz!Mixin class for all transformers.NXy
fit_paramsreturnc                     |! | j         |fi |                    |          S  | j         ||fi |                    |          S )a6  
        Fit to data, then transform it.
        Fits transformer to X and y with optional parameters fit_params
        and returns a transformed version of X.
        Parameters
        ----------
        X : ndarray of shape (n_samples, n_features)
            Training set.
        y : ndarray of shape (n_samples,), default=None
            Target values.
        **fit_params : dict
            Additional fit parameters.
        Returns
        -------
        X_new : ndarray array of shape (n_samples, n_features_new)
            Transformed array.
        )r   r   )selfr   r   r   s       r   fit_transformzTransformerMixin.fit_transform7   s]    ( 948A,,,,66q999 48Aq//J//99!<<<r   N)r   r   r   __doc__r   r   r   r   r   r   r   r   4   sT        ++= =s =x} =3 =SV = = = = = =r   r   c                       e Zd ZddZd ZddZdefdZd Ze	d	             Z
e	d
             Ze	d             Zd ZddZddZddZe	d             Zd Ze	d             Ze	d             Ze	d             ZdS )PipelineFc                 J    || _         || _        |                                  d S r   )stepsverbose_validate_steps)r   r"   r#   s      r   __init__zPipeline.__init__Z   s(    
r   c           	         t          | j         \  }}|d d         }|d         }|D ]^}||dk    rt          |d          st          |d          rt          |d          s#t          d|dt	          |          d          _|9|dk    r5t          |d          s't          d	|dt	          |          d          d S d S d S )
Npassthroughr   r   r   znAll intermediate steps should be transformers and implement fit and transform or be the string 'passthrough' 'z' (type z	) doesn'tzLLast step of Pipeline should implement fit or be the string 'passthrough'. ')zipr"   hasattr	TypeErrortype)r   names
estimatorstransformers	estimatorts         r   r$   zPipeline._validate_steps_   s&   ,z "#2#rN	 	 	AyA..Au%% O)D)D W;N N   i 1247777<   !]**Iu-- + ) -6IItIH  	 "!****r   Tc              #      K   t          | j                  }|s|dz  }t          t          | j        d|                    D ]!\  }\  }}|s|||fV  ||dk    r|||fV  "dS )z
        Generate (idx, (name, trans)) tuples from self.steps

        When filter_passthrough is True, 'passthrough' and None transformers
        are filtered out.
           r   Nr(   )lenr"   	enumerater   )r   
with_finalfilter_passthroughstopidxnametranss          r   _iterzPipeline._iter   s       4: 	AID"+F4:q$,G,G"H"H 	' 	'C$% '4&&&&&"u'='=4&&&&		' 	'r   r   c                 *    t          | j                  S )z4
        Returns the length of the Pipeline
        )r4   r"   r   s    r   __len__zPipeline.__len__   s     4:r   c                     t          |t                    r8|j        dvrt          d          |                     | j        |                   S 	 | j        |         \  }}n# t          $ r | j        |         cY S w xY w|S )a  Returns a sub-pipeline or a single esimtator in the pipeline

        Indexing with an integer will return an estimator; using a slice
        returns another Pipeline instance which copies a slice of this
        Pipeline. This copy is shallow: modifying (or fitting) estimators in
        the sub-pipeline will affect the larger pipeline and vice-versa.
        However, replacing a value in `step` will not affect a copy.
        )r3   Nz*Pipeline slicing only supports a step of 1)
isinstanceslicestep
ValueError	__class__r"   r+   named_steps)r   indr:   ests       r   __getitem__zPipeline.__getitem__   s     c5!! 	3xy(( !MNNN>>$*S/222	)
3ID## 	) 	) 	)#C((((	) 
s   A   A:9A:c                 2    | j         d         d         j        S )Nr'   r3   )r"   _estimator_typer>   s    r   rK   zPipeline._estimator_type   s    z"~a 00r   c                 *    t          | j                  S r   )dictr"   r>   s    r   rF   zPipeline.named_steps   s    DJr   c                 4    | j         d         d         }|dn|S )Nr'   r3   r(   )r"   )r   r0   s     r   _final_estimatorzPipeline._final_estimator   s!    JrN1%	 ) 1}}y@r   c                 n    | j         sd S | j        |         \  }}d|dz   t          | j                  |fz  S )Nz(step %d of %d) Processing %sr3   )r#   r"   r4   )r   step_idxr:   rC   s       r   _log_messagezPipeline._log_message   s@    | 	4Z)
d.(Q,DJQU1VVVr   Nc                 2   t          | j                  | _        |                                  d | j        D             }|                                D ]O\  }}d|vr"t	          d                    |                    |                    dd          \  }}|||         |<   P|                     dd          D ]4\  }	}
}||dk    rt          |||d fi ||
         \  }}|
|f| j        |	<   5| j	        dk    r|i fS ||| j        d         d	                  fS )
Nc                     i | ]
\  }}||i S r   r   ).0r:   rC   s      r   
<dictcomp>z!Pipeline._fit.<locals>.<dictcomp>   s#    VVVtTEUD"EUEUEUr   __zPipeline.fit does not accept the {} parameter. You can pass parameters to specific steps of your pipeline using the stepname__parameter format, e.g. `Pipeline.fit(X, y, logisticregression__sample_weight=sample_weight)`.r3   F)r6   r7   r(   r'   r   )
listr"   r$   itemsrD   formatsplitr<   _fit_transform_onerO   )r   r   r   r   fit_params_stepspnamepvalrC   paramrQ   r:   transformerfitted_transformers                r   _fitzPipeline._fit   st   $*%%
VVtzVVV%++-- 
	1 
	1KE45   ( )/u    ++dA..KD%,0T"5))+/:: ,6 ,
 ,
 	> 	>'HdK "k]&B&B %7Q4% %+;D+A% %!A! %)*<#=DJx   M11b5L"4:b>!#4555r   c                 h     | j         ||fi |\  }}| j        dk    r | j        j        ||fi | | S )a  Fit the model

        Fit all the transforms one after the other and transform the
        data, then fit the transformed data using the final estimator.

        Parameters
        ----------
        X : iterable
            Training data. Must fulfill input requirements of first step of the
            pipeline.

        y : iterable, default=None
            Training targets. Must fulfill label requirements for all steps of
            the pipeline.

        **fit_params : dict of string -> object
            Parameters passed to the ``fit`` method of each step, where
            each parameter name is prefixed such that parameter ``p`` for step
            ``s`` has key ``s__p``.

        Returns
        -------
        self : Pipeline
            This estimator
        r(   )rc   rO   r   )r   r   r   r   Xts        r   r   zPipeline.fit   sV    4 #1a66:66J M11%D!%b!::z:::r   c                     | j         } | j        ||fi |\  }}|dk    r|S t          |d          r |j        ||fi |S  |j        ||fi |                    |          S )a  Fit the model and transform with the final estimator

        Fits all the transforms one after the other and transforms the
        data, then uses fit_transform on transformed data with the final
        estimator.

        Parameters
        ----------
        X : iterable
            Training data. Must fulfill input requirements of first step of the
            pipeline.

        y : iterable, default=None
            Training targets. Must fulfill label requirements for all steps of
            the pipeline.

        **fit_params : dict of string -> object
            Parameters passed to the ``fit`` method of each step, where
            each parameter name is prefixed such that parameter ``p`` for step
            ``s`` has key ``s__p``.

        Returns
        -------
        Xt : array-like of shape  (n_samples, n_transformed_features)
            Transformed samples
        r(   r   )rO   rc   r*   r   r   r   )r   r   r   r   	last_stepre   s         r   r   zPipeline.fit_transform  s    6 )	"1a66:66J%%I9o.. 	D*9*2q??J??? 9=Q55*55??CCCr   c                 >    | j         dk    r| j         j         | j        S )a  Apply transforms, and transform with the final estimator

        This also works where final estimator is ``None``: all prior
        transformations are applied.

        Parameters
        ----------
        X : iterable
            Data to transform. Must fulfill input requirements of first step
            of the pipeline.

        Returns
        -------
        Xt : array-like of shape  (n_samples, n_transformed_features)
        r(   )rO   r   
_transformr>   s    r   r   zPipeline.transform&  s&    &  M11!++r   c                 j    |}|                                  D ]\  }}}|                    |          }|S r   )r<   r   )r   r   re   _r   s        r   ri   zPipeline._transform=  s>    #zz|| 	) 	)OAq)$$R((BB	r   c                 2    | j         d         d         j        S )Nr'   )r"   classes_r>   s    r   rm   zPipeline.classes_C  s    z"~b!**r   c                 F    t          | j        d         d         dd          S )Nr   r3   	_pairwiseF)getattrr"   r>   s    r   ro   zPipeline._pairwiseG  s!     tz!}Q'e<<<r   c                 2    | j         d         d         j        S )Nr   r3   )r"   n_features_in_r>   s    r   rr   zPipeline.n_features_in_L  s     z!}Q..r   )F)TTr   )r   r   r   r%   r$   r<   intr?   rI   propertyrK   rF   rO   rR   rc   r   r   r   ri   rm   ro   rr   r   r   r   r    r    Y   s          
  @' ' ' '"      ( 1 1 X1     X  A A XAW W W!6 !6 !6 !6F   >"D "D "D "DH   X,   + + X+ = = X= / / X/ / /r   r    c                    d | D             }t          t                    }t          | |          D ]\  }}||xx         dz  cc<   t          |                                          D ]\  }}|dk    r||= t          t          t          |                               D ]7}||         }||v r)||xx         d||         z  z  cc<   ||xx         dz  cc<   8t          t          ||                     S )zGenerate names for estimators.c                     g | ]?}t          |t                    r|n%t          |          j                                        @S r   )rA   strr,   r   lower)rU   r0   s     r   
<listcomp>z$_name_estimators.<locals>.<listcomp>U  sP         	3//U		T)__5M5S5S5U5U  r   r3   z-%d)r   rs   r)   rX   rY   reversedranger4   )r.   r-   	namecountrH   r:   kvis           r   _name_estimatorsr   R  s!    #  E C  IU++  	T$1Y__&&''  166!eC
OO,,-- ! !Qx9!HHH	$//HHHdOOOq OOOE:&&'''r   r   c                      |                     dd          }|rGt          d                    t          |                                          d                             t          t          |           |          S )a  Construct a Pipeline from the given estimators.

    This is a shorthand for the Pipeline constructor; it does not require, and
    does not permit, naming the estimators. Instead, their names will be set
    to the lowercase of their types automatically.

    Parameters
    ----------
    *steps : list of estimators.

    verbose : bool, default=False
        If True, the time elapsed while fitting each step will be printed as it
        is completed.

    Returns
    -------
    p : Pipeline
    r#   FzUnknown keyword arguments: "{}"r   )r#   )popr+   rZ   rX   keysr    r   )r"   kwargsr#   s      r   make_pipeliner   j  su    & jjE**G 
-44T&++--5H5H5KLL
 
 	
 $U++W====r   c                 >    |                      |          }||S ||z  S r   )r   ra   r   r   weightr   ress         r   _transform_oner     s)    



"
"C~
<r   c                     t          | d          r | j        ||fi |}n" | j        ||fi |                    |          }||| fS ||z  | fS )z
    Fits ``transformer`` to ``X`` and ``y``. The transformed result is returned
    with the fitted transformer. If ``weight`` is not ``None``, the result will
    be multiplied by ``weight``.
    r   )r*   r   r   r   r   s         r   r\   r\     s|     {O,, ?'k'1;;
;;koa11j11;;A>>~K<$$r   N)r   collectionsr   	itertoolsr   typingr   r   r   typing_extensionsr   r
   r   r    r   r   r   r\   r   r   r   <module>r      s?  $ $J $ # # # # #       * * * * * * * * * * & & & & & &$ $ $ $ $( $ $ $= = = = =* = = =Jv/ v/ v/ v/ v/ v/ v/ v/r( ( (0>x > > > >6  % % % % %r   