
    i                   T   d Z ddlmZ ddlZddlZddl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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 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*Z+ddl,m-Z- dd	l"m.Z. dd
l$m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZF erddlGZHddl(Z+ddlImJZJmKZK eDZLeDZMeDZNeAZOed   ZPed   ZQeddded   f   ZRed   ZSeddded   f   ZTeed   ed   ed   f   ZUeed   e7ed   f   ZVeed   ed   ed   ed   f   ZWeed   e7ed   ed   f   ZXed   ZYed   ZZeed   eed      ed   f   Z[eed   eed      ed   ed   f   Z\ed   Z]ede7df   Z^ed   Z_eeeeL   eeM   eeN   f   eeeL   eeM   eeN   f   eeeL   eeM   eeN   f   f   Z` edd !      Za ed"d#!      Zb ed$d%!      ZceCsJ e0sJ erdd&ldmeZe  ej                  eg      Zhg d'Zi ed(      Zj G d) d eD      ZkekZl G d* d#ek      Zm eFd+      Zn G d, d%em      Zo G d- d.ek      Zpd/e+j                  j                  ep<    G d0 d1      Zs G d2 d3et      Zu G d4 d5et      Zv G d6 d7em      Zwed=d8       Zxed>d9       Zxd>d:Zx G d; d<      Zyy)?a%  
RDFLib defines the following kinds of Graphs:

* :class:`~rdflib.graph.Graph`
* :class:`~rdflib.graph.QuotedGraph`
* :class:`~rdflib.graph.ConjunctiveGraph`
* :class:`~rdflib.graph.Dataset`

Graph
-----

An RDF graph is a set of RDF triples. Graphs support the python ``in``
operator, as well as iteration and some operations like union,
difference and intersection.

see :class:`~rdflib.graph.Graph`

Conjunctive Graph
-----------------

.. warning::
    ConjunctiveGraph is deprecated, use :class:`~rdflib.graph.Dataset` instead.

A Conjunctive Graph is the most relevant collection of graphs that are
considered to be the boundary for closed world assumptions.  This
boundary is equivalent to that of the store instance (which is itself
uniquely identified and distinct from other instances of
:class:`~rdflib.store.Store` that signify other Conjunctive Graphs).  It is
equivalent to all the named graphs within it and associated with a
``_default_`` graph which is automatically assigned a
:class:`~rdflib.term.BNode` for an identifier - if one isn't given.

see :class:`~rdflib.graph.ConjunctiveGraph`

Quoted graph
------------

The notion of an RDF graph [14] is extended to include the concept of
a formula node. A formula node may occur wherever any other kind of
node can appear. Associated with a formula node is an RDF graph that
is completely disjoint from all other graphs; i.e. has no nodes in
common with any other graph. (It may contain the same labels as other
RDF graphs; because this is, by definition, a separate graph,
considerations of tidiness do not apply between the graph at a formula
node and any other graph.)

This is intended to map the idea of "{ N3-expression }" that is used
by N3 into an RDF graph upon which RDF semantics is defined.

see :class:`~rdflib.graph.QuotedGraph`

Dataset
-------

The RDF 1.1 Dataset, a small extension to the Conjunctive Graph. The
primary term is "graphs in the datasets" and not "contexts with quads"
so there is a separate method to set/retrieve a graph in a dataset and
to operate with dataset graphs. As a consequence of this approach,
dataset graphs cannot be identified with blank nodes, a name is always
required (RDFLib will automatically add a name if one is not provided
at creation time). This implementation includes a convenience method
to directly add a single quad to a dataset graph.

see :class:`~rdflib.graph.Dataset`

Working with graphs
===================

Instantiating Graphs with default store (Memory) and default identifier
(a BNode):

    >>> g = Graph()
    >>> g.store.__class__
    <class 'rdflib.plugins.stores.memory.Memory'>
    >>> g.identifier.__class__
    <class 'rdflib.term.BNode'>

Instantiating Graphs with a Memory store and an identifier -
<https://rdflib.github.io>:

    >>> g = Graph('Memory', URIRef("https://rdflib.github.io"))
    >>> g.identifier
    rdflib.term.URIRef('https://rdflib.github.io')
    >>> str(g)  # doctest: +NORMALIZE_WHITESPACE
    "<https://rdflib.github.io> a rdfg:Graph;rdflib:storage
     [a rdflib:Store;rdfs:label 'Memory']."

Creating a ConjunctiveGraph - The top level container for all named Graphs
in a "database":

    >>> g = ConjunctiveGraph()
    >>> str(g.default_context)
    "[a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'Memory']]."

Adding / removing reified triples to Graph and iterating over it directly or
via triple pattern:

    >>> g = Graph()
    >>> statementId = BNode()
    >>> print(len(g))
    0
    >>> g.add((statementId, RDF.type, RDF.Statement)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g.add((statementId, RDF.subject,
    ...     URIRef("https://rdflib.github.io/store/ConjunctiveGraph"))) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g.add((statementId, RDF.predicate, namespace.RDFS.label)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g.add((statementId, RDF.object, Literal("Conjunctive Graph"))) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> print(len(g))
    4
    >>> for s, p, o in g:
    ...     print(type(s))
    ...
    <class 'rdflib.term.BNode'>
    <class 'rdflib.term.BNode'>
    <class 'rdflib.term.BNode'>
    <class 'rdflib.term.BNode'>

    >>> for s, p, o in g.triples((None, RDF.object, None)):
    ...     print(o)
    ...
    Conjunctive Graph
    >>> g.remove((statementId, RDF.type, RDF.Statement)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> print(len(g))
    3

``None`` terms in calls to :meth:`~rdflib.graph.Graph.triples` can be
thought of as "open variables".

Graph support set-theoretic operators, you can add/subtract graphs, as
well as intersection (with multiplication operator g1*g2) and xor (g1
^ g2).

Note that BNode IDs are kept when doing set-theoretic operations, this
may or may not be what you want. Two named graphs within the same
application probably want share BNode IDs, two graphs with data from
different sources probably not.  If your BNode IDs are all generated
by RDFLib they are UUIDs and unique.

    >>> g1 = Graph()
    >>> g2 = Graph()
    >>> u = URIRef("http://example.com/foo")
    >>> g1.add([u, namespace.RDFS.label, Literal("foo")]) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g1.add([u, namespace.RDFS.label, Literal("bar")]) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g2.add([u, namespace.RDFS.label, Literal("foo")]) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g2.add([u, namespace.RDFS.label, Literal("bing")]) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> len(g1 + g2)  # adds bing as label
    3
    >>> len(g1 - g2)  # removes foo
    1
    >>> len(g1 * g2)  # only foo
    1
    >>> g1 += g2  # now g1 contains everything


Graph Aggregation - ConjunctiveGraphs and ReadOnlyGraphAggregate within
the same store:

    >>> store = plugin.get("Memory", Store)()
    >>> g1 = Graph(store)
    >>> g2 = Graph(store)
    >>> g3 = Graph(store)
    >>> stmt1 = BNode()
    >>> stmt2 = BNode()
    >>> stmt3 = BNode()
    >>> g1.add((stmt1, RDF.type, RDF.Statement)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g1.add((stmt1, RDF.subject,
    ...     URIRef('https://rdflib.github.io/store/ConjunctiveGraph'))) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g1.add((stmt1, RDF.predicate, namespace.RDFS.label)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g1.add((stmt1, RDF.object, Literal('Conjunctive Graph'))) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g2.add((stmt2, RDF.type, RDF.Statement)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g2.add((stmt2, RDF.subject,
    ...     URIRef('https://rdflib.github.io/store/ConjunctiveGraph'))) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g2.add((stmt2, RDF.predicate, RDF.type)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g2.add((stmt2, RDF.object, namespace.RDFS.Class)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g3.add((stmt3, RDF.type, RDF.Statement)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g3.add((stmt3, RDF.subject,
    ...     URIRef('https://rdflib.github.io/store/ConjunctiveGraph'))) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g3.add((stmt3, RDF.predicate, namespace.RDFS.comment)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g3.add((stmt3, RDF.object, Literal(
    ...     'The top-level aggregate graph - The sum ' +
    ...     'of all named graphs within a Store'))) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> len(list(ConjunctiveGraph(store).subjects(RDF.type, RDF.Statement)))
    3
    >>> len(list(ReadOnlyGraphAggregate([g1,g2]).subjects(
    ...     RDF.type, RDF.Statement)))
    2

ConjunctiveGraphs have a :meth:`~rdflib.graph.ConjunctiveGraph.quads` method
which returns quads instead of triples, where the fourth item is the Graph
(or subclass thereof) instance in which the triple was asserted:

    >>> uniqueGraphNames = set(
    ...     [graph.identifier for s, p, o, graph in ConjunctiveGraph(store
    ...     ).quads((None, RDF.predicate, None))])
    >>> len(uniqueGraphNames)
    3
    >>> unionGraph = ReadOnlyGraphAggregate([g1, g2])
    >>> uniqueGraphNames = set(
    ...     [graph.identifier for s, p, o, graph in unionGraph.quads(
    ...     (None, RDF.predicate, None))])
    >>> len(uniqueGraphNames)
    2

Parsing N3 from a string

    >>> g2 = Graph()
    >>> src = '''
    ... @prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    ... @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    ... [ a rdf:Statement ;
    ...   rdf:subject <https://rdflib.github.io/store#ConjunctiveGraph>;
    ...   rdf:predicate rdfs:label;
    ...   rdf:object "Conjunctive Graph" ] .
    ... '''
    >>> g2 = g2.parse(data=src, format="n3")
    >>> print(len(g2))
    4

Using Namespace class:

    >>> RDFLib = Namespace("https://rdflib.github.io/")
    >>> RDFLib.ConjunctiveGraph
    rdflib.term.URIRef('https://rdflib.github.io/ConjunctiveGraph')
    >>> RDFLib["Graph"]
    rdflib.term.URIRef('https://rdflib.github.io/Graph')

    )annotationsN)BytesIO)IOTYPE_CHECKINGAnyBinaryIOCallableDict	GeneratorIterableListMappingNoReturnOptionalSetTextIOTupleTypeTypeVarUnioncastoverload)urlparse)url2pathname
Collection)ParserError)RDF	NamespaceNamespaceManager)InputSourceParsercreate_input_source)Path)Resource)
Serializer)Store)BNodeGenidIdentifiedNode
IdentifierLiteralNodeRDFLibGenidURIRef)QueryUpdate)_SubjectType_PredicateType_ObjectType)r2   r3   r4   _ContextTyper2   r3   r4   r5   )_TripleType_OptionalQuadType_ContextIdentifierType)_TriplePatternType_QuadPatternType)_TriplePathPatternType_QuadPathPatternType)r$   r3   )_TripleSelectorType_QuadSelectorType)r6   _TriplePathType_GraphTGraph)bound_ConjunctiveGraphTConjunctiveGraph	_DatasetTDataset)_NamespaceSetString) rA   rD   QuotedGraphSeqModificationExceptionrF   UnSupportedAggregateOperationReadOnlyGraphAggregateBatchAddGraphrC   r8   rE   r@   r4   _OptionalIdentifiedQuadTyper7   r3   r<   r:   r>   	_QuadTyper2   _TripleOrOptionalQuadType_TripleOrTriplePathType_TripleOrQuadPathPatternType_TripleOrQuadPatternType_TripleOrQuadSelectorTyper;   r?   r9   r=   r6   _TCArgTc                      e Zd ZU dZded<   ded<   ded<   ded<   	 	 	 	 	 d[	 	 	 	 	 	 	 	 	 d\ fd	Zed]d
       Zed^d       Zed_d       Z	e	j                  d`d       Z	dadZdadZdbdZdcdZdbdZdbdZdddedZdddfdZdgdZdhdZdidZe	 	 	 	 djd       Ze	 	 	 	 dkd       Ze	 	 	 	 dld       Z	 	 	 	 dldZd ZdmdZdndZdod Zdmd!Zdmd"Zdpd#Zdpd$Zdqd%Z dpd&Z!dqd'Z"drd(Z#drd)Z$dsd*Z%dsd+Z&dsd,Z'dsd-Z(e%Z)e&Z*	 	 	 	 	 	 dtd.Z+	 	 	 du	 	 	 	 	 	 	 dvd/Z,	 	 	 du	 	 	 	 	 	 	 dwd0Z-	 	 	 du	 	 	 	 	 	 	 dxd1Z.	 dy	 	 	 	 	 dzd2Z/	 	 dy	 	 	 	 	 d{d3Z0	 dy	 	 	 	 	 d|d4Z1	 d}	 	 	 	 	 d~d5Z2e	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd6       Z3e	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd7       Z3e	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd8       Z3e	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 dd9       Z3de4jf                  ddd:f	 	 	 	 	 	 	 	 	 	 	 dd;Z3dd<Z5	 d}	 	 	 	 	 dd=Z6	 d}	 	 	 	 	 	 	 dd>Z7	 d}	 	 	 	 	 	 	 dd?Z8dd@Z9dddAZ:	 	 d	 	 	 	 	 	 	 	 	 ddBZ;ddCZ<dddDZ=e	 	 	 	 	 	 	 	 	 	 	 	 ddE       Z>e	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddF       Z>e	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddG       Z>e	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddH       Z>e	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddI       Z>	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddJZ>	 	 	 d	 	 	 	 	 	 	 ddKZ?	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddLZ@	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddMZA	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddNZBd}ddOZCddPZDdqdQZEdpdRZFddSZGddTZHddUZI	 	 	 	 	 	 ddVZJ	 	 	 	 d	 	 	 	 	 	 	 	 	 ddWZK	 d	 	 	 	 	 ddXZLddY	 	 	 	 	 ddZZM xZNS )rA   a
  An RDF Graph: a Python object containing nodes and relations between them as
    RDF 'triples'.

    This is the central RDFLib object class and Graph objects are almost always present
    it all uses of RDFLib.

    The basic use is to create a Graph and iterate through or query its content, e.g.:

    >>> from rdflib import Graph, URIRef
    >>> g = Graph()

    >>> g.add((
    ...     URIRef("http://example.com/s1"),   # subject
    ...     URIRef("http://example.com/p1"),   # predicate
    ...     URIRef("http://example.com/o1"),   # object
    ... )) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>

    >>> g.add((
    ...     URIRef("http://example.com/s2"),   # subject
    ...     URIRef("http://example.com/p2"),   # predicate
    ...     URIRef("http://example.com/o2"),   # object
    ... )) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>

    >>> for triple in sorted(g):  # simple looping
    ...     print(triple)
    (rdflib.term.URIRef('http://example.com/s1'), rdflib.term.URIRef('http://example.com/p1'), rdflib.term.URIRef('http://example.com/o1'))
    (rdflib.term.URIRef('http://example.com/s2'), rdflib.term.URIRef('http://example.com/p2'), rdflib.term.URIRef('http://example.com/o2'))

    >>> # get the object of the triple with subject s1 and predicate p1
    >>> o = g.value(
    ...     subject=URIRef("http://example.com/s1"),
    ...     predicate=URIRef("http://example.com/p1")
    ... )


    The constructor accepts one argument, the "store" that will be used to store the
    graph data with the default being the `Memory <rdflib.plugins.stores.memory.Memory>`
    (in memory) Store. Other Stores that persist content to disk using various file
    databases or Stores that use remote servers (SPARQL systems) are supported. See
    the :doc:`rdflib.plugins.stores` package for Stores currently shipped with RDFLib.
    Other Stores not shipped with RDFLib can be added, such as
    `HDT <https://github.com/rdflib/rdflib-hdt/>`_.

    Stores can be context-aware or unaware.  Unaware stores take up
    (some) less space but cannot support features that require
    context, such as true merging/demerging of sub-graphs and
    provenance.

    Even if used with a context-aware store, Graph will only expose the quads which
    belong to the default graph. To access the rest of the data the
    `Dataset` class can be used instead.

    The Graph constructor can take an identifier which identifies the Graph
    by name.  If none is given, the graph is assigned a BNode for its
    identifier.

    For more on Named Graphs, see the RDFLib `Dataset` class and the TriG Specification,
    https://www.w3.org/TR/trig/.
    boolcontext_awareformula_awaredefault_unionOptional[str]baseNc                   t         t        |           || _        |  |xs
 t	               | _        t        | j
                  t              st        | j
                        | _        |  t        |t              s' t        j                  |t                     x| _        }n|| _        || _        || _        d| _        d| _        d| _        y NF)superrA   __init__r\   r(   _Graph__identifier
isinstancer*   r/   r'   pluginget_Graph__store_Graph__namespace_manager_bind_namespacesrX   rY   rZ   )selfstore
identifiernamespace_managerr\   bind_namespaces	__class__s         ;C:\Projects\mas-dev\.venv\Lib\site-packages\rdflib/graph.pyr`   zGraph.__init__  s     	eT#%	&1%'$++^< &t'8'8 9D%'#;6::eU#;#==DL5 DL#4  /"""    c                    | j                   S N)re   rh   s    rn   ri   zGraph.store   s    ||ro   c                    | j                   S rq   )ra   rr   s    rn   rj   zGraph.identifier  s       ro   c                h    | j                   t        | | j                        | _         | j                   S )z0
        this graph's namespace-manager
        )rf   r    rg   rr   s    rn   rk   zGraph.namespace_manager  s1    
 ##+'7d>S>S'TD$'''ro   c                    || _         y rq   )rf   )rh   nms     rn   rk   zGraph.namespace_manager  s
    #% ro   c                :    d| j                   dt        |       dS )Nz<Graph identifier=z (z)>)rj   typerr   s    rn   __repr__zGraph.__repr__  s    /3T
KKro   c                    t        | j                  t              r>| j                  j                         d| j                  j
                  j                  dS d| j                  j
                  j                  z  S )Nz9 a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label 'z'].z?[a rdfg:Graph;rdflib:storage [a rdflib:Store;rdfs:label '%s']].)rb   rj   r/   n3ri   rm   __name__rr   s    rn   __str__zGraph.__str__  sc    doov. ##%tzz';';'D'DF F
 W

$$--. .ro   c                    | S rq    rr   s    rn   toPythonzGraph.toPython"      ro   c                <    | j                   j                  |       | S )z>Destroy the store identified by ``configuration`` if supported)re   destroyrh   configurations     rn   r   zGraph.destroy%  s    ]+ro   c                :    | j                   j                          | S )zCommits active transactions)re   commitrr   s    rn   r   zGraph.commit+  s    ro   c                :    | j                   j                          | S )zRollback active transactions)re   rollbackrr   s    rn   r   zGraph.rollback0  s    ro   c                :    | j                   j                  ||      S )zOpen the graph store

        Might be necessary for stores that require opening a connection to a
        database or acquiring some resource.
        )re   open)rh   r   creates      rn   r   z
Graph.open5  s     ||  77ro   c                :    | j                   j                  |      S )zClose the graph store

        Might be necessary for stores that require closing a connection to a
        database or releasing some resource.
        )commit_pending_transaction)re   close)rh   r   s     rn   r   zGraph.close=  s     ||!!=W!XXro   c                    |\  }}}t        |t              sJ d|d       t        |t              sJ d|d       t        |t              sJ d|d       | j                  j                  |||f| d       | S )!Add a triple with self as contextSubject  must be an rdflib term
Predicate Object Fquoted)rb   r-   re   addrh   triplespos        rn   r   z	Graph.addE  sy    1a!T"N1$NN"!T"PQ$PP"!T"M!$MM"!QD7ro   c                P      j                   j                   fd|D                S )%Add a sequence of triple with contextc              3     K   | ]D  \  }}}}t        |t              r-|j                  j                  u rt        |||      r||||f F y wrq   )rb   rA   rj   _assertnode.0r   r   r   crh   s        rn   	<genexpr>zGraph.addN.<locals>.<genexpr>Q  sO      
#
1a!U#/Aq!$	 1aL#   A
A)re   addNrh   quadss   ` rn   r   z
Graph.addNN  s+     	 
#
 	
 ro   c                @    | j                   j                  ||        | S )zRemove a triple from the graph

        If the triple does not provide a context attribute, removes the triple
        from all contexts.
        context)re   removerh   r   s     rn   r   zGraph.removeZ  s      	FD1ro   c                     y rq   r   r   s     rn   tripleszGraph.triplesc       .1ro   c                     y rq   r   r   s     rn   r   zGraph.triplesi       25ro   c                     y rq   r   r   s     rn   r   zGraph.tripleso       :=ro   c              #     K   |\  }}}t        |t              r#|j                  | ||      D ]  \  }}|||f  y| j                  j	                  |||f|       D ]  \  \  }}}}|||f  yw)zGenerator over the triple store

        Returns triples that match the given triple pattern. If triple pattern
        does not provide a context, all contexts will be searched.
        r   N)rb   r$   evalre   r   )	rh   r   r   r   r   _s_o_pcgs	            rn   r   zGraph.triplesu  s      1aa&&q!,B!Ri - %)LL$8$8!QD$8$Q Rb"bj  %Rs   A.A0c                   t        |t              r|j                  |j                  |j                  }}}|||| j                  |||f      S ||| j                  |      S ||| j                  |      S ||| j                  |      S || j                  ||      S || j                  ||      S || j                  ||      S |||f| v S t        |t        t        f      r| j                  |      S t        d      )aN  
        A graph can be "sliced" as a shortcut for the triples method
        The python slice syntax is (ab)used for specifying triples.
        A generator over matches is returned,
        the returned tuples include only the parts not given

        >>> import rdflib
        >>> g = rdflib.Graph()
        >>> g.add((rdflib.URIRef("urn:bob"), namespace.RDFS.label, rdflib.Literal("Bob"))) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>

        >>> list(g[rdflib.URIRef("urn:bob")]) # all triples about bob
        [(rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'), rdflib.term.Literal('Bob'))]

        >>> list(g[:namespace.RDFS.label]) # all label triples
        [(rdflib.term.URIRef('urn:bob'), rdflib.term.Literal('Bob'))]

        >>> list(g[::rdflib.Literal("Bob")]) # all triples with bob as object
        [(rdflib.term.URIRef('urn:bob'), rdflib.term.URIRef('http://www.w3.org/2000/01/rdf-schema#label'))]

        Combined with SPARQL paths, more complex queries can be
        written concisely:

        Name of all Bobs friends:

        g[bob : FOAF.knows/FOAF.name ]

        Some label for Bob:

        g[bob : DC.title|FOAF.name|RDFS.label]

        All friends and friends of friends of Bob

        g[bob : FOAF.knows * "+"]

        etc.

        .. versionadded:: 4.0

        zWYou can only index a graph by a single rdflib term or path, or a slice of rdflib terms.)rb   slicestartstopstepr   subject_predicatessubject_objectspredicate_objectssubjects
predicatesobjectsr$   r-   	TypeError)rh   itemr   r   r   s        rn   __getitem__zGraph.__getitem__  s   T dE"jj$))TYY!qAyQY19||Q1I..qy..q11qy++A..qy--a00}}Q**q!,,||Aq)) 1ayD((tTl+))$// i ro   c                :    | j                   j                  |       S )zReturns the number of triples in the graph

        If context is specified then the number of triples in the context is
        returned instead.
        r   )re   __len__rr   s    rn   r   zGraph.__len__  s     ||##D#11ro   c                $    | j                  d      S )z&Iterates over all triples in the storeNNNr   rr   s    rn   __iter__zGraph.__iter__  s    ||.//ro   c                2    | j                  |      D ]  } y y)z$Support for 'triple in graph' syntaxTFr   r   s     rn   __contains__zGraph.__contains__  s    ll6*F +ro   c                ,    t        | j                        S rq   )hashrj   rr   s    rn   __hash__zGraph.__hash__  s    DOO$$ro   c                    |yt        |t              r3| j                  |j                  kD  | j                  |j                  k  z
  S y)N   rb   rA   rj   rh   others     rn   __cmp__zGraph.__cmp__  sG    =u%OOe&6&66%"2"22  ro   c                X    t        |t              xr | j                  |j                  k(  S rq   r   r   s     rn   __eq__zGraph.__eq__  s#    %'ODOOu?O?O,OOro   c                d    |d u xs+ t        |t              xr | j                  |j                  k  S rq   r   r   s     rn   __lt__zGraph.__lt__  s1     
ue$K5;K;K)K	
ro   c                    | |k  xs | |k(  S rq   r   r   s     rn   __le__zGraph.__le__      e|,tu},ro   c                d    t        |t              xr | j                  |j                  kD  xs |d uS rq   r   r   s     rn   __gt__zGraph.__gt__  s2    5%(OT__u?O?O-O 
	
ro   c                    | |kD  xs | |k(  S rq   r   r   s     rn   __ge__zGraph.__ge__   r   ro   c                <      j                   fd|D                S )zKAdd all triples in Graph other to Graph.
        BNode IDs are not changed.c              3  2   K   | ]  \  }}}|||f  y wrq   r   )r   r   r   r   rh   s       rn   r   z!Graph.__iadd__.<locals>.<genexpr>  s      7gaA1aD/s   )r   r   s   ` rn   __iadd__zGraph.__iadd__  s     			777ro   c                6    |D ]  }| j                  |        | S )zRSubtract all triples in Graph other from Graph.
        BNode IDs are not changed.)r   )rh   r   r   s      rn   __isub__zGraph.__isub__	  s     FKK ro   c                f   	  t        |              }t        t	        | j                               t	        |j                               z         D ]  \  }}|j                  ||        | D ]  }|j                  |        |D ]  }|j                  |        |S # t        $ r t               }Y w xY w)z6Set-theoretic union
        BNode IDs are not changed.)rx   r   rA   setlist
namespacesbindr   )rh   r   retvalprefixurixys          rn   __add__zGraph.__add__  s    	T$Z\F tDOO$56e>N>N>P9QQRKFCKK$ SAJJqM AJJqM   	WF	s   B B0/B0c                    	  t        |              }|D ]  }|| v s|j                  |        |S # t        $ r t               }Y 4w xY w)z>Set-theoretic intersection.
        BNode IDs are not changed.rx   r   rA   r   rh   r   r   r   s       rn   __mul__zGraph.__mul__  sQ    	T$Z\F ADy

1    	WF	   1 AAc                    	  t        |              }| D ]  }||vs|j                  |        |S # t        $ r t               }Y 4w xY w)z<Set-theoretic difference.
        BNode IDs are not changed.r   r   s       rn   __sub__zGraph.__sub__+  sQ    	T$Z\F A~

1    	WF	r   c                    | |z
  || z
  z   S )z5Set-theoretic XOR.
        BNode IDs are not changed.r   r   s     rn   __xor__zGraph.__xor__7  s     u..ro   c                    |\  }}}|J d       |J d       | j                  ||df       | j                  |||f       | S )zConvenience method to update the value of object

        Remove any existing triples for subject and predicate before adding
        (subject, predicate, object).
        Nz>s can't be None in .set([s,p,o]), as it would remove (*, p, *)z>p can't be None in .set([s,p,o]), as it would remove (s, *, *))r   r   )rh   r   subject	predicateobject_s        rn   r   z	Graph.setA  sm     )/%)W	LK	L !	LK	L!Wi./'9g./ro   c              #    K   t        |t              r$|D ]  }| j                  |||      D ]  }|    y|s"| j                  d||f      D ]
  \  }}}|  yt	               }| j                  d||f      D ]!  \  }}}||vs| 	 |j                  |       # y# t        $ r}	t        j                  |	 d        d}	~	ww xY ww)zZA generator of (optionally unique) subjects with the given
        predicate and object(s)N1. Consider not setting parameter 'unique' to True)	rb   r   r   r   r   r   MemoryErrorloggererror)
rh   r  objectuniqueobjr   r   r   subses
             rn   r   zGraph.subjectsT  s      fd#y#v>AG ?  #||T9f,EFGAq!G  G u#||T9f,EFGAq!}" HHQK	  G
  + ""LL#$#%V W "	"0   BCC
BC	C'C  CCc              #  ,  K   |s"| j                  |d|f      D ]
  \  }}}|  yt               }| j                  |d|f      D ]!  \  }}}||vs| 	 |j                  |       # y# t        $ r}t        j                  | d        d}~ww xY ww)zWA generator of (optionally unique) predicates with the given
        subject and objectNr  r   r   r   r  r  r  )	rh   r  r	  r
  r   r   r   predsr  s	            rn   r   zGraph.predicatesr  s      <<$(?@1a A EE<<$(?@1aE>G		!	 A
 '  c!RS 	s0   ABBA*'B*	B3BBBc              #    K   t        |t              r$|D ]  }| j                  |||      D ]  }|    y|s"| j                  ||df      D ]
  \  }}}|  yt	               }| j                  ||df      D ]!  \  }}}||vs| 	 |j                  |       # y# t        $ r}	t        j                  |	 d        d}	~	ww xY ww)zZA generator of (optionally unique) objects with the given
        subject(s) and predicateNr  )	rb   r   r   r   r   r   r  r  r  )
rh   r  r  r
  subjr   r   r   objsr  s
             rn   r   zGraph.objects  s      gt$dIv>AG ?   #||Wi,FGGAq!G  H u#||Wi,FGGAq!}" HHQK	  H
  + ""LL#$#%V W "	"r  c              #  <  K   |s$| j                  dd|f      D ]  \  }}}||f  yt               }| j                  dd|f      D ]'  \  }}}||f|vs||f 	 |j                  ||f       ) y# t        $ r}t        j                  | d        d}~ww xY ww)z[A generator of (optionally unique) (subject, predicate) tuples
        for the given objectNr  r  )rh   r	  r
  r   r   r   
subj_predsr  s           rn   r   zGraph.subject_predicates  s     
 <<tV(<=1ad
 > J<<tV(<=1aq6+Q$J"1v.	 >
 '  c!RS 	0   ABBA2/B2	B;BBBc              #  <  K   |s$| j                  d|df      D ]  \  }}}||f  yt               }| j                  d|df      D ]'  \  }}}||f|vs||f 	 |j                  ||f       ) y# t        $ r}t        j                  | d        d}~ww xY ww)z[A generator of (optionally unique) (subject, object) tuples
        for the given predicateNr  r  )rh   r  r
  r   r   r   	subj_objsr  s           rn   r   zGraph.subject_objects  s      <<y$(?@1ad
 A I<<y$(?@1aq6*Q$J!q!f-	 A
 '  c!RS 	r  c              #  <  K   |s$| j                  |ddf      D ]  \  }}}||f  yt               }| j                  |ddf      D ]'  \  }}}||f|vs||f 	 |j                  ||f       ) y# t        $ r}t        j                  | d        d}~ww xY ww)z[A generator of (optionally unique) (predicate, object) tuples
        for the given subjectNr  r  )rh   r  r
  r   r   r   	pred_objsr  s           rn   r   zGraph.predicate_objects  s     
 <<$(=>1ad
 ? I<<$(=>1aq6*Q$J!q!f-	 ?
 '  c!RS 	r  c              #  ~   K   |\  }}}| j                   j                  |||f|       D ]  \  \  }}}}	|||f  y w)Nr   )ri   triples_choices)
rh   r   r   r  r  r  r   r   r   r   s
             rn   r  zGraph.triples_choices  sW     
 '-#G "ZZ77i)4 8 
MIQ1r Q'M
s   ;=c                     y rq   r   rh   r  r  r	  defaultanys         rn   valuezGraph.value       ro   c                     y rq   r   r  s         rn   r"  zGraph.value  r#  ro   c                     y rq   r   r  s         rn   r"  zGraph.value	  r#  ro   c                     y rq   r   r  s         rn   r"  zGraph.value  s     ro   Tc                   |}||||||y|| j                  ||      }|| j                  ||      }|| j                  ||      }	 t              }|du ru	 t        |       d|d|d|d}| j                  j                  |||fd      }	|	D ]$  \  \  }
}}}|d|
d|d|dt        |      d	z  }& t        j                  |      |S # t        $ r Y |S w xY w# t        $ r |}Y |S w xY w)	a  Get a value for a pair of two criteria

        Exactly one of subject, predicate, object must be None. Useful if one
        knows that there may only be one value.

        It is one of those situations that occur a lot, hence this
        'macro' like utility

        Parameters:

        - subject, predicate, object: exactly one must be None
        - default: value to be returned if no values found
        - any: if True, return any value in the case there is more than one,
          else, raise UniquenessError
        NFz"While trying to find a value for (z, z-) the following multiple values where found:
(z)
 (contexts: z)
)
r   r   r   nextri   r   r   
exceptionsUniquenessErrorStopIteration)rh   r  r  r	  r   r!  r   valuesmsgr   r   r   r   contextss                 rn   r"  zGraph.value  sC   .  _!2FN!fn>\\'95F?]]9f5F__Wf5F	&\F e|L #Iv7 
 #jj00'9f1MtTG/6+	Aq8 N	   07 %44S99  % )  	F* -	s%   C# A4C 	C C #C21C2c              #     K   t        |g      }|rj| j                  |t        j                        }|| | j                  |t        j                        }||v rt        d      |j                  |       |riyyw)zgGenerator over all items in the resource specified by list

        list is an RDF collection.
        Nz,List contains a recursive rdf:rest reference)r   r"  r   firstrest
ValueErrorr   )rh   r   chainr   s       rn   itemszGraph.items^  sl     
 TF::dCII.D
::dCHH-Du} !OPPIIdO s   A7A<:A<c              #     K   |i }n||v ryd||<    |||       D ]"  }| | j                  |||      D ]  }|  $ yw)a  
        Generates transitive closure of a user-defined
        function against the graph

        >>> from rdflib.collection import Collection
        >>> g = Graph()
        >>> a = BNode("foo")
        >>> b = BNode("bar")
        >>> c = BNode("baz")
        >>> g.add((a,RDF.first,RDF.type)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((a,RDF.rest,b)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((b,RDF.first,namespace.RDFS.label)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((b,RDF.rest,c)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((c,RDF.first,namespace.RDFS.comment)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((c,RDF.rest,RDF.nil)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> def topList(node,g):
        ...    for s in g.subjects(RDF.rest, node):
        ...       yield s
        >>> def reverseList(node,g):
        ...    for f in g.objects(node, RDF.first):
        ...       print(f)
        ...    for s in g.subjects(RDF.rest, node):
        ...       yield s

        >>> [rt for rt in g.transitiveClosure(
        ...     topList,RDF.nil)] # doctest: +NORMALIZE_WHITESPACE
        [rdflib.term.BNode('baz'),
         rdflib.term.BNode('bar'),
         rdflib.term.BNode('foo')]

        >>> [rt for rt in g.transitiveClosure(
        ...     reverseList,RDF.nil)] # doctest: +NORMALIZE_WHITESPACE
        http://www.w3.org/2000/01/rdf-schema#comment
        http://www.w3.org/2000/01/rdf-schema#label
        http://www.w3.org/1999/02/22-rdf-syntax-ns#type
        [rdflib.term.BNode('baz'),
         rdflib.term.BNode('bar'),
         rdflib.term.BNode('foo')]

        Nr   )transitiveClosure)rh   funcargseenrtrt_2s         rn   r7  zGraph.transitiveClosuren  sY     h <DD[S	sD/BH..tR>
 ? "   ?Ac              #     K   |i }||v ryd||<   | | j                  ||      D ]  }| j                  |||      D ]  }|    yw)zTransitively generate objects for the ``predicate`` relationship

        Generated objects belong to the depth first transitive closure of the
        ``predicate`` relationship starting at ``subject``.
        Nr   )r   transitive_objects)rh   r  r  rememberr	  r   s         rn   r?  zGraph.transitive_objects  sa      Hhll7I6F,,VYI J 7   AA	c              #     K   |i }||v ryd||<   | | j                  ||      D ]  }| j                  |||      D ]  }|    yw)zTransitively generate subjects for the ``predicate`` relationship

        Generated subjects belong to the depth first transitive closure of the
        ``predicate`` relationship starting at ``object``.
        Nr   )r   transitive_subjects)rh   r  r	  r@  r  r   s         rn   rC  zGraph.transitive_subjects  sa      HX}}Y7G--i(K L 8rA  c                8    | j                   j                  |      S rq   )rk   qnamerh   r   s     rn   rE  zGraph.qname  s    %%++C00ro   c                :    | j                   j                  ||      S rq   )rk   compute_qnamerh   r   generates      rn   rH  zGraph.compute_qname  s    %%33CBBro   c                @    | j                   j                  ||||      S )a6  Bind prefix to namespace

        If override is True will bind namespace to given prefix even
        if namespace was already bound to a different prefix.

        if replace, replace any existing prefix with the new namespace

        for example:  graph.bind("foaf", "http://xmlns.com/foaf/0.1/")

        )overridereplace)rk   r   )rh   r   	namespacerL  rM  s        rn   r   z
Graph.bind  s+    0 %%**I' + 
 	
ro   c              #  \   K   | j                   j                         D ]  \  }}||f  yw)z/Generator over all the prefix, namespace tuplesN)rk   r   )rh   r   rN  s      rn   r   zGraph.namespaces  s0     !%!7!7!B!B!DFI)## "Es   *,c                :    | j                   j                  ||      S )z5Turn uri into an absolute URI if it's not one already)rk   
absolutizerh   r   defrags      rn   rQ  zGraph.absolutize  s    %%00f==ro   c                     y rq   r   rh   destinationformatr\   encodingargss         rn   	serializezGraph.serialize       ro   c                    y rq   r   rU  s         rn   rZ  zGraph.serialize  s     ro   c                     y rq   r   rU  s         rn   rZ  zGraph.serialize  s     ro   c                     y rq   r   rU  s         rn   rZ  zGraph.serialize$  r[  ro   c                     y rq   r   rU  s         rn   rZ  zGraph.serialize/  s     $'ro   c                   || j                   } t        j                  |t              |       }|gt	               }|5 |j
                  |f|dd| |j                         j                  d      S  |j
                  |f||d| |j                         S t        |d      r/t        t        t           |      } |j
                  |f||d| | S t        |t        j                        rt        |      }nIt        t        |      }	t!        |	      \  }
}}}}}|
dk(  r |dk7  rt#        d|	d      t%        |      }n|	}t'        |d	      5 } |j
                  |f||d| ddd       | S # 1 sw Y   | S xY w)
a  
        Serialize the graph.

        :param destination:
           The destination to serialize the graph to. This can be a path as a
           :class:`str` or :class:`~pathlib.PurePath` object, or it can be a
           :class:`~typing.IO` ``[bytes]`` like object. If this parameter is not
           supplied the serialized graph will be returned.
        :param format:
           The format that the output should be written in. This value
           references a :class:`~rdflib.serializer.Serializer` plugin. Format
           support can be extended with plugins, but ``"xml"``, ``"n3"``,
           ``"turtle"``, ``"nt"``, ``"pretty-xml"``, ``"trix"``, ``"trig"``,
           ``"nquads"``, ``"json-ld"`` and ``"hext"`` are built in. Defaults to
           ``"turtle"``.
        :param base:
           The base IRI for formats that support it. For the turtle format this
           will be used as the ``@base`` directive.
        :param encoding: Encoding of output.
        :param args:
           Additional arguments to pass to the
           :class:`~rdflib.serializer.Serializer` that will be used.
        :return: The serialized graph if ``destination`` is `None`. The
            serialized graph is returned as `str` if no encoding is specified,
            and as `bytes` if an encoding is specified.
        :rtype: :class:`bytes` if ``destination`` is `None` and ``encoding`` is not `None`.
        :rtype: :class:`str` if ``destination`` is `None` and ``encoding`` is `None`.
        :return: ``self`` (i.e. the :class:`~rdflib.graph.Graph` instance) if
            ``destination`` is not `None`.
        :rtype: :class:`~rdflib.graph.Graph` if ``destination`` is not `None`.
        Nutf-8)r\   rX  writefile zthe file URI z2 has an authority component which is not supportedwb)r\   rc   rd   r&   r   rZ  getvaluedecodehasattrr   r   bytesrb   pathlibPurePathstrr   r3  r   r   )rh   rV  rW  r\   rX  rY  
serializerstreamos_pathlocationschemenetlocpathparams_queryfragments                   rn   rZ  zGraph.serialize9  s   R <99D3VZZ
3D9
YF$
$$VQ$QDQ(//88$
$$VR$RTR((;("U)[1F J  NdXNN"  +w'7'78k*[1AI(AS>ffhV#|(+H<7ij  +40G&Ggt$$
$$VR$RTR % %s   E//E9c                b    t        | j                  d ||      j                  |      |d       y )N)rW  rX  T)rc  flush)printrZ  rg  )rh   rW  rX  outs       rn   ry  zGraph.print  s/     	NN4NBII(S	
ro   c                d   t        ||||||      }||j                  }d}|t        |d      rnt        |j                  dd      rWt        |j                  j                  t              r3t        j                  j                  |j                  j                        }|d}d}	  t        j                  |t                     }		  |	j                   || fi | 	 |j&                  r|j)                          | S # t        j                  $ r_ t        j                  j                  t        |t              s|n
t        |            }|  t        j                  |t                     }	Y w xY w# t"        $ r}
|rt%        d|z        |
d}
~
ww xY w# |j&                  r|j)                          w w xY w)	a  
        Parse an RDF source adding the resulting triples to the Graph.

        The source is specified using one of source, location, file or data.

        .. caution::

           This method can access directly or indirectly requested network or
           file resources, for example, when parsing JSON-LD documents with
           ``@context`` directives that point to a network location.

           When processing untrusted or potentially malicious documents,
           measures should be taken to restrict network and file access.

           For information on available security measures, see the RDFLib
           :doc:`Security Considerations </security_considerations>`
           documentation.

        :param source: An `xml.sax.xmlreader.InputSource`, file-like object,
            `pathlib.Path` like object, or string. In the case of a string the string
            is the location of the source.
        :param location: A string indicating the relative or absolute URL of the
            source. `Graph`'s absolutize method is used if a relative location
            is specified.
        :param file: A file-like object.
        :param data: A string containing the data to be parsed.
        :param format: Used if format can not be determined from source, e.g.
            file extension or Media Type. Defaults to text/turtle. Format
            support can be extended with plugins, but "xml", "n3" (use for
            turtle), "nt" & "trix" are built in.
        :param publicID: the logical URI to use as the document base. If None
            specified the document location is used (at least in the case where
            there is a document location). This is used as the base URI when
            resolving relative URIs in the source document, as defined in `IETF
            RFC 3986
            <https://datatracker.ietf.org/doc/html/rfc3986#section-5.1.4>`_,
            given the source document does not define a base URI.
        :return: ``self``, i.e. the :class:`~rdflib.graph.Graph` instance.

        Examples:

        >>> my_data = '''
        ... <rdf:RDF
        ...   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        ...   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
        ... >
        ...   <rdf:Description>
        ...     <rdfs:label>Example</rdfs:label>
        ...     <rdfs:comment>This is really just an example.</rdfs:comment>
        ...   </rdf:Description>
        ... </rdf:RDF>
        ... '''
        >>> import os, tempfile
        >>> fd, file_name = tempfile.mkstemp()
        >>> f = os.fdopen(fd, "w")
        >>> dummy = f.write(my_data)  # Returns num bytes written
        >>> f.close()

        >>> g = Graph()
        >>> result = g.parse(data=my_data, format="application/rdf+xml")
        >>> len(g)
        2

        >>> g = Graph()
        >>> result = g.parse(location=file_name, format="application/rdf+xml")
        >>> len(g)
        2

        >>> g = Graph()
        >>> with open(file_name, "r") as f:
        ...     result = g.parse(f, format="application/rdf+xml")
        >>> len(g)
        2

        >>> os.remove(file_name)

        >>> # default turtle parsing
        >>> result = g.parse(data="<http://example.com/a> <http://example.com/a> <http://example.com/a> .")
        >>> len(g)
        3

        sourcepublicIDrp  rc  datarW  NFrc  nameturtleTzCould not guess RDF format for %r from file extension so tried Turtle but failed.You can explicitly specify format using the format argument.)r#   content_typerh  getattrrc  rb   r  rl  rdflibutilguess_formatrc   rd   r"   PluginExceptionr!   parseSyntaxErrorr   
