
    Pi                        d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z ddlmZmZmZ ddlmZ ddlmZmZmZ dd	lmZ d
gZeeef         Z G d d
e          ZdS )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.

```python
>>> from rdflib import ConjunctiveGraph, URIRef, Namespace
>>> g = ConjunctiveGraph()
>>> data = open("test/data/nquads.rdflib/example.nquads", "rb")
>>> g.parse(data, format="nquads") # doctest:+ELLIPSIS
<Graph identifier=... (<class 'rdflib.graph.ConjunctiveGraph'>)>
>>> 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"))

```
    )annotations)	getreader)AnyMutableMappingOptional)ParserError)ConjunctiveGraphDatasetGraph)InputSource)W3CNTriplesParserr_tailr_wspace)BNodeNQuadsParserc                  &    e Zd Z	 	 dddZdddZdS )r   NFinputsourcer   sinkr   bnode_contextOptional[_BNodeContextType]	skolemizeboolkwargsr   c                &   |j         j        s
J d            t          |j         d          }|j        }d}t	          |t          t
          f          r|j        }n4|j        -|j        |j        k    r|}n|                    |j                  }|||_        |                    |           || _	        || _
        |                                }	|	s,|                                }	 t          d          |	          }	t          |	d          st          d          |	| _        d| _        	 |                                 x| _        }
| j        n?	 |                     |           n'# t          $ r}t          d	|d
|
          d}~ww xY wb| j	        S )a  Parse inputsource as an N-Quads file.

        Args:
            inputsource: The source of N-Quads-formatted data.
            sink: The graph where parsed quads will be stored.
            bnode_context: Optional dictionary mapping blank node identifiers to
                [`BNode`][rdflib.term.BNode] instances.
                See `.W3CNTriplesParser.parse` for more details.
            skolemize: Whether to skolemize blank nodes.

        Returns:
            The Dataset containing the parsed quads.

        Raises:
            AssertionError: If the sink store is not context-aware.
            ParseError: If the input is not a file-like object or contains invalid lines.
        z1NQuadsParser must be given a context-aware store.T)storedefault_unionNzutf-8readz)Item to parse must be a file-like object. zInvalid line (z):
)r   context_awarer
   default_context
isinstancer	   
identifierget_contextremove_graphr   r   getCharacterStreamgetByteStreamr   hasattr
ParseErrorfilebufferreadlineline	parseline)selfr   r   r   r   r   ds
ds_defaultnew_default_contextsource_NQuadsParser__linemsgs               q/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/rdflib/plugins/parsers/nquads.pyparsezNQuadsParser.parse2   s   4 J$	? 	?>	? 	?$ 4:T:::'
"dW&6788 	F"&"6_(*"777&*##&(nnT_&E&E#*!4BOOJ'''	"//11 	0 ..00F'Yw''//Fvv&& 	JHIII		K!%0DIy K}---- K K K jSSS&&!IJJJK	K ys   E$ $
F.FFreturnNonec                   |                      t                     | j        r| j                            d          rd S |                     |          }|                      t                     |                                 }|                      t                     |                     |          }|                      t                     |                                 p|                     |          }|                      t                     | j        rt          d          |r2| j                            |                              |||f           d S | j        j                            |||f           d S )N#zTrailing garbage)eatr   r,   
startswithsubject	predicateobjecturirefnodeidr   r(   r   r#   addr    )r.   r   r=   r>   objcontexts         r5   r-   zNQuadsParser.parselinev   sL   	 	di22377 	F,,}--NN$$	kk-((++--=4;;}#=#=9 	1/000  	EI!!'**..C/HIIIIII%))7Is*CDDDDD    )NF)
r   r   r   r   r   r   r   r   r   r   )N)r   r   r7   r8   )__name__
__module____qualname__r6   r-    rE   r5   r   r   /   s[         6:B B B B BHE E E E E E ErE   N)__doc__
__future__r   codecsr   typingr   r   r   rdflib.exceptionsr   r(   rdflib.graphr	   r
   r   rdflib.parserr   rdflib.plugins.parsers.ntriplesr   r   r   rdflib.termr   __all__str_BNodeContextTyper   rI   rE   r5   <module>rV      s(   8 # " " " " "       0 0 0 0 0 0 0 0 0 0 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9 % % % % % % P O O O O O O O O O      
"3:. _E _E _E _E _E$ _E _E _E _E _ErE   