
    Pi>                       U d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
mZmZmZmZmZmZ ddlmZmZ er(ddlmZmZ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"m#Z# dZ$dZ%dZ&dZ'de(d<   ej)        Z)ej*        Z*ej+        Z+g dZ, G d de          Z- G d de          Z. G d de          Z/ G d d          Z0 G d d          Z1dS )a  ## Types of store

`Context-aware`: An RDF store capable of storing statements within contexts
is considered context-aware. Essentially, such a store is able to partition
the RDF model it represents into individual, named, and addressable
sub-graphs.

Relevant Notation3 reference regarding formulae, quoted statements, and such:
http://www.w3.org/DesignIssues/Notation3.html

`Formula-aware`: An RDF store capable of distinguishing between statements
that are asserted and statements that are quoted is considered formula-aware.

`Transaction-capable`: capable of providing transactional integrity to the
RDF operations performed on it.

`Graph-aware`: capable of keeping track of empty graphs.
    )annotationsN)BytesIO)
TYPE_CHECKINGAnyDict	GeneratorIterableIteratorMappingOptionalTupleUnion)
DispatcherEvent)Graph_ContextType	_QuadType_TripleChoiceType_TriplePatternType_TripleType)QueryUpdate)Result)
IdentifierNodeURIRef   NoneUNKNOWN)StoreCreatedEventTripleAddedEventTripleRemovedEventNodePicklerStorec                      e Zd ZdZdS )r!   z{This event is fired when the Store is created.

    Attributes:
        configuration: String used to create the store
    N__name__
__module____qualname____doc__     `/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/rdflib/store.pyr!   r!   I   s           r-   r!   c                      e Zd ZdZdS )r"   zThis event is fired when a triple is added.

    Attributes:
        triple: The triple added to the graph.
        context: The context of the triple, if any.
        graph: The graph to which the triple was added.
    Nr'   r,   r-   r.   r"   r"   Q              r-   r"   c                      e Zd ZdZdS )r#   zThis event is fired when a triple is removed.

    Attributes:
        triple: The triple removed from the graph.
        context: The context of the triple, if any.
        graph: The graph from which the triple was removed.
    Nr'   r,   r-   r.   r#   r#   [   r0   r-   r#   c                  J    e Zd ZddZddZddZddZ	 dddZd dZd!dZ	dS )"r$   returnr   c                D    i | _         i | _        | j         j        | _        d S N)_objects_ids__getitem___get_objectselfs    r.   __init__zNodePickler.__init__f   s#    (*$&	=4r-   keyr   Optional[str]c                Z    	 | j                             |          S # t          $ r Y d S w xY wr5   )r7   get	TypeError)r;   r=   s     r.   _get_idszNodePickler._get_idsk   s=    	9==%%% 	 	 	44	s    
**objectidstrc                .    || j         |<   || j        |<   d S r5   )r6   r7   )r;   rC   rD   s      r.   registerzNodePickler.registerq   s     "b	&r-   sbytesr   c                    t          t          |                    }| j        |_        	 |                                S # t
          $ r}t          d|z            d }~ww xY w)Nz Could not find Node class for %s)	Unpicklerr   r9   persistent_loadloadKeyErrorUnpicklingError)r;   rH   upes       r.   loadszNodePickler.loadsu   sm    wqzz"" "-	J7799 	J 	J 	J!"Dq"HIII	Js   > 
AAANobjprotocolOptional[Any]binc                    t                      }t          |          }| j        |_        |                    |           |                                S r5   )r   PicklerrB   persistent_iddumpgetvalue)r;   rS   rT   rV   srcps         r.   dumpszNodePickler.dumps   s@     iiCLL -	s||~~r-   Mapping[str, Any]c                    | j                                         }|d= |                    t          | j                                                  t          | j                                                  d           |S )Nr9   )r7   r6   )__dict__copyupdatetupler7   itemsr6   r;   states     r.   __getstate__zNodePickler.__getstate__   so    ""$$- 49??,,--5ATATAVAV;W;WXX	
 	
 	
 r-   rg   c                    | j                             |           t          | j                  | _        t          | j                  | _        | j        j        | _        d S r5   )ra   rc   dictr7   r6   r8   r9   rf   s     r.   __setstate__zNodePickler.__setstate__   sK    U###OO	T]++=4r-   r3   r   )r=   r   r3   r>   )rC   r   rD   rE   r3   r   )rH   rI   r3   r   NN)rS   r   rT   rU   rV   rU   )r3   r_   )rg   r_   r3   r   )
r(   r)   r*   r<   rB   rG   rR   r^   rh   rk   r,   r-   r.   r$   r$   e   s        5 5 5 5
      J J J J OS	 	 	 	 	   5 5 5 5 5 5r-   r$   c                  <   e Zd ZU dZded<   dZded<   dZded<   dZded<   	 	 dQdRdZe	dSd            Z
dTdZ	 dUdVdZdUdWdZdTdZdXdZ	 dUdYd ZdZd#Z	 d[d\d&Z	 d[d]d)Z	 d[d^d,Zd[d_d.Z	 d[d`d1Zdad<Zdbd?ZdcdddEZdedFZdfdHZdgdJZdXdKZdXdLZdhdOZdhdPZ dS )ir%   Fboolcontext_awareformula_awaretransaction_awaregraph_awareNconfigurationr>   
identifierOptional[Identifier]c                l    d| _         t                      | _        |r|                     |           dS dS )zInitialize the Store.

        Args:
            identifier: URIRef of the Store. Defaults to CWD
            configuration: String containing information open can use to
                connect to datastore.
        N)_Store__node_picklerr   