auto_closer   )rh   r}  r~  rW  rp  rc  r  rY  could_not_guess_formatparserses              rn   r  zGraph.parse  s   ~ %
 >((F!&>'FKK6v{{//511&++2B2BC~!)-&	2/VZZ/1F	FLL..   3 %% 		2 [[--(=3v;F ~/VZZ/1F		2  	%!S  	    !s7   %C8 E- 8A/E*)E*-	F6FFF F/c                   |xs i }|xs t        | j                               }| j                  rd}n3t        | t              r| j
                  j                  }n| j                  }t        | j                  d      r#|r!	  | j                  j                  ||||fi |S t        |t        j                        s2t        j                  t        t        |      t        j                        }t        |t        j                         s* t        j                  |t        j                         |       } | |j                  |||fi |      S # t        $ r Y w xY w)a  
        Query this graph.

        A type of 'prepared queries' can be realised by providing initial
        variable bindings with initBindings

        Initial namespaces are used to resolve prefixes used in the query, if
        none are given, the namespaces from the graph's namespace manager are
        used.

        .. caution::

           This method can access indirectly requested network endpoints, for
           example, query processing will attempt to access network endpoints
           specified in ``SERVICE`` directives.

           When processing untrusted or potentially malicious queries, measures
           should be taken to restrict network and file access.

           For information on available security measures, see the RDFLib
           :doc:`Security Considerations </security_considerations>`
           documentation.

        :returntype: :class:`~rdflib.query.Result`

        	__UNION__query)dictr   rZ   rb   rD   default_contextrj   rh  ri   r  NotImplementedErrorResultrc   rd   r   rl  	Processor)	rh   query_object	processorresultinitNsinitBindingsuse_store_providedkwargsquery_graphs	            rn   r  zGraph.query!  s&   J $)r24 12%K./..99K//K4::w',>	'tzz''  	
   &%,,/ZZS& 15<<@F)U__5>

