o
    ÒmÆiw  ã                   @   s^   d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	m
Z
 dgZedƒZG dd„ de
ƒZdS )	z2
Notation 3 (N3) RDF graph serializer for RDFLib.
é    N)ÚGraph)ÚOWLÚ	Namespace)ÚOBJECTÚSUBJECTÚTurtleSerializerÚN3Serializerz#http://www.w3.org/2000/10/swap/log#c                       s    e Zd ZdZdZddef‡ fdd„Z‡ fdd„Z‡ fd	d
„Zd‡ fdd„	Z	‡ fdd„Z
d ‡ fdd„	Zd dd„Z‡ fdd„Zd!‡ fdd„	Zdd„ Zdd„ Z‡  ZS )"r   z%Notation 3 (N3) RDF graph serializer.Zn3NÚstorec                    s2   t t| ƒ |¡ | j tjdtjdi¡ || _	d S )Nú=z=>)
Úsuperr   Ú__init__ÚkeywordsÚupdater   ZsameAsÚSWAP_LOGZimpliesÚparent)Úselfr	   r   ©Ú	__class__© úW/home/kim/smarthome/.venv/lib/python3.10/site-packages/rdflib/plugins/serializers/n3.pyr      s   
zN3Serializer.__init__c                    s   t t| ƒ ¡  i | _d S ©N)r   r   ÚresetZ_stores©r   r   r   r   r      s   
zN3Serializer.resetc                    s   | j stt| ƒ ¡  d S d S r   )r   r   r   ÚendDocumentr   r   r   r   r      s   ÿzN3Serializer.endDocumentr   c                    s,   t t| ƒ |¡}| jd ur|| j ¡ 7 }|S r   )r   r   Úindentr   )r   Úmodifierr   r   r   r   r   "   s   
zN3Serializer.indentc                    sŠ   t t| ƒ |¡ t|d tƒr|d D ]}|  |¡ qt|d tƒr.|d D ]}|  |¡ q&t|d tƒrA|d D ]	}|  |¡ q9d S d S )Nr   é   é   )r   r   ÚpreprocessTripleÚ
isinstancer   )r   ZtripleÚtr   r   r   r   (   s   þzN3Serializer.preprocessTripleTc                    s:   d }| j d ur| j  ||¡}|d u rtt| ƒ ||¡}|S r   )r   Ú	get_pnamer   r   )r   ÚuriÚ
gen_prefixZqnamer   r   r   r!   4   s   
zN3Serializer.get_pnamec                 C   s   t jdtdd |  ||¡S )NzHN3Serializer.getQName is deprecated, use N3Serializer.get_pname instead.r   )Ú
stacklevel)ÚwarningsÚwarnÚDeprecationWarningr!   )r   r"   r#   r   r   r   ÚgetQName<   s   ýzN3Serializer.getQNamec                    s>   |   |¡ |  |¡}t|ƒdkrdS |  |¡ptt| ƒ |¡S )Nr   F)ÚsubjectDoneZbuildPredicateHashÚlenÚs_clauser   r   Ú	statement)r   ÚsubjectÚ
propertiesr   r   r   r,   D   s
   

zN3Serializer.statementFc                    s(   |   ||¡stt| ƒ |||¡ d S d S r   )Úp_clauser   r   Úpath)r   ÚnodeÚpositionÚnewliner   r   r   r0   K   s   ÿzN3Serializer.pathc                 C   sD   t |tƒr |  d|  ¡  ¡ |  |t¡ |  |¡ |  d¡ dS dS )NÚ
z .TF)r   r   Úwriter   r/   r   ZpredicateList)r   r-   r   r   r   r+   O   s   


zN3Serializer.s_clausec                 C   s~   t |tƒr=|  |¡ |tu r|  d¡ |  d¡ |  jd7  _t|| d}| | j¡ |  jd8  _|  |  	¡ d ¡ dS dS )Nú Ú{r   )r   Ú}TF)
r   r   r)   r   r5   Údepthr   Ú	serializeÚstreamr   )r   r1   r2   Ú
serializerr   r   r   r/   Y   s   



zN3Serializer.p_clauser   )r   )T)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z
short_namer   r   r   r   r   r   r!   r(   r,   r0   r+   r/   Ú__classcell__r   r   r   r   r      s    

)r@   r%   Zrdflib.graphr   Zrdflib.namespacer   r   Z!rdflib.plugins.serializers.turtler   r   r   Ú__all__r   r   r   r   r   r   Ú<module>   s    