
    01i                   p   S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
JrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJrJr  SSKJr  SSK J!r!  SSK"J#r#  SSK$J%r%  SSK&J'r'  SSK(J)r)  SSK*r+SSK,J-r-  SS	K"J.r.  SS
K$J/r/J0r0J1r1  SSK2J3r3J4r4J5r5  SSK6J7r7  SSK8J9r9  SSK:J;r;  SSK<J=r=  SSK>J?r?J@r@JArAJBrBJCrCJDrDJErEJFrF  \(       a  SSKGrHSSK(r+SSKIJJrJJKrK  \DrL\DrM\DrN\ArO\S   rP\S   rQ\SSS\S   4   rR\S   rS\SSS\S   4   rT\\S   \S   \S   4   rU\\S   \7\S   4   rV\\S   \S   \S   \S   4   rW\\S   \7\S   \S   4   rX\S   rY\S   rZ\\S   \\S      \S   4   r[\\S   \\S      \S   \S   4   r\\S   r]\S\7S4   r^\S   r_\\\\L   \\M   \\N   4   \\\L   \\M   \\N   4   \\\L   \\M   \\N   4   4   r`\" SS S!9ra\" S"S#S!9rb\" S$S%S!9rc\C(       d   e\0(       d   e\(       a  SS&KdJere  \R                  " \g5      rh/ S'Qri\" S(5      rj " S) S \D5      rk\krl " S* S#\k5      rm\F" S+5      rn " S, S%\m5      ro " S- S.\k5      rpS/\+R                  R                  \p'    " S0 S15      rs " S2 S3\t5      ru " S4 S5\t5      rv " S6 S7\m5      rw\S=S8 j5       rx\S>S9 j5       rxS>S: jrx " S; S<5      ryg)?ak$  
RDFLib defines the following kinds of Graphs:

* [`Graph`][rdflib.graph.Graph]
* [`QuotedGraph`][rdflib.graph.QuotedGraph]
* [`ConjunctiveGraph`][rdflib.graph.ConjunctiveGraph]
* [`Dataset`][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 [`Graph`][rdflib.graph.Graph]

## Conjunctive Graph

!!! warning "Deprecation notice"
    `ConjunctiveGraph` is deprecated, use [`Dataset`][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
[`Store`][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
[`BNode`][rdflib.term.BNode] for an identifier - if one isn't given.

See [`ConjunctiveGraph`][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 [`QuotedGraph`][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 [`Dataset`][rdflib.graph.Dataset]

## Working with graphs

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

```python
>>> 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>:

```python
>>> 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":

```python
>>> 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:

```python
>>> 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 [`triples()`][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.

```python
>>> 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:

```python
>>> 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 [`quads()`][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:

```python
>>> 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:

```python
>>> 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:

```python
>>> 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                    ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S'        S]         S^U 4S
 jjjr\S_S j5       r\S`S j5       r	\SaS j5       r
\
R                  SbS j5       r
ScS jrScS jrSdS jrSeS jrSdS jrSdS jr Sf     SgS jjrSfShS jjrSiS jrSjS jrSkS jr\    SlS j5       r\    SmS j5       r\    SnS j5       r    SnS jrS rSoS jrSpS  jrSqS! jrSoS" jrSoS# jrSrS$ jrSrS% jr SsS& jr!SrS' jr"SsS( jr#StS) jr$StS* jr%SuS+ jr&SuS, jr'SuS- jr(SuS. jr)\&r*\'r+      SvS/ jr,   Sw       SxS0 jjr-   Sw       SyS1 jjr.   Sw       SzS2 jjr/ S{     S|S3 jjr0  S{     S}S4 jjr1 S{     S~S5 jjr2 S     SS6 jjr3\     S           SS7 jj5       r4\     S           SS8 jj5       r4\     S           SS9 jj5       r4\     S           SS: jj5       r4S	\5Rh                  S	S	S;4           SS< jjr4SS= jr6 S     SS> jjr7 S       SS? jjr8 S       SS@ jjr9SSA jr:SSSB jjr;  S         SSC jjr<SSD jr=SSSE jjr>\            SSF j5       r?\   S           SSG jj5       r?\    S           SSH jj5       r?\   S           SSI jj5       r?\    S           SSJ jj5       r?    S             SSK jjr?   S       SSL jjr@      S               SSM jjrA     S               SSN jjrB    S             SSO jjrCSSSP jjrDSSQ jrESsSR jrFSrSS jrGSST jrHSSU jrISSV jrJ      SSW jrK    S         SSX jjrL S     SSY jjrMS	S;SZ.       SS[ jjrNS\rOU =rP$ )rA   i  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
in all uses of RDFLib.

Example:
    The basic use is to create a Graph and iterate through or query its content:

    ```python
    >>> 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")
    ... )

    ```


Args:
    store: 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.
        All [builtin storetypes][rdflib.plugins.stores] can be accessed via
        their registered names.
        Other Stores not shipped with RDFLib can be added as plugins, such as
        [HDT](https://github.com/rdflib/rdflib-hdt/).
        Registration of external plugins
        is described in [`rdflib.plugin`][rdflib.plugin].

        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/>.
    identifier: identifier of the graph itself
    namespace_manager: Used namespace manager.
        Create with bind_namespaces if `None`.
    base: Base used for [URIs][rdflib.term.URIRef]
    bind_namespaces: Used bind_namespaces for namespace_manager
        Is only used, when no namespace_manager is provided.
boolcontext_awareformula_awaredefault_unionOptional[str]baseNc                  > [         [        U ]  5         X@l        U   U=(       d
    [	        5       U l        [        U R
                  [        5      (       d  [        U R
                  5      U l        U   [        U[        5      (       d(  [        R                  " U[        5      " 5       =U l        nOXl        X0l        XPl        SU l        SU l        SU l        g 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         F/home/james-whalen/.local/lib/python3.13/site-packages/rdflib/graph.pyr`   Graph.__init__  s     	eT#%	&1%'$++^<< &t'8'8 9D%''#)::eU#;#==DL5 L#4  /"""    c                    U R                   $ N)re   rh   s    rn   ri   Graph.store"  s    ||rp   c                    U R                   $ rr   )ra   rs   s    rn   rj   Graph.identifier&  s       rp   c                h    U R                   c  [        X R                  5      U l         U R                   $ )z 
this graph's namespace-manager
)rf   r    rg   rs   s    rn   rk   Graph.namespace_manager*  s/    
 ##+'7>S>S'TD$'''rp   c                    Xl         g rr   )rf   )rh   nms     rn   rk   rx   3  s    #% rp   c                >    SU R                   < S[        U 5      < S3$ )Nz<Graph identifier=z (z)>)rj   typers   s    rn   __repr__Graph.__repr__7  s    /3T
KKrp   c                   [        U R                  [        5      (       a@  U R                  R                  5       < SU R                  R
                  R                  < S3$ SU R                  R
                  R                  -  $ )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__rs   s    rn   __str__Graph.__str__:  sf    doov.. ##%tzz';';'D'DF F
 W

$$--. .rp   c                    U $ rr    rs   s    rn   toPythonGraph.toPythonD      rp   c                <    U R                   R                  U5        U $ )z<Destroy the store identified by `configuration` if supported)re   destroyrh   configurations     rn   r   Graph.destroyG  s    ]+rp   c                :    U R                   R                  5         U $ )zCommits active transactions)re   commitrs   s    rn   r   Graph.commitM  s    rp   c                :    U R                   R                  5         U $ )zRollback active transactions)re   rollbackrs   s    rn   r   Graph.rollbackR  s    rp   c                8    U R                   R                  X5      $ )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   
Graph.openW  s     ||  77rp   c                4    U R                   R                  US9$ )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   Graph.closea  s     ||!!=W!XXrp   c                   Uu  p#n[        U[        5      (       d   SU< S35       e[        U[        5      (       d   SU< S35       e[        U[        5      (       d   SU< S35       eU R                  R                  X#U4U SS9  U $ )zxAdd a triple with self as context.

Args:
    triple: The triple to add to the graph.

Returns:
    The graph instance.
Subject  must be an rdflib term
Predicate Object Fquoted)rb   r-   re   addrh   triplespos        rn   r   	Graph.addi  s     a!T""N1$NN"!T""PQ$PP"!T""M!$MM"!D7rp   c                R   ^  T R                   R                  U 4S jU 5       5        T $ )%Add a sequence of triple with contextc              3     >#    U  HQ  u  pp4[        U[        5      (       d  M  UR                  TR                  L d  M8  [        XU5      (       d  MK  XX44v   MS     g 7frr   )rb   rA   rj   _assertnode.0r   r   r   crh   s        rn   	<genexpr>Graph.addN.<locals>.<genexpr>|  sT      
#
a!U#  /  A!$	 Q1L#   AAAA)re   addNrh   quadss   ` rn   r   
Graph.addNy  s+     	 
#
 	
 rp   c                8    U R                   R                  XS9  U $ )zzRemove 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   Graph.remove  s     	F1rp   c                    g rr   r   r   s     rn   triplesGraph.triples       .1rp   c                    g rr   r   r   s     rn   r   r          25rp   c                    g rr   r   r   s     rn   r   r          :=rp   c              #     #    Uu  p#n[        U[        5      (       a"  UR                  XU5       H  u  pVXSU4v   M     gU R                  R	                  X#U4U S9 H  u  u  pWphXWU4v   M     g7f)av  Generator over the triple store.

Returns triples that match the given triple pattern. If the triple pattern
does not provide a context, all contexts will be searched.

Args:
    triple: A triple pattern where each component can be a specific value or None
        as a wildcard. The predicate can also be a path expression.

Yields:
    Triples matching the given pattern.
