
    Pi                        d dl mZ d dlZd dlmZmZ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 d	d
dZ G d de          ZdS )    )annotationsN)IOAnyOptional)uuid4)Dataset)_nq_row)_nt_row)
SerializerAD)addremovec                  >     e Zd ZdZd fdZ	 	 dddZd Zd Z xZS )PatchSerializerz
    Creates an RDF patch file to add and remove triples/quads.
    Can either:
    - Create an add or delete patch for a single Dataset.
    - Create a patch to represent the difference between two Datasets.
    storer   c                X    || _         t                                          |           d S N)r   super__init__)selfr   	__class__s     t/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/rdflib/plugins/serializers/patch.pyr   zPatchSerializer.__init__   s*     $
    Nstream	IO[bytes]baseOptional[str]encodingkwargsr   returnNonec                    |                     d          }|                     d          }|                     d          |                     d          sdt                        j        |t          j        d           F                                 j                                        k    rt          j        d            fd	}d fd	}|r|t          v sJ d|             n|sd} |             |r>t                               |          }	 | j                                        |	           nZ|rX 	                    |          \  }
} ||
                                dd            ||                                dd           
                    d                    d                     dS )an  Serialize the store to the given stream.

        Args:
            stream: The stream to serialize to.
            base: The base URI to use for the serialization.
            encoding: The encoding to use for the serialization.
            kwargs: Additional keyword arguments.

        Supported keyword arguments:

        - operation: The operation to perform. Either 'add' or 'remove'.
        - target: The target Dataset to compare against.
        NB: Only one of 'operation' or 'target' should be provided.
        - header_id: The header ID to use.
        - header_prev: The previous header ID to use.
        	operationtarget	header_idheader_prevzuuid:Nz&PatchSerializer does not support base.zBPatchSerializer does not use custom encoding. Given encoding was: c                                         d d                     d                     r-                     d d                     d                                          d                     d                     d S )NzH id <z> .
replacezH prev <z>
zTX .
)writeencode)r   r&   r'   r   s   r   write_headerz/PatchSerializer.serialize.<locals>.write_headerD   s    LL2)22299(INNOOO V8888??)TTUUULL9==>>>>>r   Fc           	         | D ]k}|sj                             |j                  }|D ]E}                                        ||j        |                              d                     Fld S )Nr)   )r   get_context
identifierr*   
_patch_rowr+   )contextsop_codeuse_passed_contextscontexttripler   r   r   s        r   write_triplesz0PatchSerializer.serialize.<locals>.write_triplesJ   s    #  * I"j44W5GHHG%  FLL0BGLLSS$i     r   zInvalid operation: r   r   T)r3   r   zTC .
r)   )F)getr   r   warningswarnloweradd_remove_methodsr   r1   _diffr*   r+   )r   r   r   r   r    r$   r%   r,   r6   operation_codeto_add	to_remover&   r'   s   `` `        @@r   	serializezPatchSerializer.serialize   s4   . JJ{++	H%%JJ{++	jj// 	*)))I=MBCCCHNN$4$48K8K8M8M$M$MM2'/2 2  
	? 	? 	? 	? 	? 	? 	? 	?		 		 		 		 		 		 		 		  	 22224U)4U4U2222 	 I 	O/33I>>NM$*--//@@@@ 	O $

6 2 2FIM&//++SdKKKKM),,..NNNNX__Xy99:::::r   c                2    || j         z
  }| j         |z
  }||fS r   )r   )r   r%   rows_to_addrows_to_removes       r   r<   zPatchSerializer._difff   s%    tz)f,N**r   c                ~    || j         j        j        k    r| dt          |           S | dt	          ||           S )N )r   default_contextr/   r
   r	   )r   r5   
context_idr$   s       r   r0   zPatchSerializer._patch_rowk   sM    3>>>33'&//333??'&*"="=???r   )r   r   )NN)
r   r   r   r   r   r   r    r   r!   r"   )	__name__
__module____qualname____doc__r   r@   r<   r0   __classcell__)r   s   @r   r   r      s                     #"&	F; F; F; F; F;P+ + +
@ @ @ @ @ @ @r   r   )
__future__r   r8   typingr   r   r   uuidr   rdflibr   !rdflib.plugins.serializers.nquadsr	   rdflib.plugins.serializers.ntr
   rdflib.serializerr   r;   r    r   r   <module>rU      s    " " " " " "  $ $ $ $ $ $ $ $ $ $             5 5 5 5 5 5 1 1 1 1 1 1 ( ( ( ( ( ( C00 `@ `@ `@ `@ `@j `@ `@ `@ `@ `@r   