dispatcheropen)r;   rt   ru   s      r.   r<   zStore.__init__   sA     6:$,, 	%IIm$$$$$	% 	%r-   r3   r$   c                   | j         ddlm}m} ddlm}m}m}m} t                      x| _         }|
                    | d           |
                    |d           |
                    |d           |
                    |d           |
                    |d           |
                    |d	           |
                    |d
           | j         S )Nr   )r   QuotedGraph)BNodeLiteralr   VariableSUBLGQV)rx   rdflib.graphr   r|   rdflib.termr}   r~   r   r   r$   rG   )r;   r   r|   r}   r~   r   r   nps           r.   node_picklerzStore.node_pickler   s    &77777777DDDDDDDDDDDD'2}}4D"KKc"""KK$$$KKs###KK%%%KKs###KKS)))KK#&&&""r-   rE   r   c                V    | j                             t          |                     d S )N)rt   )ry   dispatchr!   r;   rt   s     r.   createzStore.create   s*      !2!O!O!OPPPPPr-   Union[str, tuple[str, str]]r   Optional[int]c                    t           S )a  Opens the store specified by the configuration string.

        Args:
            configuration: Store configuration string
            create: If True, a store will be created if it doesn't exist.
                If False and the store doesn't exist, an exception is raised.

        Returns:
            One of: VALID_STORE, CORRUPTED_STORE, or NO_STORE

        Raises:
            Exception: If there are insufficient permissions to open the store.
        )r    )r;   rt   r   s      r.   rz   z
Store.open   s	      r-   commit_pending_transactionc                    dS )zCloses the database connection.

        Args:
            commit_pending_transaction: Whether to commit all pending
                transactions before closing (if the store is transactional).
        Nr,   )r;   r   s     r.   closezStore.close         r-   c                    dS )zDestroys the instance of the store.

        Args:
            configuration: The configuration string identifying the store instance.
        Nr,   r   s     r.   destroyzStore.destroy   r   r-   c                    dS )z:Allows the store to perform any needed garbage collection.Nr,   r:   s    r.   gczStore.gc   s    r-   tripler   contextr   quotedc                X    | j                             t          ||                     dS )a  Adds the given statement to a specific context or to the model.

        Args:
            triple: The triple to add
            context: The context to add the triple to
            quoted: If True, indicates this statement is quoted/hypothetical
                (for formula-aware stores)

        Note:
            It should be an error to not specify a context and have the quoted
            argument be True. It should also be an error for the quoted argument
            to be True when the store is not formula-aware.
        r   r   N)ry   r   r"   )r;   r   r   r   s       r.   addz	Store.add   s.    & 	  !1!Q!Q!QRRRRRr-   quadsIterable[_QuadType]c           	     x    |D ]6\  }}}}|J d|d|d|d            |                      |||f|           7dS )aQ  Adds each item in the list of statements to a specific context.

        The quoted argument is interpreted by formula-aware stores to indicate this
        statement is quoted/hypothetical.

        Note:
            The default implementation is a redirect to add.

        Args:
            quads: An iterable of quads to add
        NzContext associated with  z	 is None!)r   )r;   r   rH   r]   ocs         r.   addNz