9eoo>tDI oioolL&SFSTT ' s   ?E
 
	EEc                   |xs i }|xs t        | j                               }| j                  rd}n3t        | t              r| j
                  j                  }n| j                  }t        | j                  d      r#|r!	  | j                  j                  ||||fi |S t        |t        j                        s* t        j                  |t        j                        |       } |j                  |||fi |S # t        $ r Y dw xY w)a^  
        Update this graph with the given update query.

        .. caution::

           This method can access indirectly requested network endpoints, for
           example, query processing will attempt to access network endpoints
           specified in ``SERVICE`` directives.

           When processing untrusted or potentially malicious queries, measures
           should be taken to restrict network and file access.

           For information on available security measures, see the RDFLib
           :doc:`Security Considerations </security_considerations>`
           documentation.
        r  update)r  r   rZ   rb   rD   r  rj   rh  ri   r  r  r  UpdateProcessorrc   rd   )rh   update_objectr  r  r  r  r  r  s           rn   r  zGraph.updatec  s    2 $)r24 12%K./..99K//K4::x(-?	(tzz((! 	
   )U%:%:;D

9e.C.CDTJIy|VNvNN ' s   ?C8 8	DDc                @    d| j                   j                  |      z  S )%Return an n3 identifier for the Graphz[%s]rk   rj   r{   rh   rk   s     rn   r{   zGraph.n3       **=N*OOOro   c                >    t         | j                  | j                  ffS rq   )rA   ri   rj   rr   s    rn   
__reduce__zGraph.__reduce__  s"    


 	
ro   c                   t        |       t        |      k7  ry| D ]1  \  }}}t        |t              rt        |t              r)|||f|vs1 y |D ]1  \  }}}t        |t              rt        |t              r)|||f| vs1 y y)z
        does a very basic check if these graphs are the same
        If no BNodes are involved, this is accurate.

        See rdflib.compare for a correct implementation of isomorphism checks
        FT)lenrb   r(   )rh   r   r   r   r   s        rn   
