container
Classes:
-
Alt– -
Bag–Unordered container (no preference order of elements)
-
Container–A class for constructing RDF containers, as per https://www.w3.org/TR/rdf11-mt/#rdf-containers
-
NoElementException– -
Seq–
Bag
Container
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>
Parameters:
-
–grapha Graph instance
-
–uriURI or Blank Node of the Container
-
–seqthe elements of the Container
-
–rtypethe type of Container, one of “Bag”, “Seq” or “Alt”
Methods:
-
__delitem__–Removing the item with index key or predicate rdf:_key
-
__getitem__–Returns item of the container at index key
-
__len__–Number of items in container
-
__setitem__–Sets the item at index key or predicate rdf:_key of the container to value
-
append–Adding item to the end of the container
-
append_multiple–Adding multiple elements to the container to the end which are in python list other
-
clear–Removing all elements from the container
-
end– -
index–Returns the 1-based numerical index of the item in the container
-
items–Returns a list of all items in the container
-
n3– -
type_of_conatiner– -
type_of_container–
Attributes:
Source code in rdflib/container.py
__delitem__
Removing the item with index key or predicate rdf:_key
Source code in rdflib/container.py
__getitem__
Returns item of the container at index key
Source code in rdflib/container.py
__len__
__setitem__
Sets the item at index key or predicate rdf:_key of the container to value
Source code in rdflib/container.py
append
Adding item to the end of the container
Source code in rdflib/container.py
append_multiple
Adding multiple elements to the container to the end which are in python list other
Source code in rdflib/container.py
clear
Removing all elements from the container
Source code in rdflib/container.py
end
index
Returns the 1-based numerical index of the item in the container
Source code in rdflib/container.py
items
Returns a list of all items in the container
Source code in rdflib/container.py
n3
type_of_conatiner
NoElementException
Seq
Bases: Container
Methods: