bsfs.triple_store.base module#

class bsfs.triple_store.base.TripleStoreBase(uri: URI | None = None)#

Bases: ABC

TripleStore base class.

Use the Open method to create a new instance and to initialize the required structures.

Triple stores express a graph via its (subject, predicate, object) triples. They provides methods to add and remove triples, and to query the storage for given graph structures. The subject is always a node in the graph, whereas nodes are identifiable by a unique URI. Note that blank nodes (without an explicit URI) are not supported. The object can be another Node or a Literal value. The relation between a subject and an object is expressed via a Predicate. The graph structures are governed by a schema that defines which Node, Literal, and Predicate classes exist and how they can interact (see bsfs.schema.Schema).

abstract classmethod Open(**kwargs: Any) TripleStoreBase#

Return a TripleStoreBase instance connected to uri.

abstract commit()#

Commit the current transaction.

abstract create(node_type: Node, guids: Iterable[URI])#

Create guid nodes with type subject.

abstract exists(node_type: Node, guids: Iterable[URI]) Iterable[URI]#

Return those guids that exist and have type node_type or a subclass thereof.

abstract fetch(node_type: Node, filter: FilterExpression, fetch: FetchExpression) Iterator[Tuple[URI, str, Any]]#

Return (guid, name, value) triples where the guid is determined by the filter query and the name matches the fetch query.

abstract get(node_type: Node, filter: FilterExpression | None = None) Iterator[URI]#

Return guids of nodes of type node_type that match the filter. Return all guids of the respective type if filter is None.

is_persistent() bool#

Return True if data is stored persistently.

abstract rollback()#

Undo changes since the last commit.

abstract property schema: Schema#

Return the store’s local schema.

abstract set(node_type: Node, guids: Iterable[URI], predicate: Predicate, values: Iterable[Any])#

Add triples to the graph.

It is assumed that all of guids exist and have node_type. This method adds a triple (guid, predicate, value) for every guid in guids and each value in values (cartesian product). Note that values must have length one for unique predicates, and that currently existing values will be overwritten in this case. It also verifies that all symbols are part of the schema and that the predicate matches the node_type. Raises bsfs.errors.ConsistencyError if these assumptions are violated.

uri: URI | None = None#