isomorphiczGraph.isomorphic  s     t9E
"GAq!a'
1e0D1ayE)   GAq!a'
1e0D1ayD(  
 ro   c                   t        | j                               }g }|sy|t        j                  t	        |               g}|r|j                         }||vr|j                  |       | j                  |      D ]  }||vs||vs|j                  |        | j                  |      D ]  }||vs||vs|j                  |        |rt	        |      t	        |      k(  ryy)a  Check if the Graph is connected

        The Graph is considered undirectional.

        Performs a search on the Graph, starting from a random node. Then
        iteratively goes depth-first through the triplets where the node is
        subject and object. Return True if all nodes have been visited and
        False if it cannot continue and there are still unvisited nodes left.
        F)r  )r	  T)	r   	all_nodesrandom	randranger  popappendr   r   )rh   r  
discoveredvisitingr   new_xs         rn   	connectedzGraph.connected  s     )*	
 f..s9~>?@A
"!!!$a0
*uH/DOOE* 1 a0
*uH/DOOE* 1  y>S_,ro   c                v    t        | j                               }|j                  | j                                |S rq   )r   r   r  r   )rh   ress     rn   r  zGraph.all_nodes  s)    $,,.!

4==?#
ro   c                    t        | |      S )a  Create a new ``Collection`` instance.

        Parameters:

        - ``identifier``: a URIRef or BNode instance.

        Example::

            >>> graph = Graph()
            >>> uri = URIRef("http://example.org/resource")
            >>> collection = graph.collection(uri)
            >>> assert isinstance(collection, Collection)
            >>> assert collection.uri is uri
            >>> assert collection.graph is graph
            >>> collection += [ Literal(1), Literal(2) ]
        r   rh   rj   s     rn   
collectionzGraph.collection  s    $ $
++ro   c                P    t        |t              st        |      }t        | |      S )a  Create a new ``Resource`` instance.

        Parameters:

        - ``identifier``: a URIRef or BNode instance.

        Example::

            >>> graph = Graph()
            >>> uri = URIRef("http://example.org/resource")
            >>> resource = graph.resource(uri)
            >>> assert isinstance(resource, Resource)
            >>> assert resource.identifier is uri
            >>> assert resource.graph is graph

        )rb   r-   r/   r%   r  s     rn   resourcezGraph.resource  s%    " *d+
+Jj))ro   c                ^    | j                  d      D ]  }|j                   ||              y )Nr   )r   r   )rh   targetr8  ts       rn   _process_skolem_tupleszGraph._process_skolem_tuples  s(     01AJJtAw 2ro   c                    dfddfd}|
t               n|}| j                  ||       |S t        t              r| j                  |fd       |S )Nc                    |\  }}}|| k(  r+t         rt        |t              sJ |j                        }|| k(  r+t         rt        |t              sJ |j                        }|||fS N)	authoritybasepath)r   rb   r(   	skolemize)bnoder  r   r   r   r  r  s        rn   do_skolemizez%Graph.skolemize.<locals>.do_skolemize  sq    IQ1Ez %a///KK)hKGEz %a///KK)hKGa7Nro   c                    | \  }}}t        |t              r|j                        }t        |t              r|j                        }|||fS r  )rb   r(   r  )r  r   r   r   r  r  s       rn   do_skolemize2z&Graph.skolemize.<locals>.do_skolemize2%  sQ    IQ1!U#KK)hKG!U#KK)hKGa7Nro   c                     |       S rq   r   )r  r  r  s    rn   <lambda>z!Graph.skolemize.<locals>.<lambda>3  s    ,ua:Pro   )r  r(   r  r6   returnr6   r  r6   r  r6   )rA   r  rb   r(   )rh   	new_graphr  r  r  r  r   r  s     ```  @rn   r  zGraph.skolemize  s[    
		 &-9=''>
 	 u%''0PQro   c                    dddd}|
