
    4Ysh`                         d Z ddlmZmZmZ ddlmZmZ ddlm	Z	m
Z
mZmZ ddlmZ ddlmZmZ ddlZdgZ G d	 de      Zy)
z~
HextuplesSerializer RDF graph serializer for RDFLib.
See <https://github.com/ontola/hextuples> for details about the format.
    )IOOptionalUnion)GraphConjunctiveGraph)LiteralURIRefNodeBNode)
Serializer)RDFXSDNHextuplesSerializerc                   d    e Zd ZdZdeeef   fdZ	 	 ddee	   de
e   de
e   fdZd	 Zd
 Zd Zy)r   z3
    Serializes RDF graphs to NTriples format.
    storec                 D   |  t        |t              rit        |j                               | _        |j                  r7|j                  | _        | j                  j                  |j                         nd | _        n|g| _        d | _        t        j                  | |       y N)
isinstancer   listcontextsdefault_contextappendr   __init__)selfr   s     /var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/serializers/hext.pyr   zHextuplesSerializer.__init__   s{    e-. !12DM$$','<'<$$$U%:%:;'+$"GDM#'D D%(    Nstreambaseencodingc                 J   |t        j                  d       |dvrt        j                  d| d       | j                  j                  du rt	        d      | j
                  D ]=  }|D ]6  }| j                  ||      }||j                  |j                                8 ? y )NzIbase has no meaning for Hextuples serialization. I will ignore this valueNzutf-8z8Hextuples files are always utf-8 encoded. I was passed: z*, but I'm still going to use utf-8 anyway!Tz>Hextuple serialization can't (yet) handle formula-aware stores)	warningswarnr   formula_aware	Exceptionr   	_hex_linewriteencode)r   r   r   r   kwargscontexttriplehls           r   	serializezHextuplesSerializer.serialize#   s     MM+
 ?*MM!!)
 +;; ::##t+P  }} 	.G! .^^FG4>LL-.	.r   c                    t        |d   t        t        f      r.t        |d   t              r|d   n| j	                  |d         }t        |d   t              rd}n{t        |d   t              rd}net        |d   t              rQ|d   j
                  |d   j
                   }n2|d   j                  t        j                  }nt        j                  }ny t        |d   t              r#|d   j                  |d   j                   }nd}nd}d| j	                  |d         d|d   d|d|d|d| j                  |      d	S y )
Nr      globalIdlocalId z["z", "   z"]
)r   r	   r   r   
_iri_or_bndatatypelanguager   
langStringr   string_context)r   r+   r*   valuer5   r6   s         r   r&   zHextuplesSerializer._hex_lineB   s<   1I
 fQi1 q	__VAY/  &)V,%F1Iu-$F1Iw/!9%%1"()"4"4!5Hay))5#&>>#&:: &)W-!9%%1"()"4"4!5H!H q	*q	g&  r   c                 l    t        |t              r| S t        |t              r|j                          S y r   )r   r	   r   n3)r   i_s     r   r4   zHextuplesSerializer._iri_or_bns   s.    b&!TNE"eegYr   c                     | j                   y|j                  dk(  ry|0| j                   $|j                  | j                   j                  k(  ry|j                  S )Nr2   zurn:x-rdflib:default)r   
identifier)r   r*   s     r   r9   zHextuplesSerializer._context{   s]    '!77 T%9%9%E!!T%9%9%D%DD!!!r   r!   )__name__
__module____qualname____doc__r   r   r   r   r   bytesr   strr-   r&   r4   r9    r   r   r   r      sc    )eE+;$;< )$ #")	.5	. sm. 3-	.>/b"r   )rC   typingr   r   r   rdflib.graphr   r   rdflib.termr   r	   r
   r   rdflib.serializerr   rdflib.namespacer   r   r"   __all__r   rF   r   r   <module>rM      s:    ' & 0 4 4 ( %  
!t"* t"r   