Store.addN  sm       	# 	#JAq!Q===#===
 HHaAY""""	# 	#r-   r   Optional[_ContextType]c                X    | j                             t          ||                     dS )z=Remove the set of triples matching the pattern from the storer   N)ry   r   r#   )r;   r   r   s      r.   removezStore.remove  s.     	  !367!S!S!STTTTTr-   r   KGenerator[Tuple[_TripleType, Iterator[Optional[_ContextType]]], None, None]c              #    K   |\  }}}t          |t                    rt          |t                    r
J d            t          |t                    r
J d            |r3|D ].}|                     |||f|          D ]\  \  }}}	}
|||	f|
fV  /dS |                     ||df|          D ]\  \  }}}	}
|||	f|
fV  dS t          |t                    rt          |t                    r
J d            |r3|D ].}|                     |||f|          D ]\  \  }}}	}
|||	f|
fV  /dS |                     d||f|          D ]\  \  }}}	}
|||	f|
fV  dS t          |t                    rt          |t                    r
J d            |r3|D ].}|                     |||f|          D ]\  \  }}}	}
|||	f|
fV  /dS |                     |d|f|          D ]\  \  }}}	}
|||	f|
fV  dS dS )a-  
        A variant of triples that can take a list of terms instead of a single
        term in any slot.  Stores can implement this to optimize the response
        time from the default 'fallback' implementation, which will iterate
        over each term in the list and dispatch to triples
        z object_ / subject are both listsz"object_ / predicate are both listsNz"subject / predicate are both listsz"predicate / subject are both lists)
isinstancelisttriples)r;   r   r   subject	predicateobject_rS   s1p1o1cgsubjpreds                r.   triples_choiceszStore.triples_choices  sC     $ '-#Ggt$$ '	+!'400TT2TTT0!)T22XX4XXX2 
+" / /C,0LL )S17- - / /(Rb  "2rlB.....// / )-i.) ) + +$LRR" r2,*****+ +
 && 	+!)T22XX4XXX2 
+# / /D,0LLy'2G- - / /(Rb  "2rlB.....// / )-9g.) ) + +$LRR" r2,*****+ +
 	4(( 
	+!'400VV2VVV0 +% / /D,0LL $0'- - / /(Rb  "2rlB.....// / )-gtW5Mw(W(W + +$LRR"r2,*****
	+ 
	++ +r-   triple_pattern>Iterator[Tuple[_TripleType, Iterator[Optional[_ContextType]]]]c                    |\  }}}dS )a  
        A generator over all the triples matching the pattern. Pattern can
        include any objects for used for comparing against nodes in the store,
        for example, REGEXTerm, URIRef, Literal, BNode, Variable, Graph,
        QuotedGraph, Date? DateRange?

        Args:
            context: A conjunctive query can be indicated by either
                providing a value of None, or a specific context can be
                queries by passing a Graph instance (if store is context aware).
        Nr,   )r;   r   r   r   r   rC   s         r.   r   zStore.triplesZ  s      &4"FFFr-   intc                    dS )aG  
        Number of statements in the store. This should only account for non-
        quoted (asserted) statements if the context is not specified,
        otherwise it should return the number of statements in the formula or
        context given.

        Args:
            context: a graph instance to query or None
        Nr,   )r;   r   s     r.   __len__zStore.__len__o  r   r-   Optional[_TripleType]#Generator[_ContextType, None, None]c                    dS )z
        Generator over all contexts in the graph. If triple is specified,
        a generator over all contexts the triple is in.

        if store is graph_aware, may also return empty contexts

        :returns: a generator over Nodes
        Nr,   )r;   r   s     r.   contextszStore.contexts{  r   r-   queryUnion[Query, str]initNsr_   initBindingsMapping[str, Identifier]
queryGraphkwargsr   r   c                    t           )a  If stores provide their own SPARQL implementation, override this.

        queryGraph is None, a URIRef or `__UNION__`
        If None the graph is specified in the query-string/object
        If URIRef it specifies the graph to query,
        If  `__UNION__` the union of all named graphs should be queried
        (This is used by ConjunctiveGraphs
        Values other than None obviously only makes sense for
        context-aware stores.)
        NotImplementedError)r;   r   r   r   r   r   s         r.   r   zStore.query  
    & "!r-   rc   Union[Update, str]c                    t           )a  If stores provide their own (SPARQL) Update implementation, override this.

        queryGraph is None, a URIRef or `__UNION__`
        If None the graph is specified in the query-string/object
        If URIRef it specifies the graph to query,
        If  `__UNION__` the union of all named graphs should be queried
        (This is used by ConjunctiveGraphs
        Values other than None obviously only makes sense for
        context-aware stores.)
        r   )r;   rc   r   r   r   r   s         r.   rc   zStore.update  r   r-   Tprefix	namespacer   overridec                    dS )a  Bind a namespace to a prefix.

        Args:
            prefix: The prefix to bind the namespace to.
            namespace: The URIRef of the namespace to bind.
            override: If True, rebind even if the given namespace is already bound
                to another prefix
        Nr,   )r;   r   r   r   s       r.   bindz
Store.bind  r   r-   c                    dS ) Nr,   )r;   r   s     r.   r   zStore.prefix  r   r-   Optional[URIRef]c                    dS r   Nr,   )r;   r   s     r.   r   zStore.namespace  r   r-   Iterator[Tuple[str, URIRef]]c              #  
   K   dS )r   FNr,   r:   s    r.   
namespaceszStore.namespaces  s      
	 	r-   c                    dS r   r,   r:   s    r.   commitzStore.commit  r   r-   c                    dS r   r,   r:   s    r.   rollbackzStore.rollback  r   r-   graphr   c                     t          d          )zAdd a graph to the store, no effect if the graph already
        exists.

        Args:
            graph: a Graph instance
        ,Graph method called on non-graph_aware store	Exceptionr;   r   s     r.   	add_graphzStore.add_graph       FGGGr-   c                     t          d          )zRemove a graph from the store, this should also remove all
        triples in the graph

        Args:
            graphid: a Graph instance
        r   r   r   s     r.   remove_graphzStore.remove_graph  r   r-   rm   )rt   r>   ru   rv   )r3   r$   )rt   rE   r3   r   )F)rt   r   r   ro   r3   r   )r   ro   r3   r   rl   )r   r   r   r   r   ro   r3   r   )r   r   r3   r   r5   )r   r   r   r   r3   r   )r   r   r   r   r3   r   )r   r   r   r   r3   r   )r   r   r3   r   )r   r   r3   r   )r   r   r   r_   r   r   r   rE   r   r   r3   r   )rc   r   r   r_   r   r   r   rE   r   r   r3   r   )T)r   rE   r   r   r   ro   r3   r   )r   r   r3   r>   )r   rE   r3   r   )r3   r   )r   r   r3   r   )!r(   r)   r*   rp   __annotations__rq   rr   rs   r<   propertyr   r   rz   r   r   r   r   r   r   r   r   r   r   r   rc   r   r   r   r   r   r   r   r   r,   r-   r.   r%   r%      s        MM#####K (,+/% % % % %" # # # X#"Q Q Q Q JO    $           	S S S S S*# # # #. +/U U U U U +/:+ :+ :+ :+ :+@ +/4 4 4 4 4*	 	 	 	 	 /3
 
 
 
 
" " " "*" " " ".                   
H H H HH H H H H Hr-   r%   )2r+   
__future__r   pickleior   typingr   r   r   r   r	   r
   r   r   r   r   rdflib.eventsr   r   r   r   r   r   r   r   r   rdflib.plugins.sparql.sparqlr   r   rdflib.queryr   r   r   r   r   VALID_STORECORRUPTED_STORENO_STOREr    r   rX   rK   rO   __all__r!   r"   r#   r$   r%   r,   r-   r.   <module>r      s    & # " " " " "                               , + + + + + + + 5                ;:::::::######4444444444      .	(             u          15 15 15 15 15 15 15 15hMH MH MH MH MH MH MH MH MH MHr-   