t               n|}| j                  ||       |S t        t              r| j                  |fd       |S )Nc                    |\  }}}|| k(  r(t         rt        |t              sJ |j                         }|| k(  r(t         rt        |t              sJ |j                         }|||fS rq   )r   rb   r/   de_skolemize)urirefr  r   r   r   s        rn   do_de_skolemizez+Graph.de_skolemize.<locals>.do_de_skolemize:  sd    IQ1F{ %a000NN$F{ %a000NN$a7Nro   c                   | \  }}}t        j                  |      rt        |      j                         }n.t        j                  |      rt        |      j                         }t        |t              r]t        j                  |      rt        |      j                         }n.t        j                  |      rt        |      j                         }|||fS rq   )r.   _is_rdflib_skolemr  r)   _is_external_skolemrb   r/   )r  r   r   r   s       rn   do_de_skolemize2z,Graph.de_skolemize.<locals>.do_de_skolemize2F  s    IQ1,,Q/N//1**1-!H))+!V$003#A335A..q1a--/Aa7Nro   c                     |       S rq   r   )r  r  r  s    rn   r  z$Graph.de_skolemize.<locals>.<lambda>^  s    /&RS:Tro   )r  r/   r  r6   r  r6   r  )rA   r  rb   r)   )rh   r  r  r  r   r  s     `  @rn   r  zGraph.de_skolemize7  s\    
		$ &-9>''0@A
 	 &''0TUro   )target_graphc               J     |t               n|d fd |       S )a  Retrieves the Concise Bounded Description of a Resource from a Graph

        Concise Bounded Description (CBD) is defined in [1] as:

        Given a particular node (the starting node) in a particular RDF graph (the source graph), a subgraph of that
        particular graph, taken to comprise a concise bounded description of the resource denoted by the starting node,
        can be identified as follows:

            1. Include in the subgraph all statements in the source graph where the subject of the statement is the
                starting node;

            2. Recursively, for all statements identified in the subgraph thus far having a blank node object, include
                in the subgraph all statements in the source graph where the subject of the statement is the blank node
                in question and which are not already included in the subgraph.

            3. Recursively, for all statements included in the subgraph thus far, for all reifications of each statement
                in the source graph, include the concise bounded description beginning from the rdf:Statement node of
                each reification.

        This results in a subgraph where the object nodes are either URI references, literals, or blank nodes not
        serving as the subject of any statement in the graph.

        [1] https://www.w3.org/Submission/CBD/

        :param resource: a URIRef object, of the Resource for queried for
        :param target_graph: Optionally, a graph to add the CBD to; otherwise, a new graph is created for the CBD
        :return: a Graph, subgraph of self if no graph was provided otherwise the provided graph

        c                d   j                  | d d f      D ]<  \  }}}	j                  |||f       t        |      t        u s-|d d f	vs5 |       > j                  d t        j
                  | f      D ]7  \  }}}j                  |d d f      D ]  \  }}}	j                  |||f        9 y rq   )r   r   rx   r(   r   r  )
r   r   r   r   s2p2o2
add_to_cbdrh   subgraphs
          rn   r  zGraph.cbd.<locals>.add_to_cbd  s    <<dD(9:1aaAY'7e#D$x(GqM	 ;  <<s{{C(@A1a"&,,4"?JBBLL"b". #@ Bro   )r   r2   r  None)rA   )rh   r  r  r  r  s   `  @@rn   cbdz	Graph.cbdb  s,    @ wH#H	/$ 	8ro   )r   NNNr  )
ri   Union[Store, str]rj   ,Optional[Union[_ContextIdentifierType, str]]rk   Optional[NamespaceManager]r\   r[   rl   rG   )r  r'   )r  r8   )r  r    )rv   r    r  r  r  rl  )rh   r@   r  r@   )rh   r@   r   rl  r  r@   F)r   rl  r   rW   r  zOptional[int])r   rW   r  r  rh   r@   r   r6   r  r@   rh   r@   r   Iterable[_QuadType]r  r@   )rh   r@   r   r9   r  r@   r   r9   r  "Generator[_TripleType, None, None]r   r;   r  &Generator[_TriplePathType, None, None]r   r=   r  .Generator[_TripleOrTriplePathType, None, None]r  int)r  r  )r   r=   r  rW   )r  rW   )r   rA   r  rW   )rh   r@   r   Iterable[_TripleType]r  r@   )r   rA   r  rA   )rh   r@   r   z0Tuple[_SubjectType, _PredicateType, _ObjectType]r  r@   )NNF)r  !Union[None, Path, _PredicateType]r	  z/Optional[Union[_ObjectType, List[_ObjectType]]]r
  rW   r  z#Generator[_SubjectType, None, None])r  Optional[_SubjectType]r	  Optional[_ObjectType]r
  rW   r  z%Generator[_PredicateType, None, None])r  z1Optional[Union[_SubjectType, List[_SubjectType]]]r  r  r
  rW   r  "Generator[_ObjectType, None, None]r^   )r	  r  r
  rW   r  z:Generator[Tuple[_SubjectType, _PredicateType], None, None])r  r  r
  rW   r  z7Generator[Tuple[_SubjectType, _ObjectType], None, None])r  r  r
  rW   r  z9Generator[Tuple[_PredicateType, _ObjectType], None, None]rq   r   _TripleChoiceTyper   Optional[_ContextType]r  r  ).....)r  r  r  r  r	  r  r   Optional[Node]r!  rW   r  r  )r  r  r  r  r	  r  r   r  r!  rW   r  r  )r  r  r  Optional[_PredicateType]r	  r  r   r  r!  rW   r  r  )r  r  r  r  r	  r  r   r  r!  rW   r  r  )r   r-   r  zGenerator[Node, None, None])r8  z-Callable[[_TCArgT, Graph], Iterable[_TCArgT]]r9  rU   r:  zOptional[Dict[_TCArgT, int]])r  r  r  r  r@  z+Optional[Dict[Optional[_SubjectType], int]]r  z-Generator[Optional[_SubjectType], None, None])r  r  r	  r  r@  z*Optional[Dict[Optional[_ObjectType], int]]r  z,Generator[Optional[_ObjectType], None, None]r   rl  r  rl  Tr   rl  rJ  rW   r  zTuple[str, URIRef, str])TF)
r   r[   rN  r   rL  rW   rM  rW   r  r  r  z)Generator[Tuple[str, URIRef], None, None]r   )r   rl  rS  r  r  r/   )rV  r  rW  rl  r\   r[   rX  rl  rY  r   r  ri  )...)....)rV  r  rW  rl  r\   r[   rX  r  rY  r   r  rl  )rV  z'Union[str, pathlib.PurePath, IO[bytes]]rW  rl  r\   r[   rX  r[   rY  r   r  rA   )rV  1Optional[Union[str, pathlib.PurePath, IO[bytes]]]rW  rl  r\   r[   rX  r[   rY  r   r  zUnion[bytes, str, Graph])Nr  NN)rh   r@   rV  r  rW  rl  r\   r[   rX  r[   rY  r   r  zUnion[bytes, str, _GraphT])r  ra  N)rW  rl  rX  rl  rz  zOptional[TextIO]r  r  NNNNNNr}  MOptional[Union[IO[bytes], TextIO, InputSource, str, bytes, pathlib.PurePath]]r~  r[   rW  r[   rp  r[   rc  z!Optional[Union[BinaryIO, TextIO]]r  zOptional[Union[str, bytes]]rY  r   r  rA   )sparqlr  NNT)r  zUnion[str, Query]r  zUnion[str, query.Processor]r  zUnion[str, Type[query.Result]]r  Optional[Mapping[str, Any]]r  "Optional[Mapping[str, Identifier]]r  rW   r  r   r  zquery.Result)r  NNT)r  zUnion[Update, str]r  z(Union[str, rdflib.query.UpdateProcessor]r  r	  r  r
  r  rW   r  r   r  r  rk   r  r  rl  r  z8Tuple[Type[Graph], Tuple[Store, _ContextIdentifierType]])r  z	Set[Node])rj   r2   r  r   )rj   zUnion[Node, str]r  r%   )r  rA   r8  z$Callable[[_TripleType], _TripleType]r  r  NNNN)
r  Optional[Graph]r  zOptional[BNode]r  r[   r  r[   r  rA   NN)r  r  r  zOptional[URIRef]r  rA   )r  r2   r  r  r  rA   )Or|   
__module____qualname____doc____annotations__r`   propertyri   rj   rk   setterry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __or____and__r   r   r   r   r   r   r   r  r"  r   r5  r7  r?  rC  rE  rH  r   r   rQ  rZ  ry  r  r  r  r{   r  r  r  r  r  r  r  r  r  r  __classcell__rm   s   @rn   rA   rA     s^
   <| 
 $-CG8<"/7# # A# 6	#
 # -#4   ! ! ( ( & &L.

8Y
 1"1 
,1 1
 5&5 
05 5
 =#= 
8= =
!#! 
8!"EN20%P

-

-

/
 FGO	* 8<BF	"4" @" 	"
 
-"@ +/(,	' & 	
 
/4 FJ7;	"B" 5" 	"
 
,"< DI+<@	C. 8<4  
A	0 FK->B	B0 +/! ( 
,	  (+"%  &	
    
   +."%'  	
    
   .1"% , 	
    
   +..1(+"%' , &	
    
  +/.1ii(,"&?'? ,? &	?
  ? ? 
?B( .2	<;< < +	<D AE	' , >	
 
72 @D	+ & =	
 
6*1C 

 
 	

 
 

8$
>
   	
   
    !	  	   
    !  	
   
   !"%<  	
    
   JM!"%'F' ' 	'
  ' ' 
"' ' JN""&IIFI I 	I
  I I 
$IZ  $	



 

 	


 


  "& $"&26,0O
O
  O O  O 0O *O O 
Oh 2:19.2;?#'@U'@U /@U /	@U
 ,@U 9@U !@U @U 
@UJ ?G.2;?#'2O)2O <2O ,	2O
 92O !2O 2O 
2OhP
*#J
,(**  #G 	  &*!%#'"&#"# # !	#
  # 
#L MQ)()9I)	)X JN9$97F9	9ro   c                      e Zd ZU dZded<   	 	 	 d"	 	 	 	 	 d# fdZd$dZe	 d%	 	 	 	 	 d&d       Ze	 d%	 	 	 	 	 d'd       Ze	 d%	 	 	 	 	 d(d       Ze	 d%	 	 	 	 	 d)d	       Ze	 d%	 	 	 	 	 d*d
       Ze	 d%	 	 	 	 	 d+d       Z	 d%	 	 	 	 	 d+dZd,dZ		 	 	 	 	 	 d-dZ
ed.d       Zed/d       Z	 	 	 	 d0dZ	 	 	 	 	 	 d1dZd-dZe	 d2	 	 	 	 	 d3d       Ze	 d2	 	 	 	 	 d4d       Ze	 d2	 	 	 	 	 d5d       Z	 d6	 	 	 	 	 d5dZ	 d6	 	 	 d7dZ	 d6	 	 	 	 	 d8dZd9dZ	 d6	 	 	 d:dZd;dZ	 	 d<	 	 	 	 	 	 	 d=dZd>dZd6d?dZ	 	 	 	 	 	 d@	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dAd ZdBd!Z xZS )CrD   a  A ConjunctiveGraph is an (unnamed) aggregation of all the named
    graphs in a store.

    .. warning::
        ConjunctiveGraph is deprecated, use :class:`~rdflib.graph.Dataset` instead.

    It has a ``default`` graph, whose name is associated with the
    graph throughout its life. :meth:`__init__` can take an identifier
    to use as the name of this default graph or it will assign a
    BNode.

    All methods that add triples work against this default graph.

    All queries are carried out against the union of all graphs.
    r5   r  c                2   t         t        |   ||       t        |       t        u rt	        j
                  dt        d       | j                  j                  sJ d       d| _        d| _	        t        | j                  |xs
 t               |      | _        y )N)rj   z4ConjunctiveGraph is deprecated, use Dataset instead.   )
stacklevelz9ConjunctiveGraph must be backed by a context aware store.Tri   rj   r\   )r_   rD   r`   rx   warningswarnDeprecationWarningri   rX   rZ   rA   r(   r  )rh   ri   rj   default_graph_baserm   s       rn   r`   zConjunctiveGraph.__init__  s     	.u.L:))MMF" zz'' 	
J	
' "!-2**)>uwEW.
ro   c                L    d}|| j                   j                  j                  z  S )NzK[a rdflib:ConjunctiveGraph;rdflib:storage [a rdflib:Store;rdfs:label '%s']]ri   rm   r|   rh   patterns     rn   r}   zConjunctiveGraph.__str__  s)    0 	 --6666ro   c                     y rq   r   rh   triple_or_quadr   s      rn   _spoczConjunctiveGraph._spoc  s    
 ro   c                     y rq   r   r(  s      rn   r*  zConjunctiveGraph._spoc      
  ro   c                     y rq   r   r(  s      rn   r*  zConjunctiveGraph._spoc  s    
 47ro   c                     y rq   r   r(  s      rn   r*  zConjunctiveGraph._spoc  s    
 ro   c                     y rq   r   r(  s      rn   r*  zConjunctiveGraph._spoc  r,  ro   c                     y rq   r   r(  s      rn   r*  zConjunctiveGraph._spoc  r,  ro   c                    |ddd|r| j                   fS dfS t        |      dk(  r|r| j                   nd}|\  }}}n&t        |      dk(  r|\  }}}}| j                  |      }fS )z_
        helper method for having methods that support
        either triples or quads
        N      )r  r  _graph)rh   r)  r   r   r   r   r   s          rn   r*  zConjunctiveGraph._spoc  s     !$gd&:&:PP4PP~!#(/$$TA&IQ1 A%)LQ1aAA!Qzro   c                h    | j                  |      \  }}}}| j                  |||f|      D ]  } y y)z)Support for 'triple/quad in graph' syntaxr   TF)r*  r   )rh   r)  r   r   r   r   r  s          rn   r   zConjunctiveGraph.__contains__  s;    ZZ/
1aq!Qi3A 4ro   c                    | j                  |d      \  }}}}t        |||       | j                  j                  |||f|d       | S )zu
        Add a triple or quad to the store.

        if a triple is given it is added to the default context
        Tr   F)r   r   )r*  r   ri   r   rh   r)  r   r   r   r   s         rn   r   zConjunctiveGraph.add  sM     ZZZ=
1aAq! 	

1ay!E:ro   c                     y rq   r   rh   r   s     rn   r4  zConjunctiveGraph._graph+  s    MPro   c                     y rq   r   r:  s     rn   r4  zConjunctiveGraph._graph.  s    '*ro   c                N    |y t        |t              s| j                  |      S |S rq   )rb   rA   get_contextr:  s     rn   r4  zConjunctiveGraph._graph1  s,     9!U###A&&Hro   c                P      j                   j                   fd|D                S )z&Add a sequence of triples with contextc              3  n   K   | ],  \  }}}}t        |||      s|||j                  |      f . y wrq   )r   r4  r   s        rn   r   z(ConjunctiveGraph.addN.<locals>.<genexpr>@  s;      
8=*!Q1QPQSTAUQ1dkk!n%s   55ri   r   r   s   ` rn   r   zConjunctiveGraph.addN;  s)    
 	

 
8=
 	
 ro   c                r    | j                  |      \  }}}}| j                  j                  |||f|       | S )z
        Removes a triple or quads

        if a triple is given it is removed from all contexts

        a quad is removed from the given context only

        r   )r*  ri   r   r8  s         rn   r   zConjunctiveGraph.removeF  s<     ZZ/
