
    ?h                     P    d 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y	)
z"
Classification class definition.
    )ConnectionError)
Connection)get_valid_uuid_decode_json_response_dict   )ConfigBuilderc                   |    e Zd ZdZdefdZdefdZdede	fdZ
dedefdZdedefd	Zdedefd
ZdededefdZy)Classificationz|
    Classification class used to schedule and/or check the status of
    a classification process of Weaviate objects.
    
connectionc                     || _         y)z
        Initialize a Classification class instance.

        Parameters
        ----------
        connection : weaviate.connect.Connection
            Connection object to an active and running Weaviate instance.
        N)_connection)selfr   s     d/home/chris/cleankitchens-env/lib/python3.12/site-packages/weaviate/classification/classification.py__init__zClassification.__init__   s     &    returnc                 .    t        | j                  |       S )a  
        Schedule a Classification of the Objects within Weaviate.

        Returns
        -------
        weaviate.classification.config_builder.ConfigBuilder
            A ConfigBuilder that should be configured to the desired
            classification task
        )r   r   )r   s    r   schedulezClassification.schedule   s     T--t44r   classification_uuidc                     t        |      }	 | j                  j                  d|z         }t	        |d      }|J |S # t        $ r}t        d      |d}~ww xY w)a-  
        Polls the current state of the given classification.

        Parameters
        ----------
        classification_uuid : str
            Identifier of the classification.

        Returns
        -------
        dict
            A dict containing the Weaviate answer.

        Raises
        ------
        ValueError
            If not a proper uuid.
        requests.ConnectionError
            If the network connection to weaviate fails.
        weaviate.UnexpectedStatusCodeException
            If weaviate reports a none OK status.
        z/classifications/)pathz-Classification status could not be retrieved.NzGet classification status)r   r   getRequestsConnectionErrorr   )r   r   responseconn_errress        r   r   zClassification.get*   s|    0 --@A	''++(+>> , H )3NO
 ' 	)?	s   > 	AAAc                 &    | j                  |d      S )a4  
        Checks if a started classification job has completed.

        Parameters
        ----------
        classification_uuid : str
            Identifier of the classification.

        Returns
        -------
        bool
            True if given classification has finished, False otherwise.
        	completed_check_statusr   r   s     r   is_completezClassification.is_completeQ   s     !!"5{CCr   c                 &    | j                  |d      S )a)  
        Checks if a started classification job has failed.

        Parameters
        ----------
        classification_uuid : str
            Identifier of the classification.

        Returns
        -------
        bool
            True if the classification failed, False otherwise.
        failedr   r!   s     r   	is_failedzClassification.is_failedb   s     !!"5x@@r   c                 &    | j                  |d      S )a-  
        Checks if a started classification job is running.

        Parameters
        ----------
        classification_uuid : str
            Identifier of the classification.

        Returns
        -------
        bool
            True if the classification is running, False otherwise.
        runningr   r!   s     r   
is_runningzClassification.is_runnings   s     !!"5yAAr   statusc                 X    	 | j                  |      }|d   |k(  ryy# t        $ r Y yw xY w)aP  
        Check for a status of a classification.

        Parameters
        ----------
        classification_uuid : str
            Identifier of the classification.
        status : str
            Status to check for.

        Returns
        -------
        bool
            True if 'status' is satisfied, False otherwise.
        Fr)   T)r   r   )r   r   r)   r   s       r   r    zClassification._check_status   s?    "	xx 34H H'	 ' 		s    	))N)__name__
__module____qualname____doc__r   r   r   r   strdictr   boolr"   r%   r(   r     r   r   r
   r
      s    

&: 
&5- 5%s %t %NDs Dt D"AS AT A"Bc Bd B" c d r   r
   N)r.   requests.exceptionsr   r   weaviate.connectr   weaviate.utilr   r   config_builderr   r
   r2   r   r   <module>r7      s%    K ' D )P Pr   