r   N)rb   r$   evalre   r   )	rh   r   r   r   r   _s_o_pcgs	            rn   r   r     ss       aa&&!,Ri - %)LL$8$8!D$8$Q bj  %Rs   A,A.c                (   [        U[        5      (       a  UR                  UR                  UR                  pCnUc  Uc  Uc  U R                  X#U45      $ Uc  Uc  U R                  U5      $ Uc  Uc  U R                  U5      $ Uc  Uc  U R                  U5      $ Uc  U R                  X45      $ Uc  U R                  X$5      $ Uc  U R                  X#5      $ X#U4U ;   $ [        U[        [        45      (       a  U R                  U5      $ [        S5      e)a  
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

```python
>>> 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.

!!! example "New in version 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__Graph.__getitem__  s   F dE""jj$))TYY!AyQY19||Q1I..qy..q11qy++A..qy--a00 }}Q** q,, ||A)) ayD((tTl++))$// i rp   c                4    U R                   R                  U S9$ )zReturns the number of triples in the graph.

If context is specified then the number of triples in the context is
returned instead.

Returns:
    The number of triples in the graph.
r   )re   __len__rs   s    rn   r   Graph.__len__  s     ||##D#11rp   c                $    U R                  S5      $ )zeIterates over all triples in the store.

Returns:
    A generator yielding all triples in the store.
NNNr   rs   s    rn   __iter__Graph.__iter__  s     ||.//rp   c                4    U R                  U5       H  n  g   g)zSupport for 'triple in graph' syntax.

Args:
    triple: The triple pattern to check for.

Returns:
    True if the triple pattern exists in the graph, False otherwise.
TFr   r   s     rn   __contains__Graph.__contains__  s     ll6*F +rp   c                ,    [        U R                  5      $ rr   )hashrj   rs   s    rn   __hash__Graph.__hash__#  s    DOO$$rp   c                    Uc  g[        U[        5      (       a3  U R                  UR                  :  U R                  UR                  :  -
  $ g)N   rb   rA   rj   rh   others     rn   __cmp__Graph.__cmp__&  sJ    =u%%OOe&6&66%"2"22  rp   c                b    [        U[        5      =(       a    U R                  UR                  :H  $ rr   r   r   s     rn   __eq__Graph.__eq__3  s#    %'ODOOu?O?O,OOrp   c                x    US L =(       d0    [        U[        5      =(       a    U R                  UR                  :  $ rr   r   r   s     rn   __lt__Graph.__lt__6  s1     
ue$K5;K;K)K	
rp   c                     X:  =(       d    X:H  $ rr   r   r   s     rn   __le__Graph.__le__;      |,t},rp   c                x    [        U[        5      =(       a    U R                  UR                  :  =(       d    US L$ rr   r   r   s     rn   __gt__Graph.__gt__>  s2    5%(OT__u?O?O-O 
	
rp   c                     X:  =(       d    X:H  $ rr   r   r   s     rn   __ge__Graph.__ge__C  r   rp   c                >   ^  T R                  U 4S jU 5       5        T $ )zCAdd all triples in Graph other to Graph.
BNode IDs are not changed.c              3  2   >#    U  H  u  po1X#T4v   M     g 7frr   r   )r   r   r   r   rh   s       rn   r   !Graph.__iadd__.<locals>.<genexpr>I  s     7gaAaD/s   r   r   s   ` rn   __iadd__Graph.__iadd__F  s     			777rp   c                :    U H  nU R                  U5        M     U $ )zJSubtract all triples in Graph other from Graph.
BNode IDs are not changed.)r   )rh   r   r   s      rn   __isub__Graph.__isub__L  s     FKK rp   c                p    [        U 5      " 5       n[        [	        U R                  5       5      [	        UR                  5       5      -   5       H  u  p4UR                  X45        M     U  H  nUR                  U5        M     U H  nUR                  U5        M     U$ ! [         a    [        5       n Nf = f)z.Set-theoretic union
BNode IDs are not changed.)r|   r   rA   setlist
namespacesbindr   )rh   r   retvalprefixurixys          rn   __add__Graph.__add__S  s    	$Z\F tDOO$56e>N>N>P9QQRKFKK$ SAJJqM AJJqM   	WF	s   B B54B5c                     [        U 5      " 5       nU H  nX0;   d  M
  UR                  U5        M     U$ ! [         a    [        5       n N9f = f)z6Set-theoretic intersection.
BNode IDs are not changed.r|   r   rA   r   rh   r   r  r  s       rn   __mul__Graph.__mul__b  sM    	$Z\F Ay

1    	WF	   5 AAc                     [        U 5      " 5       nU  H  nX1;  d  M
  UR                  U5        M     U$ ! [         a    [        5       n N9f = f)z4Set-theoretic difference.
BNode IDs are not changed.r  r  s       rn   __sub__Graph.__sub__n  sM    	$Z\F A~

1    	WF	r  c                    X-
  X-
  -   $ )z-Set-theoretic XOR.
BNode IDs are not changed.r   r   s     rn   __xor__Graph.__xor__z  s     ..rp   c                    Uu  p#nUc   S5       eUc   S5       eU R                  X#S45        U R                  X#U45        U $ )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  	Graph.set  sg     )/%W	LK	L !	LK	L!W./'g./rp   c              #    #    [        U[        5      (       a'  U H   nU R                  XU5       H  nUv   M	     M"     gU(       d"  U R                  SX45       H
  u  pVnUv   M     g[	        5       nU R                  SX45       H#  u  pVnXX;  d  M  Uv    UR                  U5        M%     g! [         a  n	[        R                  U	 S35        e Sn	A	ff = f7f)a/  A generator of (optionally unique) subjects with the given
predicate and object(s)

Args:
    predicate: A specific predicate to match or None to match any predicate.
    object: A specific object or list of objects to match or None to match any object.
    unique: If True, only yield unique subjects.
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   Graph.subjects  s      fd##yv>AG ?  #||T9,EFGA!G  G u#||T9,EFGA!}" HHQK	  G
  + ""LL#$#%V W "	"0   BCCB-(C-
C7CCCc              #  @  #    U(       d#  U R                  USU45       H
  u  pEnUv   M     g[        5       nU R                  USU45       H#  u  pEnXW;  d  M  Uv    UR                  U5        M%     g! [         a  n[        R                  U S35        e SnAff = f7f)a;  Generate predicates with the given subject and object.

Args:
    subject: A specific subject to match or None to match any subject.
    object: A specific object to match or None to match any object.
    unique: If True, only yield unique predicates.

Yields:
    Predicates matching the given subject and object.
Nr)  r   r  r   r*  r+  r,  )	rh   r$  r-  r.  r   r   r   predsr1  s	            rn   r   Graph.predicates  s       <<$(?@a A EE<<$(?@a>G		!	 A
 '  c!RS 	s0   ABBA3.B3
B=BBBc              #    #    [        U[        5      (       a'  U H   nU R                  XBU5       H  nUv   M	     M"     gU(       d"  U R                  XS45       H
  u  pgnUv   M     g[	        5       nU R                  XS45       H#  u  pgnXX;  d  M  Uv    UR                  U5        M%     g! [         a  n	[        R                  U	 S35        e Sn	A	ff = f7f)as  A generator of (optionally unique) objects with the given
subject(s) and predicate

Args:
    subject: A specific subject or a list of subjects to match or None to match any subject.
    predicate: A specific predicate to match or None to match any predicate.
    unique: If True, only yield unique objects.

Yields:
    Objects matching the given subject and predicate.
Nr)  )	rb   r  r   r   r  r   r*  r+  r,  )
rh   r$  r%  r.  subjr   r   r   objsr1  s
             rn   r   Graph.objects  s     " gt$$dv>AG ?   #||W,FGGA!G  H u#||W,FGGA!}" HHQK	  H
  + ""LL#$#%V W "	"r3  c              #  J  #    U(       d$  U R                  SSU45       H  u  p4nX44v   M     g[        5       nU R                  SSU45       H'  u  p4nX44U;  d  M  X44v    UR                  X445        M)     g! [         a  n[        R                  U S35        e SnAff = f7f)zSA generator of (optionally unique) (subject, predicate) tuples
for the given objectNr)  r5  )rh   r-  r.  r   r   r   
subj_predsr1  s           rn   r   Graph.subject_predicates  s     
 <<tV(<=ad
 > J<<tV(<=a6+$J"v.	 >
 '  c!RS 	0   AB#B#!A83B#8
B BB  B#c              #  J  #    U(       d$  U R                  SUS45       H  u  p4nX54v   M     g[        5       nU R                  SUS45       H'  u  p4nX54U;  d  M  X54v    UR                  X545        M)     g! [         a  n[        R                  U S35        e SnAff = f7f)zSA generator of (optionally unique) (subject, object) tuples
for the given predicateNr)  r5  )rh   r%  r.  r   r   r   	subj_objsr1  s           rn   r   Graph.subject_objects  s      <<y$(?@ad
 A I<<y$(?@a6*$J!qf-	 A
 '  c!RS 	r?  c              #  J  #    U(       d$  U R                  USS45       H  u  p4nXE4v   M     g[        5       nU R                  USS45       H'  u  p4nXE4U;  d  M  XE4v    UR                  XE45        M)     g! [         a  n[        R                  U S35        e SnAff = f7f)zSA generator of (optionally unique) (predicate, object) tuples
for the given subjectNr)  r5  )rh   r$  r.  r   r   r   	pred_objsr1  s           rn   r   Graph.predicate_objects-  s     
 <<$(=>ad
 ? I<<$(=>a6*$J!qf-	 ?
 '  c!RS 	r?  c              #  r   #    Uu  p4nU R                   R                  X4U4U S9 H  u  u  pgpXgU4v   M     g 7f)Nr   )ri   triples_choices)
rh   r   r   r$  r%  r&  r   r   r   r   s
             rn   rG  Graph.triples_choicesB  sL     
 '-#G "ZZ77)4 8 
MIQ1 'M
s   57c                    g rr   r   rh   r$  r%  r-  defaultanys         rn   valueGraph.valueO       rp   c                    g rr   r   rJ  s         rn   rM  rN  Y  rO  rp   c                    g rr   r   rJ  s         rn   rM  rN  c  rO  rp   c                    g rr   r   rJ  s         rn   rM  rN  m  s     rp   Tc                   UnUc  Ub  Uc  Ub  Uc  Uc  gUc  U R                  X5      nUc  U R                  X#5      nUc  U R                  X5      n [        W5      nUSL a|   [        U5        SU< SU< SU< S3nU R                  R                  XU4S5      n	U	 H'  u  u  ppUSU
< SU< SU< S[        U5      < S3	-  nM)     [        R                  " U5      e U$ ! [         a     U$ f = f! [         a    Un U$ f = f)	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

Args:
    subject: Subject of the triple pattern, exactly one of subject, predicate, object must be None
    predicate: Predicate of the triple pattern, exactly one of subject, predicate, object must be None
    object: Object of the triple pattern, exactly one of subject, predicate, object 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-  rK  rL  r  valuesmsgr   r   r   r   contextss                 rn   rM  rN  w  s<   .  _!2FN!fn>\\'5F?]]95F__W5F	&\F e|L #Iv7 
 #jj00'f1MtTG/6+	q N	   07 %44S99! &  % )  	F* -	s%   C3 $A;C" "
C0/C03DDc              #    #    [        U/5      nU(       ar  U R                  U[        R                  5      nUb  Uv   U R                  U[        R                  5      nX;   a  [        S5      eUR                  U5        U(       a  Mq  gg7f)z_Generator over all items in the resource specified by list

Args:
    list: An RDF collection.
Nz,List contains a recursive rdf:rest reference)r  rM  r   firstrest
ValueErrorr   )rh   r  chainr   s       rn   itemsGraph.items  sk      TF::dCII.D
::dCHH-D} !OPPIIdO ds   BB	B	c              #     #    Uc  0 nOX#;   a  gSX2'   U" X 5       H$  nUv   U R                  XU5       H  nUv   M	     M&     g7f)a~  Generates transitive closure of a user-defined function against the graph

```python
from rdflib.collection import Collection
g = Graph()
a = BNode("foo")
b = BNode("bar")
c = BNode("baz")
g.add((a,RDF.first,RDF.type))
g.add((a,RDF.rest,b))
g.add((b,RDF.first,namespace.RDFS.label))
g.add((b,RDF.rest,c))
g.add((c,RDF.first,namespace.RDFS.comment))
g.add((c,RDF.rest,RDF.nil))
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)]
# [rdflib.term.BNode('baz'),
#  rdflib.term.BNode('bar'),
#  rdflib.term.BNode('foo')]

[rt for rt in g.transitiveClosure(
    reverseList,RDF.nil)]
# 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')]
```

Args:
    func: A function that generates a sequence of nodes
    arg: The starting node
    seen: A dict of visited nodes
Nr   )transitiveClosure)rh   funcargseenrtrt_2s         rn   rd  Graph.transitiveClosure  sP     d <D[	s/BH..t>
 ? "s   AAc              #     #    Uc  0 nX;   a  gSX1'   Uv   U R                  X5       H   nU R                  XBU5       H  nUv   M	     M"     g7f)aJ  Transitively generate objects for the ``predicate`` relationship

