
    4Ysh)                     l    d 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lm	Z	 dgZ
 G d	 de      Zy
)a  
This is a rdflib plugin for parsing NQuad files into Conjunctive
graphs that can be used and queried. The store that backs the graph
*must* be able to handle contexts.

>>> from rdflib import ConjunctiveGraph, URIRef, Namespace
>>> g = ConjunctiveGraph()
>>> data = open("test/nquads.rdflib/example.nquads", "rb")
>>> g.parse(data, format="nquads") # doctest:+ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.Graph'>)>
>>> assert len(g.store) == 449
>>> # There should be 16 separate contexts
>>> assert len([x for x in g.store.contexts()]) == 16
>>> # is the name of entity E10009 "Arco Publications"?
>>> #   (in graph http://bibliographica.org/entity/E10009)
>>> # Looking for:
>>> # <http://bibliographica.org/entity/E10009>
>>> #   <http://xmlns.com/foaf/0.1/name>
>>> #   "Arco Publications"
>>> #   <http://bibliographica.org/entity/E10009>
>>> s = URIRef("http://bibliographica.org/entity/E10009")
>>> FOAF = Namespace("http://xmlns.com/foaf/0.1/")
>>> assert(g.value(s, FOAF.name).eq("Arco Publications"))
    )	getreader)ConjunctiveGraph)W3CNTriplesParser)
ParseError)r_tail)r_wspaceNQuadsParserc                       e Zd ZddZddZy)r	   Nc                    |j                   j                  sJ d       t        |j                   |j                        | _        |j                         }|s!|j                         } t        d      |      }t        |d      st        d      || _
        d| _        	 | j                         x| _        }| j                  	 | j                  S 	 | j                  |       C# t        $ r}t        d|d	|      d}~ww xY w)
a  
        Parse inputsource as an N-Quads file.

        :type inputsource: `rdflib.parser.InputSource`
        :param inputsource: the source of N-Quads-formatted data
        :type sink: `rdflib.graph.Graph`
        :param sink: where to send parsed triples
        :type bnode_context: `dict`, optional
        :param bnode_context: a dict mapping blank node identifiers to `~rdflib.term.BNode` instances.
                              See `.NTriplesParser.parse`
        z1NQuadsParser must be given a context aware store.)store
identifierzutf-8readz)Item to parse must be a file-like object. NzInvalid line (z):
)r   context_awarer   r   sinkgetCharacterStreamgetByteStreamr   hasattrr   filebufferreadlineline	parseline)selfinputsourcer   bnode_contextkwargssource_NQuadsParser__linemsgs           }/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/plugins/parsers/nquads.pyparsezNQuadsParser.parse(   s     zz'' 	
B	
' %4::$//R	//1 ..0F'Yw'/Fvv&HII	!%0DIyy  yyK}-   K S&!IJJKs   C   	C?)C::C?c                    | j                  t               | j                  r| j                  j                  d      ry | j	                  |      }| j                  t               | j                         }| j                  t               | j                  |      }| j                  t               | j                         xs) | j                  |      xs | j                  j                  }| j                  t               | j                  rt        d      | j                  j                  |      j                  |||f       y )N#zTrailing garbage)eatr   r   
startswithsubject	predicateobjecturirefnodeidr   r   r   r   get_contextadd)r   r   r'   r(   objcontexts         r!   r   zNQuadsParser.parselineN   s    		dii22C9,,}-NN$	kk-(++-U4;;}#=UAUAU99/00 			g&**GY+DE    )N)__name__
__module____qualname__r"   r    r0   r!   r	   r	   '   s    $LFr0   N)__doc__codecsr   rdflibr   rdflib.plugins.parsers.ntriplesr   r   r   r   __all__r	   r4   r0   r!   <module>r:      s7   2  # > 6 2 4
<F$ <Fr0   