1a

1a)Q/ro   c                     y rq   r   rh   r)  r   s      rn   r   zConjunctiveGraph.triplesT  s    
 .1ro   c                     y rq   r   rC  s      rn   r   zConjunctiveGraph.triples[  s    
 25ro   c                     y rq   r   rC  s      rn   r   zConjunctiveGraph.triplesb  s    
 :=ro   c              #    K   | j                  |      \  }}}}| j                  |xs |      }| j                  r|| j                  k(  rd}n|| j                  }t	        |t
              r'|| }|j                  |||      D ]  \  }}|||f  y| j                  j                  |||f|      D ]  \  \  }}}}|||f  yw)a  
        Iterate over all the triples in the entire conjunctive graph

        For legacy reasons, this can take the context to query either
        as a fourth element of the quad, or as the explicit context
        keyword parameter. The kw param takes precedence.
        Nr   )	r*  r4  rZ   r  rb   r$   r   ri   r   )rh   r)  r   r   r   r   r   r   s           rn   r   zConjunctiveGraph.triplesi  s      ZZ/
1a++gl+$.....aw1-1Ag . "&!3!3Q1Iw!3!O	Aq2Ag "Ps   CCc              #     K   | j                  |      \  }}}}| j                  j                  |||f|      D ]  \  \  }}}}|D ]
  }||||f   yw)z:Iterate over all the quads in the entire conjunctive graphr   N)r*  ri   r   )rh   r)  r   r   r   r   r   ctxs           rn   r   zConjunctiveGraph.quads  se     
 ZZ/
1a!ZZ//Aq	1/EMIQ1rAsl"  Fs   AAc              #     K   |\  }}}|| j                   s| j                  }n| j                  |      }| j                  j	                  |||f|      D ]  \  \  }}}}	|||f  yw)z<Iterate over all the triples in the entire conjunctive graphNr   )rZ   r  r4  ri   r  )
rh   r   r   r   r   r   s1p1o1r   s
             rn   r  z ConjunctiveGraph.triples_choices  sx      1a?%%..kk'*G !%

 : :Aq!9g : VLRR"b"* !Ws   A'A)c                6    | j                   j                         S )z1Number of triples in the entire conjunctive graph)ri   r   rr   s    rn   r   zConjunctiveGraph.__len__  s    zz!!##ro   c              #     K   | j                   j                  |      D ]*  }t        |t              r| | j	                  |       , yw)z|Iterate over all contexts in the graph

        If triple is specified, iterate over all contexts the triple is in.
        N)ri   r/  rb   rA   r=  )rh   r   r   s      rn   r/  zConjunctiveGraph.contexts  sE      zz**62G'5)  &&w// 3s   A
Ac                n    | j                         D cg c]  }|j                  |k(  s| c}d   S c c}w )z0Returns the graph identified by given identifierr   )r/  rj   )rh   rj   r   s      rn   	get_graphzConjunctiveGraph.get_graph  s0    ==?I?aallj.H?I!LLIs   22c                H    t        | j                  || j                  |      S )zgReturn a context graph for the given identifier

        identifier must be a URIRef or BNode.
        )ri   rj   rk   r\   )rA   ri   rk   )rh   rj   r   r\   s       rn   r=  zConjunctiveGraph.get_context  s'     **!"44	
 	
ro   c                <    | j                   j                  d|       y)z(Removes the given context from the graphr   N)ri   r   )rh   r   s     rn   remove_contextzConjunctiveGraph.remove_context  s    

,g6ro   c                N    |j                  dd      d   }|d}t        ||      S )zURI#context#r   r   z#context)r\   )splitr/   )rh   r   
context_ids      rn   rW  zConjunctiveGraph.context_id  s/    iiQ"#Jjs++ro   c                l    t        ||||||      }| j                  } |j                  |f||d| |S )a7  
        Parse source adding the resulting triples to its own context (sub graph
        of this graph).

        See :meth:`rdflib.graph.Graph.parse` for documentation on arguments.

        If the source is in a format that does not support named graphs its triples
        will be added to the default graph
        (i.e. :attr:`ConjunctiveGraph.default_context`).

        :Returns:

        The graph into which the source was parsed. In the case of n3 it returns
        the root context.

        .. caution::

           This method can access directly or indirectly requested network or
           file resources, for example, when parsing JSON-LD documents with
           ``@context`` directives that point to a network location.

           When processing untrusted or potentially malicious documents,
           measures should be taken to restrict network and file access.

           For information on available security measures, see the RDFLib
           :doc:`Security Considerations </security_considerations>`
           documentation.

        *Changed in 7.0*: The ``publicID`` argument is no longer used as the
        identifier (i.e. name) of the default graph as was the case before
        version 7.0. In the case of sources that do not support named graphs,
        the ``publicID`` parameter will also not be used as the name for the
        graph that the data is loaded into, and instead the triples from sources
        that do not support named graphs will be loaded into the default graph
        (i.e. :attr:`ConjunctiveGraph.default_context`).
        r|  )r~  rW  )r#   r  r  )	rh   r}  r~  rW  rp  rc  r  rY  r   s	            rn   r  zConjunctiveGraph.parse  sM    b %
" &&fGxG$Gro   c                >    t         | j                  | j                  ffS rq   )rD   ri   rj   rr   s    rn   r  zConjunctiveGraph.__reduce__"	  s    $**doo!>>>ro   )r   NN)ri   r  rj   z$Optional[Union[IdentifiedNode, str]]r"  r[   r  r  )r)  rO   r   rW   r  rO   )r)  z%Union[_TripleType, _OptionalQuadType]r   rW   r  r7   )r)  r  r   rW   r  z(Tuple[None, None, None, Optional[Graph]])r)  "Optional[_TripleOrQuadPatternType]r   rW   r  r:   )r)  rT   r   rW   r  r>   )r)  z#Optional[_TripleOrQuadSelectorType]r   rW   r  r>   r)  rT   r  rW   )rh   rC   r)  rP   r  rC   )r   z)Union[Graph, _ContextIdentifierType, str]r  rA   )r   r  r  r  )r   z3Optional[Union[Graph, _ContextIdentifierType, str]]r  r  )rh   rC   r   r  r  rC   ).)r)  rS   r   r  r  r  )r)  rR   r   r  r  r  )r)  rT   r   r  r  r  rq   )r)  rZ  r  z(Generator[_OptionalQuadType, None, None]r  r  r   zOptional[_TripleType]r  z#Generator[_ContextType, None, None])rj   r8   r  zUnion[Graph, None])FN)rj   r  r   rW   r\   r[   r  rA   )r   r5   r  r  )r   rl  rW  r[   r  r/   r  r  r  )r|   r  r  r  r  r`   r}   r   r*  r   r   r4  r   r   r   r   r  r   r/  rP  r=  rS  rW  r  r  r  r  s   @rn   rD   rD     s      "! $-;?,0	
 
 9
 *	
07  !  
	    =    
	     77 7 
2	7 7  :  
	    1    
	      ;    
	    ;  
	* 1 
$ P P* *D	 )<	  +.101 (1 
,	1 1  +.545 (5 
0	5 5  +.=1= (= 
8	= = +/1 ( 
8	D DH	#@	#	1	# +/! ( 
,	"$
 /30+0	,0"M "	
@
 
 	

 

"7, "& $"&26,0E
E
  E E  E 0E *E E 
EN?ro   zurn:x-rdflib:defaultc                  
    e Zd ZdZ	 	 	 d	 	 	 	 	 d fdZddZddZddZ	 	 	 	 ddZ	 	 d	 	 	 	 	 ddZ		 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ
	 	 	 	 dd	Z	 	 	 	 	 	 dd
Z	 d	 	 	 d fdZeZ	 d	 	 	 d fdZ	 	 ddZ xZS )rF   a  
    An RDFLib Dataset is an object that stores multiple Named Graphs - instances of
    RDFLib Graph identified by IRI - within it and allows whole-of-dataset or single
    Graph use.

    RDFLib's Dataset class is based on the `RDF 1.2. 'Dataset' definition
    <https://www.w3.org/TR/rdf12-datasets/>`_:

    ..

        An RDF dataset is a collection of RDF graphs, and comprises:

        - Exactly one default graph, being an RDF graph. The default graph does not
            have a name and MAY be empty.
        - Zero or more named graphs. Each named graph is a pair consisting of an IRI or
            a blank node (the graph name), and an RDF graph. Graph names are unique
            within an RDF dataset.

    Accordingly, a Dataset allows for `Graph` objects to be added to it with
    :class:`rdflib.term.URIRef` or :class:`rdflib.term.BNode` identifiers and always
    creats a default graph with the :class:`rdflib.term.URIRef` identifier
    :code:`urn:x-rdflib:default`.

    Dataset extends Graph's Subject, Predicate, Object (s, p, o) 'triple'
    structure to include a graph identifier - archaically called Context - producing
    'quads' of s, p, o, g.

    Triples, or quads, can be added to a Dataset. Triples, or quads with the graph
    identifer :code:`urn:x-rdflib:default` go into the default graph.

    .. note:: Dataset builds on the `ConjunctiveGraph` class but that class's direct
        use is now deprecated (since RDFLib 7.x) and it should not be used.
        `ConjunctiveGraph` will be removed from future RDFLib versions.

    Examples of usage and see also the examples/datast.py file:

    >>> # Create a new Dataset
    >>> ds = Dataset()
    >>> # simple triples goes to default graph
    >>> ds.add((
    ...     URIRef("http://example.org/a"),
    ...     URIRef("http://www.example.org/b"),
    ...     Literal("foo")
    ... ))  # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Dataset'>)>
    >>>
    >>> # Create a graph in the dataset, if the graph name has already been
    >>> # used, the corresponding graph will be returned
    >>> # (ie, the Dataset keeps track of the constituent graphs)
    >>> g = ds.graph(URIRef("http://www.example.com/gr"))
    >>>
    >>> # add triples to the new graph as usual
    >>> g.add((
    ...     URIRef("http://example.org/x"),
    ...     URIRef("http://example.org/y"),
    ...     Literal("bar")
    ... )) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> # alternatively: add a quad to the dataset -> goes to the graph
    >>> ds.add((
    ...     URIRef("http://example.org/x"),
    ...     URIRef("http://example.org/z"),
    ...     Literal("foo-bar"),
    ...     g
    ... )) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Dataset'>)>
    >>>
    >>> # querying triples return them all regardless of the graph
    >>> for t in ds.triples((None,None,None)):  # doctest: +SKIP
    ...     print(t)  # doctest: +NORMALIZE_WHITESPACE
    (rdflib.term.URIRef("http://example.org/a"),
     rdflib.term.URIRef("http://www.example.org/b"),
     rdflib.term.Literal("foo"))
    (rdflib.term.URIRef("http://example.org/x"),
     rdflib.term.URIRef("http://example.org/z"),
     rdflib.term.Literal("foo-bar"))
    (rdflib.term.URIRef("http://example.org/x"),
     rdflib.term.URIRef("http://example.org/y"),
     rdflib.term.Literal("bar"))
    >>>
    >>> # querying quads() return quads; the fourth argument can be unrestricted
    >>> # (None) or restricted to a graph
    >>> for q in ds.quads((None, None, None, None)):  # doctest: +SKIP
    ...     print(q)  # doctest: +NORMALIZE_WHITESPACE
    (rdflib.term.URIRef("http://example.org/a"),
     rdflib.term.URIRef("http://www.example.org/b"),
     rdflib.term.Literal("foo"),
     None)
    (rdflib.term.URIRef("http://example.org/x"),
     rdflib.term.URIRef("http://example.org/y"),
     rdflib.term.Literal("bar"),
     rdflib.term.URIRef("http://www.example.com/gr"))
    (rdflib.term.URIRef("http://example.org/x"),
     rdflib.term.URIRef("http://example.org/z"),
     rdflib.term.Literal("foo-bar"),
     rdflib.term.URIRef("http://www.example.com/gr"))
    >>>
    >>> # unrestricted looping is equivalent to iterating over the entire Dataset
    >>> for q in ds:  # doctest: +SKIP
    ...     print(q)  # doctest: +NORMALIZE_WHITESPACE
    (rdflib.term.URIRef("http://example.org/a"),
     rdflib.term.URIRef("http://www.example.org/b"),
     rdflib.term.Literal("foo"),
     None)
    (rdflib.term.URIRef("http://example.org/x"),
     rdflib.term.URIRef("http://example.org/y"),
     rdflib.term.Literal("bar"),
     rdflib.term.URIRef("http://www.example.com/gr"))
    (rdflib.term.URIRef("http://example.org/x"),
     rdflib.term.URIRef("http://example.org/z"),
     rdflib.term.Literal("foo-bar"),
     rdflib.term.URIRef("http://www.example.com/gr"))
    >>>
    >>> # resticting iteration to a graph:
    >>> for q in ds.quads((None, None, None, g)):  # doctest: +SKIP
    ...     print(q)  # doctest: +NORMALIZE_WHITESPACE
    (rdflib.term.URIRef("http://example.org/x"),
     rdflib.term.URIRef("http://example.org/y"),
     rdflib.term.Literal("bar"),
     rdflib.term.URIRef("http://www.example.com/gr"))
    (rdflib.term.URIRef("http://example.org/x"),
     rdflib.term.URIRef("http://example.org/z"),
     rdflib.term.Literal("foo-bar"),
     rdflib.term.URIRef("http://www.example.com/gr"))
    >>> # Note that in the call above -
    >>> # ds.quads((None,None,None,"http://www.example.com/gr"))
    >>> # would have been accepted, too
    >>>
    >>> # graph names in the dataset can be queried:
    >>> for c in ds.graphs():  # doctest: +SKIP
    ...     print(c.identifier)  # doctest:
    urn:x-rdflib:default
    http://www.example.com/gr
    >>> # A graph can be created without specifying a name; a skolemized genid
    >>> # is created on the fly
    >>> h = ds.graph()
    >>> for c in ds.graphs():  # doctest: +SKIP
    ...     print(c)  # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
    DEFAULT
    https://rdflib.github.io/.well-known/genid/rdflib/N...
    http://www.example.com/gr
    >>> # Note that the Dataset.graphs() call returns names of empty graphs,
    >>> # too. This can be restricted:
    >>> for c in ds.graphs(empty=False):  # doctest: +SKIP
    ...     print(c)  # doctest: +NORMALIZE_WHITESPACE
    DEFAULT
    http://www.example.com/gr
    >>>
    >>> # a graph can also be removed from a dataset via ds.remove_graph(g)

    ... versionadded:: 4.0
    c                    t         t        |   |d        | j                  j                  st        d      t        | j                  t        |      | _        || _	        y )N)ri   rj   z.DataSet must be backed by a graph-aware store!r  )