Generated objects belong to the depth first transitive closure of the
`predicate` relationship starting at `subject`.

Args:
    subject: The subject to start the transitive closure from
    predicate: The predicate to follow
    remember: A dict of visited nodes
Nr   )r   transitive_objects)rh   r$  r%  rememberr-  r   s         rn   rl  Graph.transitive_objects  sX       Hll76F,,VI J 7   A
Ac              #     #    Uc  0 nX#;   a  gSX2'   Uv   U R                  X5       H   nU R                  XU5       H  nUv   M	     M"     g7f)aI  Transitively generate subjects for the ``predicate`` relationship

Generated subjects belong to the depth first transitive closure of the
`predicate` relationship starting at `object`.

Args:
    predicate: The predicate to follow
    object: The object to start the transitive closure from
    remember: A dict of visited nodes
Nr   )r   transitive_subjects)rh   r%  r-  rm  r$  r   s         rn   rq  Graph.transitive_subjects  sX       H}}Y7G--i(K L 8ro  c                8    U R                   R                  U5      $ rr   )rk   qnamerh   r  s     rn   rt  Graph.qname9  s    %%++C00rp   c                8    U R                   R                  X5      $ rr   )rk   compute_qnamerh   r  generates      rn   rx  Graph.compute_qname<  s    %%33CBBrp   c                6    U R                   R                  XX4S9$ )a  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

Args:
    prefix: The prefix to bind
    namespace: The namespace to bind the prefix to
    override: If True, override any existing prefix binding
    replace: If True, replace any existing namespace binding

Example:
    ```python
    graph.bind("foaf", "http://xmlns.com/foaf/0.1/")
    ```
)overridereplace)rk   r  )rh   r  	namespacer}  r~  s        rn   r  
Graph.bind?  s(    @ %%** + 
 	
rp   c              #  \   #    U R                   R                  5        H
  u  pX4v   M     g7f)zjGenerator over all the prefix, namespace tuples

Returns:
    Generator yielding prefix, namespace tuples
N)rk   r  )rh   r  r  s      rn   r  Graph.namespacesc  s-      "&!7!7!B!B!DF## "Es   *,c                8    U R                   R                  X5      $ )z5Turn uri into an absolute URI if it's not one already)rk   
absolutizerh   r  defrags      rn   r  Graph.absolutizel  s    %%00==rp   c                    g rr   r   rh   destinationformatr\   encodingargss         rn   	serializeGraph.serializeq       rp   c                   g rr   r   r  s         rn   r  r  |       rp   c                    g rr   r   r  s         rn   r  r         rp   c                    g rr   r   r  s         rn   r  r    r  rp   c                    g rr   r   r  s         rn   r  r         $'rp   c                   Uc  U R                   n[        R                  " U[        5      " U 5      nUcg  [	        5       nUc5  UR
                  " U4USS.UD6  UR                  5       R                  S5      $ UR
                  " U4X4S.UD6  UR                  5       $ [        US5      (       a.  [        [        [           U5      nUR
                  " U4X4S.UD6  U $ [        U[        R                  5      (       a  [        U5      nOI[        [        U5      n	[!        U	5      u  pppU
S:X  a"  US:w  a  [#        SU	< S35      e[%        U5      nOU	n['        US	5       nUR
                  " U4X4S.UD6  SSS5        U $ ! , (       d  f       U $ = f)
a=  Serialize the graph.

Args:
    destination: The destination to serialize the graph to. This can be a path as a
        string or pathlib.PurePath object, or it can be an IO[bytes] like object.
        If this parameter is not supplied the serialized graph will be returned.
    format: The format that the output should be written in. This value
        references a Serializer plugin.
        Format support is managed with [plugins][rdflib.plugin].
        Defaults to "turtle" and some other formats are builtin,
        like "xml" and "trix".
        See also [serialize module][rdflib.plugins.parsers].
    base: The base IRI for formats that support it. For the turtle format this
        will be used as the @base directive.
    encoding: Encoding of output.
    args: Additional arguments to pass to the Serializer that will be used.

Returns:
    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.

    self (i.e. the Graph instance) if `destination` is not None.
