
    4Ysh%              
       |   d dl mZ d dlmZ d dlmZ dgZ G d de      Zd Ze	dk(  r e        d dl
mZ  e       Z ee e             Z ee      d k(  sJ  ee e        ed	       ed
       ed       ed      g      Z ee      dk(  sJ ed    ed
      k(  s
J ed          ed=  ee       ed	       ed       ed      gk(  sJ  ee             	 ed= ej#                   ed              e ee             eD ]
  Z ee        ed= ej)                           ee      d k(  sJ yy# e$ r Y ]w xY w)    )RDF)BNode)Literal
Collectionc                   b    e Zd ZdZg fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zy)r   a  
    See "Emulating container types":
    https://docs.python.org/reference/datamodel.html#emulating-container-types

    >>> from rdflib.graph import Graph
    >>> from pprint import pprint
    >>> listName = BNode()
    >>> g = Graph('Memory')
    >>> listItem1 = BNode()
    >>> listItem2 = BNode()
    >>> g.add((listName, RDF.first, Literal(1))) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g.add((listName, RDF.rest, listItem1)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g.add((listItem1, RDF.first, Literal(2))) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g.add((listItem1, RDF.rest, listItem2)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g.add((listItem2, RDF.rest, RDF.nil)) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> g.add((listItem2, RDF.first, Literal(3))) # doctest: +ELLIPSIS
    <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
    >>> c = Collection(g,listName)
    >>> pprint([term.n3() for term in c])
    [u'"1"^^<http://www.w3.org/2001/XMLSchema#integer>',
     u'"2"^^<http://www.w3.org/2001/XMLSchema#integer>',
     u'"3"^^<http://www.w3.org/2001/XMLSchema#integer>']

    >>> Literal(1) in c
    True
    >>> len(c)
    3
    >>> c._get_container(1) == listItem1
    True
    >>> c.index(Literal(2)) == 1
    True
    c                 B    || _         |xs
 t               | _        | |z  } y N)graphr   uri)selfr
   r   seqs       q/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/collection.py__init__zCollection.__init__0   s    
>%'    c                 l    ddj                  | D cg c]  }|j                          c}      z  S c c}w )a  
        >>> from rdflib.graph import Graph
        >>> listName = BNode()
        >>> g = Graph('Memory')
        >>> listItem1 = BNode()
        >>> listItem2 = BNode()
        >>> g.add((listName, RDF.first, Literal(1))) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((listName, RDF.rest, listItem1)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((listItem1, RDF.first, Literal(2))) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((listItem1, RDF.rest, listItem2)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((listItem2, RDF.rest, RDF.nil)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((listItem2, RDF.first, Literal(3))) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> c = Collection(g, listName)
        >>> print(c.n3()) #doctest: +NORMALIZE_WHITESPACE
        ( "1"^^<http://www.w3.org/2001/XMLSchema#integer>
          "2"^^<http://www.w3.org/2001/XMLSchema#integer>
          "3"^^<http://www.w3.org/2001/XMLSchema#integer> )
        z( %s ) )joinn3)r   is     r   r   zCollection.n35   s,    2 388T$:QTTV$:;<<$:s   1
c                     t        |t              sJ | j                  }| j                  }d}||k  r0|dz  }|j	                  |t
        j                        }|	 |S ||k  r0|S )z+Gets the first, rest holding node at index.r      )
isinstanceintr
   r   valuer   rest)r   indexr
   	containerr   s        r   _get_containerzCollection._get_containerP   sm    %%%%

HH	%iFAIsxx8I  %i
 r   c                 p    t        t        | j                  j                  | j                                    S )zlength of items in collection.)lenlistr
   itemsr   r   s    r   __len__zCollection.__len__]   s%    4

((2344r   c                    | j                   }d}	 |t        j                  |f| j                  v r|S t	        | j                  j                  |t        j                              }|dz  }|t        j                  gk(  rt        |d| j                         |st        d| j                   z        t        |      dk(  sJ d| j                   z         |d   })zM
        Returns the 0-based numerical index of the item in the list
        r   r   z is not in zMalformed RDF Collection: %s)r   r   firstr
   r!   objectsr   nil
ValueError	Exceptionr    )r   itemlistNamer   newLinks        r   r   zCollection.indexa   s     88#))T*djj8tzz11(CHHEF
swwi'$$%IJJ #$BTXX$MNNw<1,W.Ltxx.WW,&qzH r   c                     | j                  |      }|r9| j                  j                  |t        j                        }|r|S t        |      t        |      )TODO)r   r
   r   r   r&   KeyError
