owmeta_core.collections module

class owmeta_core.collections.Bag(*args, no_type_decl=False, **kwargs)[source]

Bases: Container

A convenience class for working with a rdf:Bag

class owmeta_core.collections.Container(*args, no_type_decl=False, **kwargs)[source]

Bases: BaseDataObject

Base class for rdfs:Containers

Example (Bag, Alt, and Seq have the same operations):

>>> nums = Bag(ident="http://example.org/fav-numbers")
>>> nums[1] = 42
>>> nums.set_member(2, 415)
owmeta_core.statement.Statement(...)
>>> nums._3(15)
owmeta_core.statement.Statement(...)
>>> nums._2.index
2
>>> nums._1()
42
>>> nums[2]
415
>>> nums._2(6)
owmeta_core.statement.Statement(...)
>>> nums[2]
6

Note that because the set of entries in rdfs:Container is not bounded, iteration over Containers is not bounded. To iterate over a Container, it is recommended to add some external bound with itertools.islice or something like zip(range(bound), container). Where values have not been set, None will be returned.

set_member(index, item)[source]

Set a member at the given index.

If an existing value is set at the given index, then it will be replaced. Note that, as described in the RDF Primer, there is no well-formedness guarantee: in particular, some other instance of a container may declare a different value at the same index.

class owmeta_core.collections.ContainerMembershipProperty(*args, **kwargs)[source]

Bases: UnionProperty

Base class for container membership properties like rdf:_1, rdf:_2, …

owner_type

alias of BaseDataObject