
    4Ysh                     t    d Z ddlmZ ddlmZmZmZmZ ddlm	Z	m
Z
 ddlmZ ddlmZmZ dgZ G d de      Zy	)
zb
Trig RDF graph serializer for RDFLib.
See <http://www.w3.org/TR/trig/> for syntax specification.
    )defaultdict)IOTYPE_CHECKINGOptionalUnion)ConjunctiveGraphGraph)TurtleSerializer)BNodeNodeTrigSerializerc            
       ~     e Zd ZdZdZdeeef   f fdZd Z	 fdZ
	 	 	 ddee   dee   d	ee   d
ee   fdZ xZS )r   trigz    storec                 l   |  |j                   rt        rt        |t              sJ t	        |j                               | _        |j                  j                  | _        |j                  r5| j
                  j                  |j                         n|g| _        d | _        t        t        | /  |       y N)context_awarer   
isinstancer   listcontextsdefault_context
identifierappendsuperr   __init__)selfr   	__class__s     /var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/serializers/trig.pyr   zTrigSerializer.__init__   s    !%)9::: !12DM#(#8#8#C#CD $$$$U%:%:;"GDM#'D nd,U3    c                 8   | j                   D ]  }|| _        | j                  |j                         t	        t
              | _        i | _        |D ]  }| j                  |        | j                         | j                  | j                  f| j                  |<    y r   )r   r   getQNamer   r   int_references	_subjectspreprocessTripleorderSubjects	_contexts)r   contexttriples      r   
preprocesszTrigSerializer.preprocess%   s    }} 	G DJMM',,-*3/DDN! .%%f-. ""$  'DNN7#	r   c                 8    t         t        |           i | _        y r   )r   r   resetr'   )r   r   s    r   r,   zTrigSerializer.reset5   s    nd)+r   streambaseencodingspaciousc                    | j                          || _        ||| _        n1| j                  j                  | j                  j                  | _        ||| _        | j                          | j                          d}| j                  j                         D ]  \  }\  }}	}
|s|
| _	        i | _
        || _        |	| _        | j                  r<|j                  | j                  k(  r#| j                  | j                         dz          nt!        |j                  t"              r|j                  j%                         }n7| j'                  |j                        }||j                  j%                         }| j                  | j                         d|z  z          | xj(                  dz  c_        |D ]>  }| j+                  |      r|rd}| j-                  |      s+|r.| j                  d       @ | xj(                  dz  c_        | j                  d        | j/                          |j                  dj1                  d             y )	NTz
{z
%s {   F
z}
zlatin-1)r,   r-   r.   r   	_spaciousr*   startDocumentr'   itemsr#   _serializedr$   r   r   writeindentr   r   n3r!   depthisDone	statementendDocumentencode)r   r-   r.   r/   r0   args	firstTimer   ordered_subjectssubjectsrefirisubjects                r   	serializezTrigSerializer.serialize9   s    	

DIZZ__(

DI%DN	8<8L8L8N 	4E4$h#"D!DDJ%DN##(8(8D<P<P(P

4;;=501e..6**--/C--(8(89C{#..113

4;;=8c>9:JJ!OJ+ %;;w' %I>>'*9JJt$% JJ!OJJJu;	> 	T[[+,r   )NNN)__name__
__module____qualname__
short_nameindentStringr   r	   r   r   r*   r,   r   bytesr   strboolrG   __classcell__)r   s   @r   r   r      st    JL4eE+;$;< 4  #"&#'8-5	8- sm8- 3-	8-
 4.8-r   N)__doc__collectionsr   typingr   r   r   r   rdflib.graphr   r	   !rdflib.plugins.serializers.turtler
   rdflib.termr   r   __all__r    r   r   <module>rY      s7   
 $ 5 5 0 > # 
`-% `-r   