r_   rF   r`   ri   graph_aware	ExceptionrA   DATASET_DEFAULT_GRAPH_IDr  rZ   )rh   ri   rZ   r"  rm   s       rn   r`   zDataset.__init__	  sV     	gt%Ed%Czz%%LMM$**/# 
 +ro   c                L    d}|| j                   j                  j                  z  S )NzB[a rdflib:Dataset;rdflib:storage [a rdflib:Store;rdfs:label '%s']]r$  r%  s     rn   r}   zDataset.__str__	  s'    S 	 --6666ro   c                H    t        |       | j                  | j                  ffS rq   )rx   ri   rZ   rr   s    rn   r  zDataset.__reduce__	  s     T
TZZ););<==ro   c                ^    | j                   | j                  | j                  | j                  fS rq   ri   rj   r  rZ   rr   s    rn   __getstate__zDataset.__getstate__	  s%    zz4??D,@,@$BTBTTTro   c                :    |\  | _         | _        | _        | _        y rq   re  )rh   states     rn   __setstate__zDataset.__setstate__	  s    
 QVM
DOT%94;Mro   c                    |7ddl m}m} | j                  d||z   d       t	               j                         }| j                  |      }||_        | j                  j                  |       |S )Nr   )_SKOLEM_DEFAULT_AUTHORITYrdflib_skolem_genidgenidF)rL  )
rdflib.termrk  rl  r   r(   r  r4  r\   ri   	add_graph)rh   rj   r\   rk  rl  gs         rn   graphzDataset.graph	  sk    
 RII),??  
 **,JKK
#

Qro   c           	     `    t        j                  | ||||||fi |}| j                  |       |S )a  
        Parse an RDF source adding the resulting triples to the Graph.

        See :meth:`rdflib.graph.Graph.parse` for documentation on arguments.

        The source is specified using one of source, location, file or data.

        If the source is in a format that does not support named graphs its triples
        will be added to the default graph
        (i.e. :attr:`.Dataset.default_context`).

        .. caution::

           This method can access directly or indirectly requested network or
           file resources, for example, when parsing JSON-LD documents with
           ``@context`` directives that point to a network location.

           When processing untrusted or potentially malicious documents,
           measures should be taken to restrict network and file access.

           For information on available security measures, see the RDFLib
           :doc:`Security Considerations </security_considerations>`
           documentation.

        *Changed in 7.0*: The ``publicID`` argument is no longer used as the
        identifier (i.e. name) of the default graph as was the case before
        version 7.0. In the case of sources that do not support named graphs,
        the ``publicID`` parameter will also not be used as the name for the
        graph that the data is loaded into, and instead the triples from sources
        that do not support named graphs will be loaded into the default graph
        (i.e. :attr:`.Dataset.default_context`).
        )rD   r  rq  )	rh   r}  r~  rW  rp  rc  r  rY  r   s	            rn   r  zDataset.parse	  s>    Z ""&(FHdD
DH
 	

1ro   c                $    | j                  |      S )zalias of graph for consistency)rq  rh   rp  s     rn   ro  zDataset.add_graph2
  s     zz!}ro   c                    t        |t              s| j                  |      }| j                  j	                  |       ||| j
                  k(  r%| j                  j                  | j
                         | S rq   )rb   rA   r=  ri   remove_graphr  ro  rt  s     rn   rv  zDataset.remove_graph8
  sa     !U#  #A

"9T111 JJ  !5!56ro   c              #     K   d}t         t        |   |      D ]  }||j                  t        k(  z  }|  |s| j                  t               y y wr^   )r_   rF   r/  rj   ra  rq  )rh   r   r   r   rm   s       rn   r/  zDataset.contextsE
  sW      w.v6Aq||'???GG 7 **566 s   AAc              #     K   t         t        |   |      D ];  \  }}}}|j                  | j                  k(  r	|||d f *||||j                  f = y wrq   )r_   rF   r   rj   r  )rh   quadr   r   r   r   rm   s         rn   r   zDataset.quadsR
  s\       4T:JAq!Q||t333Atm# Aq||++ ;s   AAc                $    | j                  d      S )z$Iterates over all quads in the storer  )r   rr   s    rn   r   zDataset.__iter__^
  s     zz233ro   )r   FN)ri   r  rZ   rW   r"  r[   r  )r  z(Tuple[Type[Dataset], Tuple[Store, bool]])r  8Tuple[Store, _ContextIdentifierType, _ContextType, bool])rh  r{  r  r  r  )rj   :Optional[Union[_ContextIdentifierType, _ContextType, str]]r\   r[   r  rA   r  r  )rp  r|  r  rA   )rh   rE   rp  r|  r  rE   rq   r\  )ry  rZ  r  2Generator[_OptionalIdentifiedQuadType, None, None])r  r}  )r|   r  r  r  r`   r}   r  rf  ri  rq  r  ro  rv  r/  graphsr   r   r  r  s   @rn   rF   rF   )	  sm   Wv $-#,0	+ + + *	+$7>UVMV	V RV"N  
	2 "& $"&26,01
1
  1 1  1 01 *1 1 
1fK	V	 /37+7	,7 F :>	,6	,	;	,4	;4ro   c                  V     e Zd ZdZ	 	 	 	 d fdZd	dZd
dZdddZddZddZ	 xZ
S )rH   a  
    Quoted Graphs are intended to implement Notation 3 formulae. They are
    associated with a required identifier that the N3 parser *must* provide
    in order to maintain consistent formulae identification for scenarios
    such as implication and other such processing.
    c                .    t         t        |   ||       y rq   )r_   rH   r`   )rh   ri   rj   rm   s      rn   r`   zQuotedGraph.__init__m
  s    
 	k4)%<ro   c                    |\  }}}t        |t              sJ d|d       t        |t              sJ d|d       t        |t              sJ d|d       | j                  j                  |||f| d       | S )r   r   r   r   r   Tr   )rb   r-   ri   r   r   s        rn   r   zQuotedGraph.addt
  sv    1a!T"N1$NN"!T"PQ$PP"!T"M!$MM"

1ay$t4ro   c                P      j                   j                   fd|D                S )r   c              3     K   | ]D  \  }}}}t        |t              r-|j                  j                  u rt        |||      r||||f F y wrq   )rb   rH   rj   r   r   s        rn   r   z#QuotedGraph.addN.<locals>.<genexpr>
  sO      
#
1a![)/Aq!$	 1aL#r   r@  r   s   ` rn   r   zQuotedGraph.addN~
  s)     	

 
#
 	
 ro   c                @    d| j                   j                  |      z  S )r  z{%s}r  r  r  s     rn   r{   zQuotedGraph.n3
  r  ro   c                    | j                   j                         }| j                  j                  j                  }d}|||fz  S )NzK{this rdflib.identifier %s;rdflib:storage [a rdflib:Store;rdfs:label '%s']})rj   r{   ri   rm   r|   )rh   rj   labelr&  s       rn   r}   zQuotedGraph.__str__
  sE    __'')


$$--0 	 *e,,,ro   c                >    t         | j                  | j                  ffS rq   )rH   ri   rj   rr   s    rn   r  zQuotedGraph.__reduce__
  s    TZZ999ro   )ri   r  rj   r  r  r  rq   r  r  r  )r|   r  r  r  r`   r   r   r{   r}   r  r  r  s   @rn   rH   rH   e
  s:    = = A=
P-:ro   rH      c                  8    e Zd ZdZddZd	dZd
dZddZddZy)rI   a.  Wrapper around an RDF Seq resource

    It implements a container type in Python with the order of the items
    returned corresponding to the Seq content. It is based on the natural
    ordering of the predicate names _1, _2, _3, etc, which is the
    'implementation' of a sequence in RDF terms.
    c                2   |  t               x}| _        t        t        t              dz         }|j                  |      D ]E  \  }}|j                  |      st        |j                  |d            }|j                  ||f       G |j                          y)a  Parameters:

        - graph:
            the graph containing the Seq

        - subject:
            the subject of a Seq. Note that the init does not
            check whether this is a Seq, this is done in whoever
            creates this instance!
        _rd  N)r   _listr/   rl  r   r   
startswithr  rM  r  sort)rh   rq  r  r  LI_INDEXr   r   is           rn   r`   zSeq.__init__
  s|     	!V#
#c(S.)++G4DAq||H%		(B/0aV$ 5 	

ro   c                    | S rq   r   rr   s    rn   r   zSeq.toPython
  r   ro   c              #  <   K   | j                   D ]	  \  }}|  yw)z#Generator over the items in the SeqN)r  )rh   r  r   s      rn   r   zSeq.__iter__
  s     zzGAtJ "s   c                ,    t        | j                        S )zLength of the Seq)r  r  rr   s    rn   r   zSeq.__len__
  s    4::ro   c                B    | j                   j                  |      \  }}|S )z Item given by index from the Seq)r  r   )rh   indexr   s      rn   r   zSeq.__getitem__
  s    jj,,U3tro   N)rq  rA   r  r2   )r  rI   )r  r  r  )r  r4   )	r|   r  r  r  r`   r   r   r   r   r   ro   rn   rI   rI   
  s     4
ro   rI   c                      e Zd ZddZddZy)rJ   c                     y rq   r   rr   s    rn   r`   zModificationException.__init__
      ro   c                     	 y)NzZModifications and transactional operations not allowed on ReadOnlyGraphAggregate instancesr   rr   s    rn   r}   zModificationException.__str__
  s    /	
