
    Pi                         d dl Z d dlmZ d dlmZ d dlmZmZ g dZ G d d          Z	 G d d	e	          Z
 G d
 de	          Z G d de	          Z G d de          ZdS )    N)randint)RDF)BNodeURIRef)	ContainerBagSeqAltNoElementExceptionc                   r    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d ZdS )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:

    ```python
    >>> 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                     || _         |pt                      | _        d| _        || _        |                     |           | j                             | j        t          j        t          | j                 f           dS )zCreates a Container

        Args:
            graph: a Graph instance
            uri: URI or Blank Node of the Container
            seq: the elements of the Container
            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        d/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/rdflib/container.py__init__zContainer.__init__2   sj     
>%''	S!!! 	
#(C,<=>>>>>    c                     g }t          t          |                     D ]"}| |dz            }|                    |           #dd                    d |D                       z  S )N   z( %s ) c                 6    g | ]}|                                 S  )n3).0as     r   
<listcomp>z Container.n3.<locals>.<listcomp>L   s     #:#:#:qADDFF#:#:#:r   )rangelenappendjoin)r   itemsivs       r   r    zContainer.n3F   sh    s4yy!! 	 	AQUALLOOOO#((#:#:E#:#:#:;;;;r   c                     | j         S )z Returns the URI of the container)r   r   s    r   _get_containerzContainer._get_containerN   s     xr   c                     | j         S )zNumber of items in container)r   r,   s    r   __len__zContainer.__len__S   s     yr   c                 H    t          j        dt          d           | j        S )Nzardflib.container.Container.type_of_conatiner is deprecated. Use type_of_container method instead.   )
stacklevel)warningswarnDeprecationWarningr   r,   s    r   type_of_conatinerzContainer.type_of_conatinerX   s0    4		
 	
 	
 	
 {r   c                     | j         S N)r   r,   s    r   type_of_containerzContainer.type_of_containera   s
    {r   c                    | j                             | j        |          }|st          |dd          t	          t          t                    dz             }d}|D ]%}t          |                    |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.indexd   s     z$$TXt44 	F$$$DEEE#c((S.)) 	- 	-AAIIh++,,AAr   c                 l   |                                  }t          |t                    sJ t          t                    dz   t          |          z   }|dk    s|t          |           k    rt          |          | j                            |t          |                    }|r|S t          |          )z*Returns item of the container at index keyr<   r   )
r-   
isinstancerA   r@   r   r%   KeyErrorr   valuer   )r   keycelem_urir*   s        r   __getitem__zContainer.__getitem__q   s     !!#s#####s88c>CHH,!88sSYY3--JQx 0 011 	 H3--r   c                 N   t          |t                    sJ |                                 }t          t                    dz   t          |          z   }|dk    s|t          |           k    rt          |          | j                            |t          |          |f           dS )zJSets the item at index key or predicate rdf:_key of the container to valuer<   r   N)
rI   rA   r-   r@   r   r%   rJ   r   setr   )r   rL   rK   rM   rN   s        r   __setitem__zContainer.__setitem__   s     #s#####!!s88c>CHH,!88sSYY3--
6(++U344444r   c                     t          |t                    sJ |dk    s|t          |           k    rt          |          | j        }| j        }t          t                    dz   t          |          z   }|                    |t          |          df           t          |dz   t          |           dz             D ]}t          t                    dz   t          |          z   }|                    |t          |                    }|                    |t          |          |f           t          t                    dz   t          |dz
            z   }|                    |t          |          |f           | xj        dz  c_        dS )z6Removing the item with index key or predicate rdf:_keyr   r<   Nr   )rI   rA   r%   rJ   r   r   r@   r   remover   r$   rK   r   r   )r   rL   r   r;   rN   jr*   s          r   __delitem__zContainer.__delitem__   sX    #s#####!88sSYY3--
H	s88c>CHH,i!1!148999sQwD		A.. 	8 	8A3xx#~A.HIvh'7'788ALL)VH%5%5q9:::3xx#~AE

2HIIy&"2"2A67777		Q				r   c                 $   g }| j         }d}	 t          t                    dz   t          |          z   }|t          |          df| j        v rA|dz  }|                    | j                            |t          |                               nn|S )z,Returns a list of all items in the containerr   Tr<   N)r   r@   r   r   r   r&   rK   )r   l_r;   r)   rN   s        r   r(   zContainer.items   s     H		3xx#~A.H6(++T2dj@@Q		$***9fX6F6FGGHHHH	 	r   c                     | j         }d}	 t          t                    dz   t          |          z   }|t          |          d f| j        v r|dz  }n|dz
  S L)Nr   Tr<   )r   r@   r   r   r   )r   r;   r)   rN   s       r   endzContainer.end   sd     H		3xx#~A.H6(++T2dj@@Q1u	r   c                    |                                  }t          t                    dz   t          |dz             z   }| j        }| j                            |t          |          |f           | xj        dz  c_        | S )z'Adding item to the end of the containerr<   r   )rZ   r@   r   r   r   r   r   r   )r   rC   rZ   rN   r;   s        r   r&   zContainer.append   sm     hhjjs88c>CaLL0H	
	6(#3#3T:;;;		Q		r   c                    |                                  }| j        }|D ]h}|dz  }| xj        dz  c_        t          t                    dz   t          |          z   }| j                            |t          |          |f           i| S )zSAdding multiple elements to the container to the end which are in python list otherr   r<   )rZ   r   r   r@   r   r   r   r   )r   otherrZ   r;   rC   rN   s         r   r   zContainer.append_multiple   s     hhjjH	 	@ 	@D1HCIINII3xx#~C0HJNNIvh'7'7>????r   c                    | j         }| j        }d}	 t          t                    dz   t          |          z   }|t	          |          df| j        v r+|                    |t	          |          df           |dz  }nnmd| _        | S )z(Removing all elements from the containerr   Tr<   Nr   )r   r   r@   r   r   rT   r   )r   r;   r   r)   rN   s        r   clearzContainer.clear   s     H	
	3xx#~A.H6(++T2dj@@i)9)94@AAAQ	 	r   N)__name__
__module____qualname____doc__r   r    r-   r/   r6   r9   rG   rO   rR   rV   r(   rZ   r&   r   r_   r   r   r   r   r   
   s       % %N (* ? ? ? ?(< < <  
  
           
5 
5 
5  (     	 	 	      r   r   c                       e Zd ZdZg fdZdS )r   z5Unordered container (no preference order of elements)c                 B    t                               | |||d           d S )Nr   r   r   r   r   r   r   s       r   r   zBag.__init__   $    4S%88888r   N)r`   ra   rb   rc   r   r   r   r   r   r      s1        ??') 9 9 9 9 9 9r   r   c                       e Zd Zg fdZd ZdS )r
   c                 B    t                               | |||d           d S )Nr
   rf   rg   s       r   r   zAlt.__init__   rh   r   c                     t          |           dk    rt                      t          dt          |                     }|                     |          }|S )Nr   r   )r%   r   r   rO   )r   rF   rC   s      r   anyonez
