
    4Ysh                         d dl mZ d dlmZmZ d dlmZ g dZ G d de      Z	 G d de	      Z
 G d	 d
e	      Z G d de	      Z G d de      Zy)    )RDF)BNodeURIRef)randint)	ContainerBagSeqAltNoElementExceptionc                   j    e Zd ZdZg d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d Zy)r   a{  A class for constructing RDF containers, as per https://www.w3.org/TR/rdf11-mt/#rdf-containers

    Basic usage, creating a ``Bag`` and adding to it::

        >>> from rdflib import Graph, BNode, Literal, Bag
        >>> g = Graph()
        >>> b = Bag(g, BNode(), [Literal("One"), Literal("Two"), Literal("Three")])
        >>> print(g.serialize(format="turtle"))
        @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
        <BLANKLINE>
        [] a rdf:Bag ;
            rdf:_1 "One" ;
            rdf:_2 "Two" ;
            rdf:_3 "Three" .
        <BLANKLINE>
        <BLANKLINE>

        >>> # print out an item using an index reference
        >>> print(b[2])
        Two

        >>> # add a new item
        >>> b.append(Literal("Hello")) # doctest: +ELLIPSIS
        <rdflib.container.Bag object at ...>
        >>> print(g.serialize(format="turtle"))
        @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
        <BLANKLINE>
        [] a rdf:Bag ;
            rdf:_1 "One" ;
            rdf:_2 "Two" ;
            rdf:_3 "Three" ;
            rdf:_4 "Hello" .
        <BLANKLINE>
        <BLANKLINE>

    r   c                    || _         |xs
 t               | _        d| _        || _        | j                  |       | j                   j                  | j                  t        j                  t        | j                     f       y)zCreates a Container

        :param graph: a Graph instance
        :param uri: URI or Blank Node of the Container
        :param seq: the elements of the Container
        :param rtype: the type of Container, one of "Bag", "Seq" or "Alt"
        r   N)	graphr   uri_len_rtypeappend_multipleaddr   type)selfr   r   seqrtypes        p/var/www/sten-cake5-migrate2.hellocrow.space/lexinfo-master/env/lib/python3.12/site-packages/rdflib/container.py__init__zContainer.__init__.   s^     
>%'	S! 	

#((C,<=>    c                     g }t        t        |             D ]  }| |dz      }|j                  |        ddj                  |D cg c]  }|j	                          c}      z  S c c}w )N   z( %s ) )rangelenappendjoinn3)r   itemsivas        r   r"   zContainer.n3A   sa    s4y! 	AQUALLO	
 #((E#:qADDF#:;;;#:s   A%
c                     | j                   S )z Returns the URI of the container)r   r   s    r   _get_containerzContainer._get_containerK   s     xxr   c                     | j                   S )zNumber of items in container)r   r(   s    r   __len__zContainer.__len__P   s     yyr   c                     | j                   S N)r   r(   s    r   type_of_conatinerzContainer.type_of_conatinerU   s    {{r   c                     | j                   j                  | j                  |      }|st        |dd      t	        t        t              dz         }d}|D ]  }t        |j                  |d            } |S )z@Returns the 1-based numerical index of the item in the containerz is not in 	container_N )	r   
predicatesr   
ValueErrorr   strr   intreplace)r   itempredLI_INDEXr$   ps         r   indexzContainer.indexX   sq     zz$$TXXt4$DEE#c(S.) 	-AAIIh+,A	-r   c                 &   | j                         }t        |t              sJ t        t              dz   t        |      z   }|dk  s|t        |       kD  rt        |      | j                  j                  |t        |            }|r|S t        |      )z*Returns item of the container at index keyr1   r   )
r)   
isinstancer6   r5   r   r   KeyErrorr   valuer   )r   keycelem_urir%   s        r   __getitem__zContainer.__getitem__e   s     !#s###s8c>CH,!8sSY3-JJQx 01H3-r   c                    t        |t              sJ | j                         }t        t              dz   t        |      z   }|dk  s|t        |       kD  rt        |      | j                  j                  |t        |      |f       y)zJSets the item at index key or predicate rdf:_key of the container to valuer1   r   N)
r>   r6   r)   r5   r   r   r?   r   setr   )r   rA   r@   rB   rC   s        r   __setitem__zContainer.__setitem__t   so     #s###!s8c>CH,!8sSY3-

6(+U34r   c                    t        |t              sJ |dk  s|t        |       kD  rt        |      | j                  }| j
                  }t        t              dz   t        |      z   }|j                  |t        |      df       t        |dz   t        |       dz         D ]  }t        t              dz   t        |      z   }|j                  |t        |            }|j                  |t        |      |f       t        t              dz   t        |dz
        z   }|j                  |t        |      |f        | xj                  dz  c_        y)z6Removing the item with index key or predicate rdf:_keyr   r1   Nr   )r>   r6   r   r?   r   r   r5   r   remover   r   r@   r   r   )r   rA   r   r0   rC   jr%   s          r   __delitem__zContainer.__delitem__   s    #s###!8sSY3-