ro   Nr  r  r  r|   r  r  r`   r}   r   ro   rn   rJ   rJ   
  s    
ro   rJ   c                      e Zd ZddZddZy)rK   c                     y rq   r   rr   s    rn   r`   z&UnSupportedAggregateOperation.__init__
  r  ro   c                     y)NzCThis operation is not supported by ReadOnlyGraphAggregate instancesr   rr   s    rn   r}   z%UnSupportedAggregateOperation.__str__
  s    Wro   Nr  r  r  r   ro   rn   rK   rK   
  s    Xro   rK   c                      e Zd ZdZd d! f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)d
Zd(dZe	 	 	 	 d*d       Ze	 	 	 	 d+d       Ze	 	 	 	 d,d       Z	 	 	 	 d,dZd-dZ	 	 	 	 d.dZd/dZd$dZd/dZd0dZd0dZ	 d1	 	 	 	 	 d2dZd3dZd4d5dZ	 d4	 	 	 	 	 	 	 d6dZd7dZd8d9dZ	 	 d:	 	 	 	 	 	 	 	 	 d;dZd1d<dZd$dZ xZ S )=rL   zUtility class for treating a set of graphs as a single graph

    Only read operations are supported (hence the name). Essentially a
    ConjunctiveGraph over an explicit subset of the entire store.
    c                    |0t         t        |   |       t        j                  | |       d | _        t        |t              r#|r!|D cg c]  }t        |t              s| c}sJ d       || _        y c c}w )Nz*graphs argument must be a list of Graphs!!)r_   rL   r`   rA   *_ReadOnlyGraphAggregate__namespace_managerrb   r   r~  )rh   r~  ri   rp  rm   s       rn   r`   zReadOnlyGraphAggregate.__init__
  s{    ($8?NN4''+D$ vt$";FqjE&:F;	8 8		8<  <s   
A6 A6c                2    dt        | j                        z  S )Nz#<ReadOnlyGraphAggregate: %s graphs>)r  r~  rr   s    rn   ry   zReadOnlyGraphAggregate.__repr__
  s    4s4;;7GGGro   c                    t               rq   rJ   r   s     rn   r   zReadOnlyGraphAggregate.destroy      #%%ro   c                    t               rq   r  rr   s    rn   r   zReadOnlyGraphAggregate.commit  r  ro   c                    t               rq   r  rr   s    rn   r   zReadOnlyGraphAggregate.rollback  r  ro   c                L    | j                   D ]  }|j                  | ||        y rq   )r~  r   )rh   r   r   rq  s       rn   r   zReadOnlyGraphAggregate.open  s"    [[E JJt]F3	 !ro   c                F    | j                   D ]  }|j                           y rq   )r~  r   )rh   rq  s     rn   r   zReadOnlyGraphAggregate.close  s    [[EKKM !ro   c                    t               rq   r  r   s     rn   r   zReadOnlyGraphAggregate.add  r  ro   c                    t               rq   r  r   s     rn   r   zReadOnlyGraphAggregate.addN  r  ro   c                    t               rq   r  r   s     rn   r   zReadOnlyGraphAggregate.remove  r  ro   c                     y rq   r   r   s     rn   r   zReadOnlyGraphAggregate.triples#  r   ro   c                     y rq   r   r   s     rn   r   zReadOnlyGraphAggregate.triples)  r   ro   c                     y rq   r   r   s     rn   r   zReadOnlyGraphAggregate.triples/  r   ro   c              #     K   |\  }}}| j                   D ]Y  }t        |t              r#|j                  | ||      D ]  \  }}|||f  6|j	                  |||f      D ]  \  }}}|||f  [ y wrq   )r~  rb   r$   r   r   )	rh   r   r   r   r   rq  rJ  rK  rL  s	            rn   r   zReadOnlyGraphAggregate.triples5  s~      1a[[E!T"FF4A.DAqQ'M / #(--Aq	":JBBb"*$ #; !s   A0A2c                    d }t        |      dk(  r|d   }| j                  D ]'  }||j                  |j                  k(  s|d d |v s' y y)Nr3  r2  TF)r  r~  rj   )rh   r)  r   rq  s       rn   r   z#ReadOnlyGraphAggregate.__contains__B  s[    ~!#$Q'G[[E%"2"2g6H6H"H!"1%. ! ro   c              #  X  K   d}t        |      dk(  r|\  }}}}n|\  }}}|K| j                  D cg c]
  }||k(  s	| c}D ]'  }|j                  |||f      D ]  \  }}	}
||	|
|f  ) y| j                  D ]'  }|j                  |||f      D ]  \  }}	}
||	|
|f  ) yc c}w w)z8Iterate over all the quads in the entire aggregate graphNr3  )r  r~  r   )rh   r)  r   r   r   r   rp  rq  rJ  rK  rL  s              rn   r   zReadOnlyGraphAggregate.quadsN  s      ~!#'JAq!Q %GAq!=%)[[;[AF![;"'--Aq	":JBBb"e++ #; < "'--Aq	":JBBb"e++ #; %	 <s   /B*
B%B% A*B*c                :    t        d | j                  D              S )Nc              3  2   K   | ]  }t        |        y wrq   )r  )r   rp  s     rn   r   z1ReadOnlyGraphAggregate.__len__.<locals>.<genexpr>h  s     /;a3q6;s   )sumr~  rr   s    rn   r   zReadOnlyGraphAggregate.__len__g  s    /4;;///ro   c                    t               rq   rK   rr   s    rn   r   zReadOnlyGraphAggregate.__hash__j      +--ro   c                    |yt        |t              ryt        |t              r3| j                  |j                  kD  | j                  |j                  k  z
  S y)Nr   )rb   rA   rL   r~  r   s     rn   r   zReadOnlyGraphAggregate.__cmp__m  sJ    =u%56KK%,,.4;;3MNNro   c                    t               rq   r  r   s     rn   r   zReadOnlyGraphAggregate.__iadd__w  r  ro   c                    t               rq   r  r   s     rn   r   zReadOnlyGraphAggregate.__isub__z  r  ro   c              #     K   |\  }}}| j                   D ](  }|j                  |||f      }|D ]  \  }}	}
||	|
f  * y wrq   )r~  r  )rh   r   r   r  r  r  rq  choicesr   r   r   s              rn   r  z&ReadOnlyGraphAggregate.triples_choices  sV     
 '-#G[[E ++Wi,IJG"1aAg #	 !r=  c                |    t        | d      r'| j                  r| j                  j                  |      S t               Nrk   )rh  rk   rE  rK   rF  s     rn   rE  zReadOnlyGraphAggregate.qname  s5    4,-$2H2H))//44+--ro   c                ~    t        | d      r(| j                  r| j                  j                  ||      S t               r  )rh  rk   rH  rK   rI  s      rn   rH  z$ReadOnlyGraphAggregate.compute_qname  s7    4,-$2H2H))77XFF+--ro   c                    t               rq   r  )rh   r   rN  rL  s       rn   r   zReadOnlyGraphAggregate.bind  s     ,--ro   c              #     K   t        | d      r)| j                  j                         D ]  \  }}||f  y | j                  D ]   }|j                         D ]  \  }}||f  " y wr  )rh  rk   r   r~  )rh   r   rN  rq  s       rn   r   z!ReadOnlyGraphAggregate.namespaces  sn     4,-%)%;%;%F%F%H!	i'' &I ).)9)9);%FI )++ *< %s   A&A(c                    t               rq   r  rR  s      rn   rQ  z!ReadOnlyGraphAggregate.absolutize  r  ro   c                    t               rq   r  )rh   r}  r~  rW  rY  s        rn   r  zReadOnlyGraphAggregate.parse  s     $%%ro   c                    t               rq   r  r  s     rn   r{   zReadOnlyGraphAggregate.n3  r  ro   c                    t               rq   r  rr   s    rn   r  z!ReadOnlyGraphAggregate.__reduce__  r  ro   r7  )r~  zList[Graph]ri   zUnion[str, Store]r  )r   rl  r  r   )r  r   r  )r   rl  r   rW   r  r  r  )r   rP   r  r   )r   r  r  r   r  r  r  r[  )r)  rT   r  zbGenerator[Tuple[_SubjectType, Union[Path, _PredicateType], _ObjectType, _ContextType], None, None]r  )rh   r@   r   r  r  r   rq   r  r  r   r  )r   r[   rN  r   rL  rW   r  r   r  r  )r   rl  rS  r  r  r   r  )
r}  r  r~  r[   rW  r[   rY  r   r  r   )rk   r  r  r   )!r|   r  r  r  r`   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rE  rH  r   r   rQ  r  r{   r  r  r  s   @rn   rL   rL   
  s   H&&&4&&& 1"1 
,1 1
 5&5 
05 5
 =#= 
8= =
%#% 
8%	,7,
,20.&& +/! ( 
,	.
. GK.#.03.?C.	.
,. #' $	&
	&
  	& 	& 	& 
	&..ro   rL   c                      y rq   r   termss    rn   r   r     s    36ro   c                      y rq   r   r  s    rn   r   r     s    &)ro   c                 H    | D ]  }t        |t              rJ d|d        y)NzTerm r   T)rb   r-   )r  r  s     rn   r   r     s'    !T"K$KK" ro   c                  J    e Zd ZdZd	d
dZddZ	 	 	 	 ddZddZddZddZ	y)rM   a)  
    Wrapper around graph that turns batches of calls to Graph's add
    (and optionally, addN) into calls to batched calls to addN`.

    :Parameters:

      - graph: The graph to wrap
      - batch_size: The maximum number of triples to buffer before passing to
        Graph's addN
      - batch_addn: If True, then even calls to `addN` will be batched according to
        batch_size

    graph: The wrapped graph
    count: The number of triples buffered since initialization or the last call to reset
    batch: The current buffer of triples

    c                    |r|dk  rt        d      || _        |f| _        || _        || _        | j                          y )Nr  z$batch_size must be a positive number)r3  rq  _BatchAddGraph__graph_tuple_BatchAddGraph__batch_size_BatchAddGraph__batch_addnreset)rh   rq  
batch_size
batch_addns       rn   r`   zBatchAddGraph.__init__  sA    Z!^CDD
#X&&

ro   c                "    g | _         d| _        | S )zQ
        Manually clear the buffered triples and reset the count to zero
        r   )batchcountrr   s    rn   r  zBatchAddGraph.reset  s     ')

ro   c                r   t        | j                        | j                  k\  r,| j                  j	                  | j                         g | _        | xj
                  dz  c_        t        |      dk(  r*| j                  j                  || j                  z          | S | j                  j                  |       | S )zV
        Add a triple to the buffer

        :param triple: The triple to add
        r   r2  )r  r  r  rq  r   r  r  r  )rh   r)  s     rn   r   zBatchAddGraph.add  s     tzz?d///JJOODJJ'DJ

a
~!#JJnt/A/AAB  JJn-ro   c                    | j                   r|D ]  }| j                  |        | S | j                  j                  |       | S rq   )r  r   rq  r   )rh   r   qs      rn   r   zBatchAddGraph.addN  s>       JJOOE"ro   c                &    | j                          | S rq   )r  rr   s    rn   	__enter__zBatchAddGraph.__enter__  s    

ro   c                Z    |d   &| j                   j                  | j                         y y )Nr   )rq  r   r  )rh   excs     rn   __exit__zBatchAddGraph.__exit__  s$    q6>JJOODJJ' ro   N)i  F)rq  rA   r  r  r  rW   )r  rM   )r)  zUnion[_TripleType, _QuadType]r  rM   )r   r  r  rM   r  )
r|   r  r  r  r`   r  r   r   r  r  r   ro   rn   rM   rM     s9    $
 
0(ro   rM   )r  r-   r  zte.Literal[True])r  r   r  rW   )zr  
__future__r   loggingrj  r  r  ior   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   urllib.parser   urllib.requestr   rdflib.exceptionsr*  rdflib.namespacerN  rdflib.pluginrc   rdflib.queryr  rdflib.utilr  rdflib.collectionr   r   r   r   r    rdflib.parserr!   r"   r#   rdflib.pathsr$   rdflib.resourcer%   rdflib.serializerr&   rdflib.storer'   rn  r(   r)   r*   r+   r,   r-   r.   r/   typing_extensionsterdflib.plugins.sparql.sparqlr0   r1   r2   r3   r4   r8   r6   rO   r7   rP   rN   r9   r;   r:   r<   rS   rR   r=   r>   rT   r?   rQ   r  r@   rC   rE   rdflib._type_checkingrG   	getLoggerr|   r  __all__rU   rA   r5   rD   ra  rF   rH   term	_ORDERINGrI   r`  rJ   rK   rL   r   rM   r   ro   rn   <module>r     s  wr #          , " ' & $    ( ) = = B B  $ ( 	 	 	 ":' CDQR	$mXn5MM  ""DE #$mX>V5WW  ^h'78(=:QQ  x7x?VVW ^]^  ^]^  !!IJ $%UV ^U+,-] 
 ^U+,-]^  ""LM m;< @A 	$|
h~68M
MN	(<
 $~"68M
MN	(<
 (>":D<M
MNP  )7
+19KL Ky1	 w y9			8	$!H )
yD yx/ B?u B?J ""89 y4 y4x	3:% 3:t &(  k "2 2j
I 
XI XN.- N.b 
 6 
 6 
 ) 
 )J( J(ro   