Alt.anyone   sJ    t99>>$&&&3t99%%A##A&&DKr   N)r`   ra   rb   r   rl   r   r   r   r
   r
      s:        ') 9 9 9 9    r   r
   c                       e Zd Zg fdZd ZdS )r	   c                 B    t                               | |||d           d S )Nr	   rf   rg   s       r   r   zSeq.__init__   rh   r   c                    t          |t                    sJ |dk    s|t          |           dz   k    rt          d          |t          |           dz   k    r|                     |           nft          t          |           |dz
  d          D ]}|                                 }t          t                    dz   t          |          z   }| j	        
                    |t          |                    }| j	                            |t          |          |f           t          t                    dz   t          |dz             z   }| j	                            |t          |          |f           t          t                    dz   t          |          z   }| j	                            |t          |          |f           | xj        dz  c_        | S )Nr   r   z1Invalid Position for inserting element in rdf:Seqr<   )rI   rA   r%   r?   r&   r$   r-   r@   r   r   rK   r   rT   r   r   )r   posrC   rU   r;   rN   r*   elem_uri_poss           r   add_at_positionzSeq.add_at_position   s   #s#####!88sSYY]**PQQQ#d))a-KK3t99cAgr22 A A //11	s88c>CFF2J$$Yx0@0@AA
!!9fX.>.>"BCCCs88c>CAJJ6
	6(+;+;Q?@@@@s88c>CHH4LJNNIvl';';TBCCCIINIIr   N)r`   ra   rb   r   rs   r   r   r   r	   r	      s:        ') 9 9 9 9    r   r	   c                       e Zd ZddZd ZdS )r   rdf:Alt Container is emptyc                     || _         d S r8   message)r   rx   s     r   r   zNoElementException.__init__  s    r   c                     | j         S r8   rw   r,   s    r   __str__zNoElementException.__str__  s
    |r   N)ru   )r`   ra   rb   r   rz   r   r   r   r   r     s7               r   r   )r3   randomr   rdflib.namespacer   rdflib.termr   r   __all__r   r   r
   r	   	Exceptionr   r   r   r   <module>r      s8                      % % % % % % % %
B
B
BZ Z Z Z Z Z Z Zz9 9 9 9 9) 9 9 9
 
 
 
 
) 
 
 
    )   2         r   