IndexError)r   keycvs       r   __getitem__zCollection.__getitem__u   sK    $

  CII.Asm#S/!r   c                     | j                  |      }|r-| j                  j                  |t        j                  |f       yt        |      )r/   N)r   r
   setr   r&   r1   )r   r2   r   r3   s       r   __setitem__zCollection.__setitem__   s:    $JJNNAsyy%01S/!r   c                 (   | |    | j                   }| j                  |      }|sJ t        |       dk(  r|dkD  ry|t        |       dz
  k(  rc| j                  |dz
        }| j                   j                  |t        j
                  t        j                  f       |j                  |ddf       y| j                  |dz         }| j                  |dz
        }|r|sJ |j                  |ddf       |j                  |t        j
                  |f       y)a   
        >>> from rdflib.namespace import RDF, RDFS
        >>> from rdflib import Graph
        >>> from pprint import pformat
        >>> g = Graph()
        >>> a = BNode('foo')
        >>> b = BNode('bar')
        >>> c = BNode('baz')
        >>> g.add((a, RDF.first, RDF.type)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((a, RDF.rest, b)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((b, RDF.first, RDFS.label)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((b, RDF.rest, c)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((c, RDF.first, RDFS.comment)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> g.add((c, RDF.rest, RDF.nil)) # doctest: +ELLIPSIS
        <Graph identifier=... (<class 'rdflib.graph.Graph'>)>
        >>> len(g)
        6
        >>> def listAncestry(node, graph):
        ...   for i in graph.subjects(RDF.rest, node):
        ...     yield i
        >>> [str(node.n3())
        ...   for node in g.transitiveClosure(listAncestry, RDF.nil)]
        ['_:baz', '_:bar', '_:foo']
        >>> lst = Collection(g, a)
        >>> len(lst)
        3
        >>> b == lst._get_container(1)
        True
        >>> c == lst._get_container(2)
        True
        >>> del lst[1]
        >>> len(lst)
        2
        >>> len(g)
        4

        r   r   N)r
   r   r    r7   r   r   r(   remove)r   r2   r
   current	priorLinknextpriors          r   __delitem__zCollection.__delitem__   s    V 	S	

%%c*wt9>cAgCIM!++C!G4IJJNNIsxx9:LL'4./&&sQw/D''a0EE!>LL'4./IIuchh-.r   c                 L    | j                   j                  | j                        S )z"Iterator over items in Collections)r
   r"   r   r#   s    r   __iter__zCollection.__iter__   s    zz))r   c                     | j                   }	 | j                  j                  |t        j                        }||t        j
                  k(  r|S |}Dr	   )r   r
   r   r   r   r(   )r   r   r   s      r   _endzCollection._end   sG    HH	::##Isxx8D|tsww   	 r   c                    | j                         }|t        j                  df| j                  v r8t	               }| j                  j                  |t        j                  |f       |}| j                  j                  |t        j                  |f       | j                  j                  |t        j                  t        j                  f       | S )a]  
        >>> from rdflib.graph import Graph
        >>> listName = BNode()
        >>> g = Graph()
        >>> c = Collection(g,listName,[Literal(1),Literal(2)])
        >>> links = [
        ...     list(g.subjects(object=i, predicate=RDF.first))[0] for i in c]
        >>> len([i for i in links if (i, RDF.rest, RDF.nil) in g])
        1

        N)	rC   r   r&   r
   r   r7   r   addr(   )r   r+   endnodes       r   appendzCollection.append   s     iikD!TZZ/7DJJNNC401C

SYY-.

SXXsww/0r   c                    | j                         }| j                  j                  |t        j                  d f       |D ]  }|t        j
                  d f| j                  v r8t               }| j                  j                  |t        j                  |f       |}| j                  j                  |t        j
                  |f        | j                  j                  |t        j                  t        j                  f       | S r	   )	rC   r
   r:   r   r   r&   r   rE   r(   )r   otherrF   r+   nxts        r   __iadd__zCollection.__iadd__   s    iik

3$/0 	3DSYY%3g

SXXs34JJNNCD12	3 	

SXXsww/0r   c                    | j                   }| j                  }|ri|j                  |t        j                        }|j                  |t        j                  d f       |j                  |t        j                  d f       |}|ri| S r	   )r   r
   r   r   r   r:   r&   )r   r   r
   r   s       r   clearzCollection.clear   sj    HH	

;;y#((3DLL)SYY56LL)SXXt45I	 
 r   N)__name__
__module____qualname____doc__r   r   r   r$   r   r5   r8   r?   rA   rC   rH   rL   rN    r   r   r   r   	   sQ    $GL (* 
=65*(
"";/z*!0 r   c                  ,    dd l } | j                          y )Nr   )doctesttestmod)rU   s    r   testrW     s    OOr   __main__)Graph1234   r   i  5   N)rdflib.namespacer   rdflib.termr   r   __all__objectr   rW   rO   rdflibrY   gr3   r    r!   r1   rH   printr   rN   rS   r   r   <module>rh      sk       .{ {| zFA1egAq6Q;;1eggclGCL'RU,WXAq6Q;;Q473<%1%	!7ws|WS\73<@@I$q'I@cF HHWS\	$q'N a 	
!GGIq6Q;;K .  s   D3 3D;:D;