Nutf-8)r\   r  writefile zthe file URI z2 has an authority component which is not supportedwb)r\   rc   rd   r&   r   r  getvaluedecodehasattrr   r   bytesrb   pathlibPurePathstrr   r_  r   r   )rh   r  r  r\   r  r  
serializerstreamos_pathlocationschemenetlocpathparams_queryfragments                   rn   r  r    s   B <99DZZ
3D9
YF$$VQ$QDQ(//88$$VR$RTR((;(("U)[1F  NdNN"  +w'7'788k*[1AI(AS>fV#|(+H<7ij  +40G&Ggt$$$VR$RTR % %$s   E::
F	c                T    [        U R                  S XS9R                  U5      USS9  g )N)r  r  T)r  flush)printr  r  )rh   r  r  outs       rn   r  Graph.print  s-     	NN4NBII(S	
rp   c           	        [        UUUUUUS9nUc  UR                  nSnUc  [        US5      (       ax  [        UR                  SS5      (       a\  [        UR                  R                  [        5      (       a3  [        R                  R                  UR                  R                  5      nUc  SnSn [        R                  " U[        5      " 5       n	 U	R                   " X40 UD6   UR&                  (       a  UR)                  5         U $ ! [        R                   af    [        R                  R                  [        U[        5      (       d  UO
[        U5      5      nUc  e [        R                  " U[        5      " 5       n	 Nf = f! ["         a  n
U(       a  [%        SU-  5      eU
eSn
A
ff = f! UR&                  (       a  UR)                  5         f f = f)	a  Parse an RDF source adding the resulting triples to the Graph.

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

Args:
    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.
    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.
    format: Used if format can not be determined from source, e.g.
        file extension or Media Type. Format support is managed
        with [plugins][rdflib.plugin].
        Available formats are e.g. "turle", "xml", "n3", "nt" and "trix"
        or see [parser module][rdflib.plugins.parsers].
    location: A string indicating the relative or absolute URL of the
        source. `Graph`'s absolutize method is used if a relative location
        is specified.
    file: A file-like object.
    data: A string containing the data to be parsed.
    args: Additional arguments to pass to the parser.

Returns:
    self, i.e. the Graph instance.

Example:
    ```python
    >>> 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

    ```

!!! warning "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
    [Security Considerations](../security_considerations.md)
    documentation.
sourcepublicIDr  r  datar  NFr  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_typer  getattrr  rb   r  r  rdflibutilguess_formatrc   rd   r"   PluginExceptionr!   parseSyntaxErrorr   
auto_closer   )rh   r  r  r  r  r  r  r  could_not_guess_formatparserses              rn   r  Graph.parse  s   D %
 >((F!&>''FKK66v{{//5511&++2B2BC~!)-&	2ZZ/1F	LL..   3 %% 		2 [[--(==3v;F ~ZZ/1F		2  	%!S  	    !s7   4 D F	 A7FF	
F/F**F//F2 2$Gc                   U=(       d    0 nU=(       d    [        U R                  5       5      nU R                  (       a  SnO8[        U [        5      (       a  U R
                  R                  nOU R                  n[        U R                  S5      (       a(  U(       a!   U R                  R                  " UUUU40 UD6$ [        U[        R                  5      (       d3  [        R                  " [        [        U5      [        R                  5      n[        U[        R                   5      (       d+  [        R                  " U[        R                   5      " U 5      nU" UR                  " XU40 UD65      $ ! [         a     Nf = f)a  
Query this graph.

Args:
    query_object: The query string or object to execute.
    processor: The query processor to use. Default is "sparql".
    result: The result format to use. Default is "sparql".
    initNs: Initial namespaces to use for resolving prefixes in the query.
        If none are given, the namespaces from the graph's namespace manager are used.
    initBindings: Initial variable bindings to use. A type of 'prepared queries'
        can be realized by providing these bindings.
    use_store_provided: Whether to use the store's query method if available.
    kwargs: Additional arguments to pass to the query processor.

Returns:
    A [`rdflib.query.Result`][`rdflib.query.Result`] instance.

!!! warning "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
    [Security Considerations](../security_considerations.md)
    documentation.
	__UNION__query)dictr  rZ   rb   rD   default_contextrj   r  ri   r  NotImplementedErrorResultrc   rd   r   r  	Processor)	rh   query_object	processorresultinitNsinitBindingsuse_store_providedkwargsquery_graphs	            rn   r  Graph.query  s*   P $)r24 12%K.//..99K//K4::w'',>	zz''  	
   &%,,//ZZS& 15<<@F)U__55

9eoo>tDI iool&SFSTT ' s   E3 3
F ?F c                V   U=(       d    0 nU=(       d    [        U R                  5       5      nU R                  (       a  SnO8[        U [        5      (       a  U R
                  R                  nOU R                  n[        U R                  S5      (       a(  U(       a!   U R                  R                  " UUUU40 UD6$ [        U[        R                  5      (       d+  [        R                  " U[        R                  5      " U 5      nUR                  " XU40 UD6$ ! [         a     Njf = f)a  Update this graph with the given update query.

Args:
    update_object: The update query string or object to execute.
    processor: The update processor to use. Default is "sparql".
    initNs: Initial namespaces to use for resolving prefixes in the query.
        If none are given, the namespaces from the graph's namespace manager are used.
    initBindings: Initial variable bindings to use.
    use_store_provided: Whether to use the store's update method if available.
    kwargs: Additional arguments to pass to the update processor.

!!! warning "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
    Security Considerations documentation.
r  update)r  r  rZ   rb   rD   r  rj   r  ri   r  r  r  UpdateProcessorrc   rd   )rh   update_objectr  r  r  r  r  r  s           rn   r  Graph.update  s    > $)r24 12%K.//..99K//K4::x((-?	zz((! 	
   )U%:%:;;

9e.C.CDTJIVNvNN ' s   D 
D('D(c                :    SU R                   R                  US9-  $ )%Return an n3 identifier for the Graphz[%s]rk   rj   r   rh   rk   s     rn   r   Graph.n3
       **=N*OOOrp   c                >    [         U R                  U R                  44$ rr   )rA   ri   rj   rs   s    rn   
__reduce__Graph.__reduce__  s"    


 	
rp   c                F   [        U 5      [        U5      :w  a  gU  H>  u  p#n[        U[        5      (       a  M  [        U[        5      (       a  M4  X#U4U;  d  M>    g   U H>  u  p#n[        U[        5      (       a  M  [        U[        5      (       a  M4  X#U4U ;  d  M>    g   g)a{  Check if this graph is isomorphic to another graph.

Performs a basic check if these graphs are the same.
If no BNodes are involved, this is accurate.

Args:
    other: The graph to compare with.

Returns:
    True if the graphs are isomorphic, False otherwise.

Note:
    This is only an approximation. See rdflib.compare for a correct
    implementation of isomorphism checks.
FT)lenrb   r(   )rh   r   r   r   r   s        rn   
isomorphicGraph.isomorphic  s    " t9E
"GA!a''
1e0D0DayE)   GA!a''
1e0D0DayD(  
 rp   c                   [        U R                  5       5      n/ nU(       d  gU[        R                  " [	        U5      5         /nU(       a  UR                  5       nXB;  a  UR                  U5        U R                  US9 H"  nXR;  d  M
  XS;  d  M  UR                  U5        M$     U R                  US9 H"  nXR;  d  M
  XS;  d  M  UR                  U5        M$     U(       a  M  [	        U5      [	        U5      :X  a  gg)ad  Check if the Graph is connected.

The Graph is considered undirectional.

Returns:
    True if all nodes have been visited and there are no unvisited nodes left,
    False otherwise.

Note:
    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.
F)r$  )r-  T)	r  	all_nodesrandom	randranger  popappendr   r   )rh   r  
discoveredvisitingr  new_xs         rn   	connectedGraph.connected5  s     )*	
 f..s9~>?@A"!!!$a0*u/DOOE* 1 a0*u/DOOE* 1 h y>S_,rp   c                v    [        U R                  5       5      nUR                  U R                  5       5        U$ rr   )r  r   r  r   )rh   ress     rn   r  Graph.all_nodes^  s)    $,,.!

4==?#
rp   c                    [        X5      $ )a  Create a new `Collection` instance.

Args:
    identifier: A URIRef or BNode instance.

Returns:
    A new Collection instance.

Example:
    ```python
    >>> 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   
collectionGraph.collectionc  s    , $++rp   c                X    [        U[        5      (       d  [        U5      n[        X5      $ )a  Create a new ``Resource`` instance.

Args:
    identifier: A URIRef or BNode instance.

Returns:
    A new Resource instance.

Example:
    ```python
    >>> 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   resourceGraph.resource{  s&    ( *d++
+J))rp   c                b    U R                  S5       H  nUR                  U" U5      5        M     g )Nr   )r   r   )rh   targetre  ts       rn   _process_skolem_tuplesGraph._process_skolem_tuples  s(     01AJJtAw 2rp   c                   ^^^^ SUU4S jjmSUU4S jjnUc
  [        5       OUnTc  U R                  Xe5        U$ [        T[        5      (       a  U R                  UUU4S j5        U$ )Nc                   > Uu  p#nX :X  a2  [         (       a  [        U[        5      (       d   eUR                  TTS9nX@:X  a2  [         (       a  [        U[        5      (       d   eUR                  TTS9nX#U4$ N)	authoritybasepath)r   rb   r(   	skolemize)bnoder  r   r   r   r	  r
  s        rn   do_skolemize%Graph.skolemize.<locals>.do_skolemize  ss    IQ1z =%a////KK)hKGz =%a////KK)hKG7Nrp   c                   > U u  pn[        U[        5      (       a  UR                  TTS9n[        U[        5      (       a  UR                  TTS9nXU4$ r  )rb   r(   r  )r  r   r   r   r	  r
  s       rn   do_skolemize2&Graph.skolemize.<locals>.do_skolemize2  sS    IQ1!U##KK)hKG!U##KK)hKG7Nrp   c                   > T" TU 5      $ rr   r   )r  r  r  s    rn   <lambda>!Graph.skolemize.<locals>.<lambda>  s    ,ua:Prp   )r  r(   r  r6   returnr6   r  r6   r  r6   )rA   r  rb   r(   )rh   	new_graphr  r	  r
  r  r  r  s     ```  @rn   r  Graph.skolemize  sf    
	 
		 	 &-9=''>
 	 u%%''0PQrp   c                   ^^ SS jmSS jnUc
  [        5       OUnTc  U R                  XC5        U$ [        T[        5      (       a  U R                  UUU4S j5        U$ )Nc                    Uu  p#nX :X  a2  [         (       a  [        U[        5      (       d   eUR                  5       nX@:X  a2  [         (       a  [        U[        5      (       d   eUR                  5       nX#U4$ rr   )r   rb   r/   de_skolemize)urirefr  r   r   r   s        rn   do_de_skolemize+Graph.de_skolemize.<locals>.do_de_skolemize  sf    IQ1{ =%a0000NN${ =%a0000NN$7Nrp   c                   U u  pn[         R                  " U5      (       a  [        U5      R                  5       nO4[        R                  " U5      (       a  [        U5      R                  5       n[        U[        5      (       ai  [         R                  " U5      (       a  [        U5      R                  5       nO4[        R                  " U5      (       a  [        U5      R                  5       nXU4$ rr   )r.   _is_rdflib_skolemr  r)   _is_external_skolemrb   r/   )r  r   r   r   s       rn   do_de_skolemize2,Graph.de_skolemize.<locals>.do_de_skolemize2  s    IQ1,,Q//N//1**1--!H))+!V$$0033#A335A..q11a--/A7Nrp   c                   > T" TU 5      $ rr   r   )r  r  r  s    rn   r  $Graph.de_skolemize.<locals>.<lambda>  s    /&RS:Trp   )r  r/   r  r6   r  r6   r  )rA   r  rb   r)   )rh   r  r  r"  r  r  s     `  @rn   r  Graph.de_skolemize  s\    
		$ &-9>''A
 	 &&''0TUrp   )target_graphinclude_reificationsc               T   ^ ^^^ Uc  [        5       mOUmSUUU U4S jjmT" U5        T$ )aa  Retrieves the Concise Bounded Description of a Resource from a Graph.

Args:
    resource: A URIRef object, the Resource to query for.
    target_graph: Optionally, a graph to add the CBD to; otherwise,
        a new graph is created for the CBD.
    include_reifications: If False, skip Rule 3 to exclude reified statements (default: True)

Returns:
    A Graph, subgraph of self if no graph was provided otherwise the provided graph.

Note:
    Concise Bounded Description (CBD) is defined 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.

    If include_reifications is set to False, Rule 3 above will be skipped, meaning reified statements
    will not be included in the CBD. This can improve performance when reified statements are not present
    or can be used to deliberately exclude them from the result.
c                j  > T	(       a  0 nT
R                  [        R                  U 5       Hp  nT
R                  U[        R                  5      nT
R                  U[        R
                  5      nUc  MH  Uc  MM  XU4nXQ;  a  U1X'   M]  X   R                  U5        Mr     T
R                  U S S 45       H}  u  pcnTR                  XcU45        [        U5      [        L a  US S 4T;  a  T" U5        T	(       d  ME  WR                  XcU4[        5       5      nU H  nUS S 4T;  d  M  T" U5        M     M     g rr   )r   r   r$  rM  r%  r-  r   r   r|   r(   rd   r  )r  
reif_indexstmtr   r   r   r   stmts
add_to_cbdr(  rh   subgraphs           rn   r.  Graph.cbd.<locals>.add_to_cbd  s    $CE
 MM#++s;D(,

4(GA

44A}"%!!326J.&.2248 <  <<dD(9:aaAY'7e#D$x(GqM ('&NNA!9ce<E % $-X=&t, !& ;rp   )r  r2   r  None)rA   )rh   r  r'  r(  r.  r/  s   `  `@@rn   cbd	Graph.cbd  s2    Z wH#H	- 	-B 	8rp   )__identifier__namespace_manager__storerg   r\   rX   rZ   rY   )rK  NNNr  )
ri   Union[Store, str]rj   ,Optional[Union[_ContextIdentifierType, str]]rk   Optional[NamespaceManager]r\   r[   rl   rG   )r  r'   )r  r8   )r  r    )rz   r    r  r1  r  r  )rh   r@   r  r@   )rh   r@   r   r  r  r@   F)r   zUnion[str, tuple[str, str]]r   rW   r  zOptional[int])r   rW   r  r1  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%  rH  r.  rW   r  "Generator[_ObjectType, None, None]r^   )r-  rJ  r.  rW   r  z:Generator[Tuple[_SubjectType, _PredicateType], None, None])r%  rH  r.  rW   r  z7Generator[Tuple[_SubjectType, _ObjectType], None, None])r$  rI  r.  rW   r  z9Generator[Tuple[_PredicateType, _ObjectType], None, None]rr   r   _TripleChoiceTyper   Optional[_ContextType]r  r@  ).....)r$  r1  r%  r1  r-  rJ  rK  Optional[Node]rL  rW   r  r1  )r$  rI  r%  r1  r-  r1  rK  rO  rL  rW   r  r1  )r$  r1  r%  Optional[_PredicateType]r-  r1  rK  rO  rL  rW   r  r1  )r$  rI  r%  rP  r-  rJ  rK  rO  rL  rW   r  rO  )r  r-   r  zGenerator[Node, None, None])re  z-Callable[[_TCArgT, Graph], Iterable[_TCArgT]]rf  rU   rg  zOptional[Dict[_TCArgT, int]])r$  rI  r%  rP  rm  z+Optional[Dict[Optional[_SubjectType], int]]r  z-Generator[Optional[_SubjectType], None, None])r%  rP  r-  rJ  rm  z*Optional[Dict[Optional[_ObjectType], int]]r  z,Generator[Optional[_ObjectType], None, None]r  r  r  r  Tr  r  rz  rW   r  zTuple[str, URIRef, str])TF)
r  r[   r  r   r}  rW   r~  rW   r  r1  r  z)Generator[Tuple[str, URIRef], None, None]r   )r  r  r  rF  r  r/   r  r1  r  r  r\   r[   r  r  r  r   r  r  .......r  r1  r  r  r\   r[   r  r1  r  r   r  r  r  z'Union[str, pathlib.PurePath, IO[bytes]]r  r  r\   r[   r  r[   r  r   r  rA   r  1Optional[Union[str, pathlib.PurePath, IO[bytes]]]r  r  r\   r[   r  r[   r  r   r  zUnion[bytes, str, Graph])Nr  NN)rh   r@   r  r\  r  r  r\   r[   r  r[   r  r   r  zUnion[bytes, str, _GraphT])r  r  N)r  r  r  r  r  zOptional[TextIO]r  r1  NNNNNNr  MOptional[Union[IO[bytes], TextIO, InputSource, str, bytes, pathlib.PurePath]]r  r[   r  r[   r  r[   r  !Optional[Union[BinaryIO, TextIO]]r  Optional[Union[str, bytes]]r  r   r  rA   )sparqlrb  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)rb  NNT)r  zUnion[Update, str]r  z(Union[str, rdflib.query.UpdateProcessor]r  rc  r  rd  r  rW   r  r   r  r1  rk   r9  r  r  r  z8Tuple[Type[Graph], Tuple[Store, _ContextIdentifierType]])r  z	Set[Node])rj   r2   r  r   )rj   zUnion[Node, str]r  r%   )r  rA   re  z$Callable[[_TripleType], _TripleType]r  r1  NNNN)
r  Optional[Graph]r  zOptional[BNode]r	  r[   r
  r[   r  rA   NN)r  rh  r  zOptional[URIRef]r  rA   )r  r2   r'  zGraph | Noner(  rW   r  rA   )Qr   
__module____qualname____firstlineno____doc____annotations__r`   propertyri   rj   rk   setterr}   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   rG  rM  r   ra  rd  rl  rq  rt  rx  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r2  __static_attributes____classcell__rm   s   @rn   rA   rA     s
   IV 
 $-CG8<"/7# # A# 6	#
 # -# #4   ! ! ( ( & &L.
 JO888BF8	8Y 
 1"1 
,1 1
 5&5 
05 5
 =#= 
8= =
!#! 
8!0HT
20%P

-

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

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

 


  "& $"&26,0R
R
  R R  R 0R *R R 
Rn 2:19.2;?#'CU'CU /CU /	CU
 ,CU 9CU !CU CU 
CUP ?G.2;?#'8O)8O <8O ,	8O
 98O !8O 8O 
8OtP
<'R
,0*0  #G 	  &*!%#'"&#"# # !	#
  # 
#L MQ)()9I)	)^ &*%)UU #	U
 #U 
U Urp   c                  T  ^  \ rS rSr% SrS\S'      S&     S'U 4S jjjr\S 5       r\R                  S 5       rS(S jr
\ S)     S*S	 jj5       r\ S)     S+S
 jj5       r\ S)     S,S jj5       r\ S)     S-S jj5       r\ S)     S.S jj5       r\ S)     S/S jj5       r S)     S/S jjrS0S jr      S1S jr\S2S j5       r\S3S j5       r    S4S jr      S5S jrS1S jr\ S6     S7S jj5       r\ S6     S8S jj5       r\ S6     S9S jj5       r S:     S9S jjr S:   S;S jjr S:     S<S jjrS=S jr S:   S>S jjrS?S jr  S@       SAS  jjrSBS! jrS:SCS" jjr      SD               SES# jjrSFS$ jrS%rU =r$ )GrD   iD  a  A ConjunctiveGraph is an (unnamed) aggregation of all the named
graphs in a store.

!!! warning "Deprecation notice"
    ConjunctiveGraph is deprecated, use [`rdflib.graph.Dataset`][rdflib.graph.Dataset] instead.

It has a `default` graph, whose name is associated with the
graph throughout its life. Constructor 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   _default_contextc                6  > [         [        U ]  XS9  [        U 5      [        L a  [        R
                  " S[        SS9  U R                  R                  (       d   S5       eSU l        SU l	        [        U R                  U=(       d
    [        5       US9U l        g )N)rj   z4ConjunctiveGraph is deprecated, use Dataset instead.   
stacklevelz9ConjunctiveGraph must be backed by a context aware store.Tri   rj   r\   )r_   rD   r`   r|   warningswarnDeprecationWarningri   rX   rZ   rA   r(   rw  )rh   ri   rj   default_graph_baserm   s       rn   r`   ConjunctiveGraph.__init__W  s     	.u.L:))MMF" zz'' 	
J	
' "!.3**)>uwEW/
rp   c                    U R                   $ rr   rw  rs   s    rn   r   ConjunctiveGraph.default_contexto      $$$rp   c                    Xl         g rr   r  rh   rM  s     rn   r  r  s       %rp   c                J    SnXR                   R                  R                  -  $ )NzK[a rdflib:ConjunctiveGraph;rdflib:storage [a rdflib:Store;rdfs:label '%s']]ri   rm   r   rh   patterns     rn   r   ConjunctiveGraph.__str__w  s'    0 	 --6666rp   c                    g rr   r   rh   triple_or_quadrK  s      rn   _spocConjunctiveGraph._spoc~  s    
 rp   c                    g rr   r   r  s      rn   r  r        
  rp   c                    g rr   r   r  s      rn   r  r    s    
 47rp   c                    g rr   r   r  s      rn   r  r    s    
 rp   c                    g rr   r   r  s      rn   r  r    r  rp   c                    g rr   r   r  s      rn   r  r    r  rp   c                    Uc  SSSU(       a  U R                   4$ S4$ [        U5      S:X  a  U(       a  U R                   OSnUu  pEnO%[        U5      S:X  a  Uu  pEpcU R                  U5      nWWWW4$ )zG
helper method for having methods that support
either triples or quads
N      )r  r  _graph)rh   r  rK  r   r   r   r   s          rn   r  r    s     !$gd&:&:PP4PP~!#(/$$TA&IQ1 A%)LQ1AA!Qzrp   c                ^    U R                  U5      u  p#pEU R                  X#U4US9 H  n  g   g)z)Support for 'triple/quad in graph' syntaxr   TF)r  r   )rh   r  r   r   r   r   r  s          rn   r   ConjunctiveGraph.__contains__  s5    ZZ/
aqQi3A 4rp   c                ~    U R                  USS9u  p#pE[        X#U5        U R                  R                  X#U4USS9  U $ )z\Add a triple or quad to the store.

if a triple is given it is added to the default context
TrK  F)r   r   )r  r   ri   r   rh   r  r   r   r   r   s         rn   r   ConjunctiveGraph.add  sE     ZZZ=
aA! 	

ay!E:rp   c                    g rr   r   rh   r   s     rn   r  ConjunctiveGraph._graph  s    MPrp   c                    g rr   r   r  s     rn   r  r    s    '*rp   c                    Uc  g [        U[        [        45      (       a  U$ [        U[        5      (       a  U R	                  UR
                  5      $ U R	                  U5      $ rr   )rb   rF   rD   rA   get_contextrj   r  s     rn   r  r    sW     9a'#3455Ha##ALL11""rp   c                R   ^  T R                   R                  U 4S jU 5       5        T $ )z&Add a sequence of triples with contextc              3  x   >#    U  H/  u  pp4[        XU5      (       d  M  XUTR                  U5      4v   M1     g 7frr   )r   r  r   s        rn   r   (ConjunctiveGraph.addN.<locals>.<genexpr>  s4      
8=*!QSTAU%Q1dkk!n%s   ::ri   r   r   s   ` rn   r   ConjunctiveGraph.addN  s)    
 	

 
8=
 	
 rp   c                f    U R                  U5      u  p#pEU R                  R                  X#U4US9  U $ )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   r  s         rn   r   ConjunctiveGraph.remove  s6     ZZ/
a

1)Q/rp   c                    g rr   r   rh   r  r   s      rn   r   ConjunctiveGraph.triples  s    
 .1rp   c                    g rr   r   r  s      rn   r   r  	  s    
 25rp   c                    g rr   r   r  s      rn   r   r  	  s    
 :=rp   c              #    #    U R                  U5      u  p4pVU R                  U=(       d    U5      nU R                  (       a  X R                  :X  a  SnOUc  U R                  n[	        U[
        5      (       a'  Uc  U nUR                  X#U5       H  u  p5X4U4v   M     gU R                  R                  X4U4US9 H  u  u  p4pWX4U4v   M     g7f)zIterate 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  r  rZ   r  rb   r$   r   ri   r   )rh   r  r   r   r   r   r   r   s           rn   r   r  	  s      ZZ/
a++gl+.....aw1-Ag . "&!3!3Q1Iw!3!O	qAg "Ps   CCc              #     #    U R                  U5      u  p#pEU R                  R                  X#U4US9 H  u  u  p#pFU H	  nX#XG4v   M     M     g7f)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   ConjunctiveGraph.quads4	  sV     
 ZZ/
a!ZZ//q	1/EMIQ1Al"  Fs   AAc              #     #    Uu  p4nUc  U R                   (       d  U R                  nOU R                  U5      nU R                  R	                  X4U4US9 H  u  u  pgpXgU4v   M     g7f)z<Iterate over all the triples in the entire conjunctive graphNr   )rZ   r  r  ri   rG  )
rh   r   r   r   r   r   s1p1o1r   s
             rn   rG   ConjunctiveGraph.triples_choices?	  sn      a?%%..kk'*G !%

 : :A!9g : VLRR"* !Ws   A'A)c                6    U R                   R                  5       $ )z1Number of triples in the entire conjunctive graph)ri   r   rs   s    rn   r   ConjunctiveGraph.__len__P	  s    zz!!##rp   c              #     #    U R                   R                  U5       H1  n[        U[        5      (       a  Uv   M  U R	                  U5      v   M3     g7f)zlIterate 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[  ConjunctiveGraph.contextsT	  sG      zz**62G'5))  &&w// 3s   AAc                v    U R                  5        Vs/ s H  o"R                  U:X  d  M  UPM     snS   $ s  snf )z0Returns the graph identified by given identifierr   )r[  rj   )rh   rj   r  s      rn   	get_graphConjunctiveGraph.get_graphe	  s.    ==?I?allj.H?I!LLIs   66c                B    [        U R                  UU R                  US9$ )zWReturn 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  ConjunctiveGraph.get_contexti	  s'     **!"44	
 	
rp   c                <    U R                   R                  SU5        g)z(Removes the given context from the graphr   N)ri   r   )rh   r   s     rn   remove_contextConjunctiveGraph.remove_contextz	  s    

,g6rp   c                H    UR                  SS5      S   nUc  Sn[        X!S9$ )zURI#context#r   r   z#context)r\   )splitr/   )rh   r  
context_ids      rn   r  ConjunctiveGraph.context_id~	  s-    iiQ"#Jj++rp   c           	     d    [        UUUUUUS9nU R                  nUR                  " U4X#S.UD6  U $ )a  Parse source adding the resulting triples to its own context (sub graph
of this graph).

See [`rdflib.graph.Graph.parse`][rdflib.graph.Graph.parse] for documentation on arguments.

Args:
    source: The source to parse
    publicID: The public ID of the source
    format: The format of the source
    location: The location of the source
    file: The file object to parse
    data: The data to parse
    **args: Additional arguments

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

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

!!! warning "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
    Security Considerations documentation.

!!! example "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. ConjunctiveGraph.default_context).
r  )r  r  )r#   r  r  )	rh   r  r  r  r  r  r  r  r   s	            rn   r  ConjunctiveGraph.parse	  sI    l %
" &&fGxG$Grp   c                >    [         U R                  U R                  44$ rr   )rD   ri   rj   rs   s    rn   r  ConjunctiveGraph.__reduce__	  s    $**doo!>>>rp   )rw  rX   rZ   )rK  NN)ri   r7  rj   z$Optional[Union[IdentifiedNode, str]]r  r[   r:  r;  )r  rO   rK  rW   r  rO   )r  z%Union[_TripleType, _OptionalQuadType]rK  rW   r  r7   )r  r1  rK  rW   r  z(Tuple[None, None, None, Optional[Graph]])r  "Optional[_TripleOrQuadPatternType]rK  rW   r  r:   )r  rT   rK  rW   r  r>   )r  z#Optional[_TripleOrQuadSelectorType]rK  rW   r  r>   r  rT   r  rW   )rh   rC   r  rP   r  rC   )r   z)Union[Graph, _ContextIdentifierType, str]r  rA   )r   r1  r  r1  )r   z3Optional[Union[Graph, _ContextIdentifierType, str]]r  rh  )rh   rC   r   r>  r  rC   ).)r  rS   r   rN  r  r@  )r  rR   r   rN  r  rB  )r  rT   r   rN  r  rD  rr   )r  r  r  z(Generator[_OptionalQuadType, None, None]rL  rE  r   zOptional[_TripleType]r  z#Generator[_ContextType, None, None])rj   r8   r  zUnion[Graph, None])FN)rj   r8  r   rW   r\   r[   r  rA   )r   r5   r  r1  )r  r  r  r[   r  r/   r]  r^  rf  )r   rj  rk  rl  rm  rn  r`   ro  r  rp  r   r   r  r   r   r  r   r   r   r   rG  r   r[  r  r  r  r  r  r  rs  rt  ru  s   @rn   rD   rD   D  s:     #" $-;?,0	
 
 9
 *	
 
0 % % & &7  !  
	    =    
	     77 7 
2	7 7  :  
	    1    
	      ;    
	    ;  
	* 1 
" P P* *#># 
# )<		  +.101 (1 
,	1 1  +.545 (5 
0	5 5  +.=1= (= 
8	= = +/1 ( 
8	B DH	#@	#	1	# +/! ( 
,	"$
 /30+0	,0"M "	
@
 
 	

 

"7, "& $"&26,0I
I
  I I  I 0I *I I 
IV? ?rp   zurn:x-rdflib:defaultc                    ^  \ rS rSrSr   S     SU 4S jjjr\S 5       r\R                  S 5       r\S 5       r	\	R                  S 5       r	\U 4S j5       r
SS	 jrS S
 jrS!S jr    S"S jrS#S jr  S$     S%S jjr      S&               S'S jjr    S(S jr      S)S jr S*   S+U 4S jjjr S*   S+U 4S jjjr S*   S,U 4S jjjr  S-S jr\            S.S j5       r\   S/           S.S jj5       r\    S0           S1S jj5       r\   S/           S2S jj5       r\    S0           S3S jj5       r    S4           S3U 4S jjjrSrU =r$ )5rF   i	  aV  
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
[`URIRef`][rdflib.term.URIRef] or [`BNode`][rdflib.term.BNode] identifiers and always
creats a default graph with the [`URIRef`][rdflib.term.URIRef] identifier
`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.

!!! warning "Deprecation notice"
    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:

```python
>>> # 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)
```

!!! example "New in version 4.0"
c                   > [         [        U ]  US S9  U R                  R                  (       d  [        S5      e[        U R                  [        US9U l        X l	        g )N)ri   rj   z.Dataset must be backed by a graph-aware store!r|  )
r_   rF   r`   ri   graph_aware	ExceptionrA   DATASET_DEFAULT_GRAPH_IDrw  rZ   )rh   ri   rZ   r  rm   s       rn   r`   Dataset.__init__q
  sT     	gt%Ed%Czz%%LMM %**/#!
 +rp   c                N    [         R                  " S[        SS9  U R                  $ NzIDataset.default_context is deprecated, use Dataset.default_graph instead.ry  rz  r}  r~  r  rw  rs   s    rn   r  Dataset.default_context
  s%    W	

 $$$rp   c                D    [         R                  " S[        SS9  Xl        g r  r  r  s     rn   r  r  
  s    W	

 !&rp   c                    U R                   $ rr   r  rs   s    rn   default_graphDataset.default_graph
  r  rp   c                    Xl         g rr   r  r  s     rn   r  r  
  r  rp   c                T   > [         R                  " S[        SS9  [        [        U ]  $ )NzHDataset.identifier is deprecated and will be removed in future versions.ry  rz  )r}  r~  r  r_   rF   rj   )rh   rm   s    rn   rj   Dataset.identifier
  s'    V	

 Wd..rp   c                J    SnXR                   R                  R                  -  $ )NzB[a rdflib:Dataset;rdflib:storage [a rdflib:Store;rdfs:label '%s']]r  r  s     rn   r   Dataset.__str__
  s%    S 	 --6666rp   c                H    [        U 5      U R                  U R                  44$ rr   )r|   ri   rZ   rs   s    rn   r  Dataset.__reduce__
  s     T
TZZ););<==rp   c                ^    U R                   U R                  U R                  U R                  4$ rr   ri   rj   r  rZ   rs   s    rn   __getstate__Dataset.__getstate__
  s%    zz4??D,>,>@R@RRRrp   c                :    Uu  U l         U l        U l        U l        g rr   r  )rh   states     rn   __setstate__Dataset.__setstate__
  s    
 OTK
DOT%79Krp   c                6    U R                  S U 5       5        U $ )zEAdd all quads in Dataset other to Dataset.
BNode IDs are not changed.c              3  0   #    U  H  u  pp4XX44v   M     g 7frr   r   )r   r   r   r   gs        rn   r   #Dataset.__iadd__.<locals>.<genexpr>
  s     7:11,s   r  r   s     rn   r  Dataset.__iadd__
  s     			777rp   c                f   Uc3  SSK JnJn  U R                  SX4-   SS9  [	        5       R                  5       nS n[        U[        5      (       a  [        U[        [        45      (       d  UnU R                  U5      nUb  UR                  U5        X&l        U R                  R                  U5        U$ )Nr   )_SKOLEM_DEFAULT_AUTHORITYrdflib_skolem_genidgenidF)r}  )rdflib.termr  r  r  r(   r  rb   rA   rF   rD   r  r  r\   ri   	add_graph)rh   rj   r\   r  r  graph_to_copyr  s          rn   graphDataset.graph
  s    
 RII)?  
 **,J)-j%(("232
 2

 'MKK
#$JJ}%

Qrp   c           	     :    [         R                  " XX#XEU40 UD6  U $ )a  Parse an RDF source adding the resulting triples to the Graph.

Args:
    source: The source to parse. See rdflib.graph.Graph.parse for details.
    publicID: The public ID of the source.
    format: The format of the source.
    location: The location of the source.
    file: The file object to parse.
    data: The data to parse.
    **args: Additional arguments.

Returns:
    The graph that the source was parsed into.

Note:
    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_graph`).
    If the source is in a format that does not support named graphs its triples
    will be added to the default graph (i.e. Dataset.default_graph).

!!! warning "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
    Security Considerations documentation.

!!! example "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. Dataset.default_graph).
)rD   r  )rh   r  r  r  r  r  r  r  s           rn   r  Dataset.parse
  s+    n 	(HD	
DH	
 rp   c                $    U R                  U5      $ )zalias of graph for consistency)r  rh   r  s     rn   r  Dataset.add_graph  s     zz!}rp   c                    [        U[        5      (       d  U R                  U5      nU R                  R	                  U5        Ub  XR
                  :X  a%  U R                  R                  U R
                  5        U $ rr   )rb   rA   r  ri   remove_graphr  r  r  s     rn   r  Dataset.remove_graph"  sb     !U##  #A

"9/// JJ  !3!34rp   c              #     >#    [         R                  " S[        SS9  Sn[        [        U ]  U5       H  nX#R                  [        :H  -  nUv   M     U(       d  U R                  [        5      v   g g 7f)Nz;Dataset.contexts is deprecated, use Dataset.graphs instead.ry  rz  F)	r}  r~  r  r_   rF   r[  rj   r  r  rh   r   rK  r   rm   s       rn   r[  Dataset.contexts/  sk      	I	

 w.v6A||'???GG 7 **566 s   A0A3c              #     >#    Sn[         [        U ]  U5       H  nX#R                  [        :H  -  nUv   M     U(       d  U R                  [        5      v   g g 7fr^   )r_   rF   r[  rj   r  r  r
  s       rn   graphsDataset.graphs>  sT      w.v6A||'???GG 7 **566 s   AAc              #     >#    [         [        U ]  U5       H9  u  p#pEUR                  U R                  :X  a	  X#US 4v   M)  X#XER                  4v   M;     g 7frr   )r_   rF   r   rj   r  )rh   quadr   r   r   r   rm   s         rn   r   Dataset.quadsI  sQ       4T:JA!||t111Atm# A||++ ;s   AAc                $    U R                  S5      $ )z$Iterates over all quads in the storerg  )r   rs   s    rn   r   Dataset.__iter__U  s     zz233rp   c                    g rr   r   r  s         rn   r  Dataset.serialize[  r  rp   c                   g rr   r   r  s         rn   r  r  f  r  rp   c                    g rr   r   r  s         rn   r  r  r  r  rp   c                    g rr   r   r  s         rn   r  r  }  r  rp   c                    g rr   r   r  s         rn   r  r    r  rp   c                2   > [         [        U ]
  " SXX4S.UD6$ )N)r  r  r\   r  r   )r_   rF   r  )rh   r  r  r\   r  r  rm   s         rn   r  r    s+     Wd- 
#
TX
 	
rp   )rw  r  rZ   rj   ri   )rK  FN)ri   r7  rZ   rW   r  r[   r:  )r  z(Tuple[Type[Dataset], Tuple[Store, bool]])r  8Tuple[Store, _ContextIdentifierType, _ContextType, bool])r  r  r  r1  )rh   rE   r   r>  r  rE   ri  )rj   :Optional[Union[_ContextIdentifierType, _ContextType, str]]r\   r[   r  rA   r]  )r  r_  r  r[   r  r[   r  r[   r  r`  r  ra  r  r   r  rF   )r  r  r  rA   )rh   rE   r  r  r  rE   rr   r  )r  r  r  2Generator[_OptionalIdentifiedQuadType, None, None])r  r  rV  rW  rX  rY  rZ  r[  )NtrigNN)r   rj  rk  rl  rm  r`   ro  r  rp  r  rj   r   r  r  r  r  r  r  r  r  r[  r  r   r   r   r  rs  rt  ru  s   @rn   rF   rF   	  s   Wv $-#,0	+ + + *	+ +$ % % & & % % & & / /7>STMT	T RV"N  
	F "& $"&26,0:
:
  : :  : 0: *: : 
:xK	V	 /37+7	,7 7  /37+7	,7 7 :>	,6	,	;	, 	,4	;4   	
   
    !	  	   
    !  	
   
   !"%<  	
    
   JM!"%'F' ' 	'
  ' ' 
"' ' JN""&

F

 

 	


  

 

 
"

 

rp   c                  n   ^  \ rS rSrSr    S
U 4S jjrSS jrSS jrSSS jjrSS jr	SS jr
S	rU =r$ )rH   i  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                ,   > [         [        U ]  X5        g rr   )r_   rH   r`   )rh   ri   rj   rm   s      rn   r`   QuotedGraph.__init__  s    
 	k4)%<rp   c                   Uu  p#n[        U[        5      (       d   SU< S35       e[        U[        5      (       d   SU< S35       e[        U[        5      (       d   SU< S35       eU R                  R                  X#U4U SS9  U $ )z!Add a triple with self as contextr   r   r   r   Tr   )rb   r-   ri   r   r   s        rn   r   QuotedGraph.add  s{    a!T""N1$NN"!T""PQ$PP"!T""M!$MM"

ay$t4rp   c                R   ^  T R                   R                  U 4S jU 5       5        T $ )r   c              3     >#    U  HQ  u  pp4[        U[        5      (       d  M  UR                  TR                  L d  M8  [        XU5      (       d  MK  XX44v   MS     g 7frr   )rb   rH   rj   r   r   s        rn   r   #QuotedGraph.addN.<locals>.<genexpr>  sT      
#
a![)  /  A!$	 Q1L#r   r  r   s   ` rn   r   QuotedGraph.addN  s)     	

 
#
 	
 rp   c                :    SU R                   R                  US9-  $ )r  z{%s}r  r  r  s     rn   r   QuotedGraph.n3  r  rp   c                    U R                   R                  5       nU R                  R                  R                  nSnX1U4-  $ )NzK{this rdflib.identifier %s;rdflib:storage [a rdflib:Store;rdfs:label '%s']})rj   r   ri   rm   r   )rh   rj   labelr  s       rn   r   QuotedGraph.__str__  sC    __'')


$$--0 	 e,,,rp   c                >    [         U R                  U R                  44$ rr   )rH   ri   rj   rs   s    rn   r  QuotedGraph.__reduce__  s    TZZ999rp   r   )ri   r7  rj   r8  r<  r=  rr   re  r:  rf  )r   rj  rk  rl  rm  r`   r   r   r   r   r  rs  rt  ru  s   @rn   rH   rH     s?    = = A=
P-: :rp   rH      c                  J    \ rS rSrSrS
S jrSS jrSS jrSS jrSS jr	Sr
g	)rI   i  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.

Args:
    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!
c                <   U   [        5       =o0l        [        [        [        5      S-   5      nUR                  U5       HJ  u  pVUR                  U5      (       d  M  [        UR                  US5      5      nUR                  Xv45        ML     UR                  5         g )N_r  )r  _listr/   r  r   r   
startswithrF  r~  r  sort)rh   r  r$  r3  LI_INDEXr   r   is           rn   r`   Seq.__init__  sw    !V#
#c(S.)++G4DA||H%%		(B/0aV$ 5 	

rp   c                    U $ rr   r   rs   s    rn   r   Seq.toPython  r   rp   c              #  >   #    U R                    H	  u  pUv   M     g7f)z#Generator over the items in the SeqNr3  )rh   r2  r   s      rn   r   Seq.__iter__  s     zzGAJ "s   c                ,    [        U R                  5      $ )zLength of the Seq)r  r3  rs   s    rn   r   Seq.__len__  s    4::rp   c                @    U R                   R                  U5      u  pU$ )z Item given by index from the Seq)r3  r   )rh   indexr   s      rn   r   Seq.__getitem__  s    jj,,U3rp   r<  N)r  rA   r$  r2   )r  rI   )r  rK  rE  )r  r4   )r   rj  rk  rl  rm  r`   r   r   r   r   rs  r   rp   rn   rI   rI     s     
rp   rI   c                  (    \ rS rSrSS jrSS jrSrg)rJ   i  c                    g rr   r   rs   s    rn   r`   ModificationException.__init__      rp   c                     g)NzZModifications and transactional operations not allowed on ReadOnlyGraphAggregate instancesr   rs   s    rn   r   ModificationException.__str__  s    /	
rp   r   Nr  r1  r:  r   rj  rk  rl  r`   r   rs  r   rp   rn   rJ   rJ     s    
rp   rJ   c                  (    \ rS rSrSS jrSS jrSrg)rK   i  c                    g rr   r   rs   s    rn   r`   &UnSupportedAggregateOperation.__init__  rF  rp   c                    g)NzCThis operation is not supported by ReadOnlyGraphAggregate instancesr   rs   s    rn   r   %UnSupportedAggregateOperation.__str__  s    Wrp   r   NrI  r:  rJ  r   rp   rn   rK   rK     s    Xrp   rK   c                    ^  \ rS rSrSrS"S#U 4S jjjrS$S jrS%S jrS&S jrS&S jr	S'S(S jjr
S)S	 jrS*S
 jrS+S jrS*S jr\    S,S j5       r\    S-S j5       r\    S.S j5       r    S.S jrS/S jr    S0S jrS1S jrS&S jrS1S jrS2S jrS2S jr S3     S4S jjrS5S jrS6S7S jjr S6       S8S jjrS9S jrS:S;S jjr  S<         S=S jjrS3S>S jjrS&S  jr S!r!U =r"$ )?rL   i  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                $  > Ub/  [         [        U ]  U5        [        R                  X5        S U l        [        U[        5      (       a6  U(       a/  U Vs/ s H  n[        U[        5      (       d  M  UPM     sn(       d   S5       eXl        g s  snf )Nz*graphs argument must be a list of Graphs!!)r_   rL   r`   rA   *_ReadOnlyGraphAggregate__namespace_managerrb   r  r  )rh   r  ri   r  rm   s       rn   r`   ReadOnlyGraphAggregate.__init__&  sz    ($8?NN4''+D$ vt$$";FqjE&:F;	8 8		8<  <s   B1Bc                2    S[        U R                  5      -  $ )Nz#<ReadOnlyGraphAggregate: %s graphs>)r  r  rs   s    rn   r}   ReadOnlyGraphAggregate.__repr__3  s    4s4;;7GGGrp   c                    [        5       err   rJ   r   s     rn   r   ReadOnlyGraphAggregate.destroy6      #%%rp   c                    [        5       err   rW  rs   s    rn   r   ReadOnlyGraphAggregate.commit:  rY  rp   c                    [        5       err   rW  rs   s    rn   r   ReadOnlyGraphAggregate.rollback=  rY  rp   c                N    U R                    H  nUR                  XU5        M     g rr   )r  r   )rh   r   r   r  s       rn   r   ReadOnlyGraphAggregate.open@  s     [[E JJtF3	 !rp   c                J    U R                    H  nUR                  5         M     g rr   )r  r   )rh   r  s     rn   r   ReadOnlyGraphAggregate.closeI  s    [[EKKM !rp   c                    [        5       err   rW  r   s     rn   r   ReadOnlyGraphAggregate.addM  rY  rp   c                    [        5       err   rW  r   s     rn   r   ReadOnlyGraphAggregate.addNP  rY  rp   c                    [        5       err   rW  r   s     rn   r   ReadOnlyGraphAggregate.removeT  rY  rp   c                    g rr   r   r   s     rn   r   ReadOnlyGraphAggregate.triplesX  r   rp   c                    g rr   r   r   s     rn   r   ri  ^  r   rp   c                    g rr   r   r   s     rn   r   ri  d  r   rp   c              #     #    Uu  p#nU R                    H^  n[        U[        5      (       a#  UR                  XU5       H  u  p$X#U4v   M     M;  UR	                  X#U45       H  u  pgnXgU4v   M     M`     g 7frr   )r  rb   r$   r   r   )	rh   r   r   r   r   r  r  r  r  s	            rn   r   ri  j  sr      a[[E!T""FF4A.DA'M / #(--q	":JBB"*$ #; !s   A5A7c                    S n[        U5      S:X  a  US   nU R                   H-  nUb  UR                  UR                  :X  d  M"  US S U;   d  M-    g   g)Nr  r  TF)r  r  rj   )rh   r  r   r  s       rn   r   #ReadOnlyGraphAggregate.__contains__w  s[    ~!#$Q'G[[E%"2"2g6H6H"H!"1%. ! rp   c              #  ^  #    Sn[        U5      S:X  a  Uu  p4pROUu  p4nUbO  U R                   Vs/ s H  ofU:X  d  M
  UPM     sn H&  nUR                  X4U45       H  u  pn
XX4v   M     M(     gU R                   H&  nUR                  X4U45       H  u  pn
XX4v   M     M(     gs  snf 7f)z8Iterate over all the quads in the entire aggregate graphNr  )r  r  r   )rh   r  r   r   r   r   r  r  r  r  r  s              rn   r   ReadOnlyGraphAggregate.quads  s      ~!#'JA!Q %GA!=%)[[;[F![;"'--q	":JBB"++ #; < "'--q	":JBB"++ #; %	 <s   .B-	B(B(A*B-c                :    [        S U R                   5       5      $ )Nc              3  8   #    U  H  n[        U5      v   M     g 7frr   )r  )r   r  s     rn   r   1ReadOnlyGraphAggregate.__len__.<locals>.<genexpr>  s     /;a3q66;s   )sumr  rs   s    rn   r   ReadOnlyGraphAggregate.__len__  s    /4;;///rp   c                    [        5       err   rK   rs   s    rn   r   ReadOnlyGraphAggregate.__hash__      +--rp   c                    Uc  g[        U[        5      (       a  g[        U[        5      (       a3  U R                  UR                  :  U R                  UR                  :  -
  $ g)Nr   )rb   rA   rL   r  r   s     rn   r   ReadOnlyGraphAggregate.__cmp__  sP    =u%%566KK%,,.4;;3MNNrp   c                    [        5       err   rW  r   s     rn   r  ReadOnlyGraphAggregate.__iadd__  rY  rp   c                    [        5       err   rW  r   s     rn   r	  ReadOnlyGraphAggregate.__isub__  rY  rp   c              #     #    Uu  p4nU R                    H(  nUR                  X4U45      nU H  u  pn
XU
4v   M     M*     g 7frr   )r  rG  )rh   r   r   r$  r%  r&  r  choicesr   r   r   s              rn   rG  &ReadOnlyGraphAggregate.triples_choices  sM     
 '-#G[[E ++W,IJG"aAg #	 !s   ?Ac                    [        U S5      (       a,  U R                  (       a  U R                  R                  U5      $ [        5       eNrk   )r  rk   rt  rK   ru  s     rn   rt  ReadOnlyGraphAggregate.qname  s8    4,--$2H2H))//44+--rp   c                    [        U S5      (       a,  U R                  (       a  U R                  R                  X5      $ [        5       er  )r  rk   rx  rK   ry  s      rn   rx  $ReadOnlyGraphAggregate.compute_qname  s8    4,--$2H2H))77FF+--rp   c                    [        5       err   rw  )rh   r  r  r}  s       rn   r  ReadOnlyGraphAggregate.bind  s     ,--rp   c              #     #    [        U S5      (       a)  U R                  R                  5        H
  u  pX4v   M     g U R                   H!  nUR                  5        H
  u  pX4v   M     M#     g 7fr  )r  rk   r  r  )rh   r  r  r  s       rn   r  !ReadOnlyGraphAggregate.namespaces  sh     4,--%)%;%;%F%F%H!'' &I ).)9)9);%F ++ *< %s   A-A/c                    [        5       err   rw  r  s      rn   r  !ReadOnlyGraphAggregate.absolutize  ry  rp   c                    [        5       err   rW  )rh   r  r  r  r  s        rn   r  ReadOnlyGraphAggregate.parse  s     $%%rp   c                    [        5       err   rw  r  s     rn   r   ReadOnlyGraphAggregate.n3  ry  rp   c                    [        5       err   rw  rs   s    rn   r  !ReadOnlyGraphAggregate.__reduce__  ry  rp   )r5  r  r  )r  zList[Graph]ri   zUnion[str, Store]r:  )r   r  r  r   )r  r   r;  )r   zstr | tuple[str, str]r   rW   r  r1  rI  )r   rP   r  r   )r   r>  r  r   r?  rA  rC  r  )r  rT   r  zbGenerator[Tuple[_SubjectType, Union[Path, _PredicateType], _ObjectType, _ContextType], None, None]rE  )rh   r@   r   rG  r  r   rr   rL  rQ  rR  rS  )r  r[   r  r   r}  rW   r  r   rT  rU  )r  r  r  rF  r  r   ri  )
r  r_  r  r[   r  r[   r  r   r  r   )rk   r9  r  r   )#r   rj  rk  rl  rm  r`   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  rG  rt  rx  r  r  r  r  r   r  rs  rt  ru  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.	.
,. #' $	&
	&
  	& 	& 	& 
	&.. .rp   rL   c                     g rr   r   termss    rn   r   r     s    36rp   c                     g rr   r   r  s    rn   r   r     s    &)rp   c                 X    U  H$  n[        U[        5      (       a  M   SU< S35       e   g)NzTerm r   T)rb   r-   )r  r  s     rn   r   r     s*    !T""K$KK" rp   c                  `    \ rS rSrSrSSS jjrSS jr    SS jrSS jrSS jr	SS jr
S	rg
)rM   i  a  Wrapper around graph that turns batches of calls to Graph's add
(and optionally, addN) into calls to batched calls to addN`.

Args:
    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

Attributes:
    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                    U(       a  US:  a  [        S5      eXl        U4U l        X l        X0l        U R                  5         g )Nry  z$batch_size must be a positive number)r_  r  _BatchAddGraph__graph_tuple_BatchAddGraph__batch_size_BatchAddGraph__batch_addnreset)rh   r  
batch_size
batch_addns       rn   r`   BatchAddGraph.__init__  s;    Z!^CDD
#X&&

rp   c                "    / U l         SU l        U $ )zA
Manually clear the buffered triples and reset the count to zero
r   )batchcountrs   s    rn   r  BatchAddGraph.reset  s     ')

rp   c                t   [        U R                  5      U R                  :  a,  U R                  R	                  U R                  5        / U l        U =R
                  S-  sl        [        U5      S:X  a)  U R                  R                  XR                  -   5        U $ U R                  R                  U5        U $ )zzAdd a triple to the buffer.

Args:
    triple_or_quad: The triple or quad to add

Returns:
    The BatchAddGraph instance
r   r  )r  r  r  r  r   r  r  r  )rh   r  s     rn   r   BatchAddGraph.add   s     tzz?d///JJOODJJ'DJ

a
~!#JJn/A/AAB  JJn-rp   c                    U R                   (       a  U H  nU R                  U5        M     U $ U R                  R                  U5        U $ rr   )r  r   r  r   )rh   r   qs      rn   r   BatchAddGraph.addN;  s>       JJOOE"rp   c                &    U R                  5         U $ rr   )r  rs   s    rn   	__enter__BatchAddGraph.__enter__C  s    

rp   c                \    US   c&  U R                   R                  U R                  5        g g )Nr   )r  r   r  )rh   excs     rn   __exit__BatchAddGraph.__exit__G  s$    q6>JJOODJJ' rp   )__batch_addn__batch_size__graph_tupler  r  r  N)i  F)r  rA   r  rF  r  rW   )r  rM   )r  zUnion[_TripleType, _QuadType]r  rM   )r   r>  r  rM   rI  )r   rj  rk  rl  rm  r`   r  r   r   r  r  rs  r   rp   rn   rM   rM     s9     
 
6(rp   rM   )r  r-   r  zte.Literal[True])r  r   r  rW   )zrm  
__future__r   loggingr  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.exceptionsrV  rdflib.namespacer  rdflib.pluginrc   rdflib.queryr  rdflib.utilr  rdflib.collectionr   r   r   r   r    rdflib.parserr!   r"   r#   rdflib.pathsr$   rdflib.resourcer%   rdflib.serializerr&   rdflib.storer'   r  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   rM  r@   rC   rE   rdflib._type_checkingrG   	getLoggerr   r+  __all__rU   rA   r5   rD   r  rF   rH   term	_ORDERINGrI   r  rJ   rK   rL   r   rM   r   rp   rn   <module>r     s  JX #          , " ' & $    ( ) = = 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 )

GD GT4 M?u M?` ""89 E
 E
P3:% 3:t &(  k "- -`
I 
XI XN.- N.b 
 6 
 6 
 ) 
 )K( K(rp   