HH	s8c>CH,i!1489sQwD	A. 	8A3x#~A.HIvh'78ALL)VH%5q9:3x#~AE
2HIIy&"2A67	8 			Q	r   c                    g }| j                   }d}	 t        t              dz   t        |      z   }|t        |      df| j                  v r:|dz  }|j                  | j                  j                  |t        |                   n	 |S v)z,Returns a list of all items in the containerr   r1   N)r   r5   r   r   r   r    r@   )r   l_r0   r$   rC   s        r   r#   zContainer.items   s     HH	3x#~A.H6(+T2djj@Q		$****9fX6FGH	 r   c                     | j                   }d}	 t        t              dz   t        |      z   }|t        |      d f| j                  v r|dz  }n|dz
  S D)Nr   r1   )r   r5   r   r   r   )r   r0   r$   rC   s       r   endzContainer.end   sZ     HH	3x#~A.H6(+T2djj@Q1u r   c                     | j                         }t        t              dz   t        |dz         z   }| j                  }| j                  j                  |t        |      |f       | xj                  dz  c_        | S )z'Adding item to the end of the containerr1   r   )rO   r5   r   r   r   r   r   r   )r   r8   rO   rC   r0   s        r   r    zContainer.append   s`     hhjs8c>CaL0HH	

	6(#3T:;		Q	r   c                 
   | j                         }| j                  }|D ]a  }|dz  }| xj                  dz  c_        t        t              dz   t        |      z   }| j
                  j                  |t        |      |f       c | S )zSAdding multiple elements to the container to the end which are in python list otherr   r1   )rO   r   r   r5   r   r   r   r   )r   otherrO   r0   r8   rC   s         r   r   zContainer.append_multiple   sx     hhjHH	 	@D1HCIINI3x#~C0HJJNNIvh'7>?	@ r   c                    | j                   }| j                  }d}	 t        t              dz   t        |      z   }|t	        |      df| j                  v r#|j                  |t	        |      df       |dz  }nn]d| _        | S )z(Removing all elements from the containerr   r1   Nr   )r   r   r5   r   r   rI   r   )r   r0   r   r$   rC   s        r   clearzContainer.clear   s     HH	

3x#~A.H6(+T2djj@i)94@AQ  	r   N)__name__
__module____qualname____doc__r   r"   r)   r+   r.   r<   rD   rG   rK   r#   rO   r    r   rT    r   r   r   r      sU    #J (* ?&<

 
5( 	r   r   c                       e Zd ZdZg fdZy)r   z5Unordered container (no preference order of elements)c                 6    t         j                  | |||d       y )Nr   r   r   r   r   r   r   s       r   r   zBag.__init__       4S%8r   N)rU   rV   rW   rX   r   rY   r   r   r   r      s    ?') 9r   r   c                       e Zd Zg fdZd Zy)r
   c                 6    t         j                  | |||d       y )Nr
   r\   r]   s       r   r   zAlt.__init__   r^   r   c                     t        |       dk(  r
t               t        dt        |             }| j                  |      }|S )Nr   r   )r   r   r   rD   )r   r;   r8   s      r   anyonez
Alt.anyone   s;    t9>$&&3t9%A##A&DKr   N)rU   rV   rW   r   rb   rY   r   r   r
   r
      s    ') 9r   r
   c                       e Zd Zg fdZd Zy)r	   c                 6    t         j                  | |||d       y )Nr	   r\   r]   s       r   r   zSeq.__init__   r^   r   c                 (   t        |t              sJ |dk  s|t        |       dz   kD  rt        d      |t        |       dz   k(  r| j	                  |       | S t        t        |       |dz
  d      D ]  }| j                         }t        t              dz   t        |      z   }| j                  j                  |t        |            }| j                  j                  |t        |      |f       t        t              dz   t        |dz         z   }| j                  j                  |t        |      |f        t        t              dz   t        |      z   }| j                  j                  t        |      |f       | xj                  dz  c_        | S )Nr   r   z1Invalid Position for inserting element in rdf:Seqr1   )r>   r6   r   r4   r    r   r)   r5   r   r   r@   r   rI   r   r   )r   posr8   rJ   r0   rC   r%   elem_uri_poss           r   add_at_positionzSeq.add_at_position   sT   #s###!8sSY]*PQQ#d)a-KK  3t9cAgr2 A //1	s8c>CF2JJ$$Yx0@A

!!9fX.>"BCs8c>CAJ6

	6(+;Q?@A s8c>CH4LJJNNIvl';TBCIINIr   N)rU   rV   rW   r   ri   rY   r   r   r	   r	      s    ') 9r   r	   c                       e Zd ZddZd Zy)r   c                     || _         y r-   message)r   rm   s     r   r   zNoElementException.__init__  s	    r   c                     | j                   S r-   rl   r(   s    r   __str__zNoElementException.__str__  s    ||r   N)zrdf:Alt Container is empty)rU   rV   rW   r   ro   rY   r   r   r   r   
  s    r   r   N)rdflib.namespacer   rdflib.termr   r   randomr   __all__objectr   r   r
   r	   	Exceptionr   rY   r   r   <module>rv      sR      % 
BR Rj9) 9
) 
) 2 r   