bsfs.schema.schema module#

class bsfs.schema.schema.Schema(predicates: Iterable[Predicate] | None = None, nodes: Iterable[Node] | None = None, literals: Iterable[Literal] | None = None)#

Bases: object

Graph schema.

Use Schema.Empty() to create a new, empty Schema rather than construct it directly.

The schema is defined by three sets: Predicates, Nodes, and Literals.

The Schema class guarantees two properties: completeness and consistency. Completeness means that the schema covers all class that are referred to by any other class in the schema. Consistency means that each class is identified by a unique URI and all classes that use that URI consequently use the same definition.

class SchemaDiff(nodes, literals, predicates)#

Bases: tuple

literals#

Alias for field number 1

nodes#

Alias for field number 0

predicates#

Alias for field number 2

classmethod Union(*args: Schema | Iterable[Schema]) Schema#

Combine multiple Schema instances into a single one. As argument, you can either pass multiple Schema instances, or a single iterable over Schema instances. Any abc.Iterable will be accepted.

Example:

>>> a, b, c = Schema.Empty(), Schema.Empty(), Schema.Empty()
>>> # multiple Schema instances
>>> Schema.Union(a, b, c)
>>> # A single iterable over Schema instances
>>> Schema.Union([a, b, c])
consistent_with(other: Schema) bool#

Checks if two schemas have different predicate, node, or literal definitions for the same uri.

diff(other: Schema) SchemaDiff#

Return node, literals, and predicates that are in self but not in other.

has_literal(lit: URI) bool#

Return True if a Literal with URI lit is part of the schema.

has_node(node: URI) bool#

Return True if a Node with URI node is part of the schema.

has_predicate(pred: URI) bool#

Return True if a Predicate with URI pred is part of the schema.

literal(uri: URI) Literal#

Return the Literal matching the uri.

literals() Iterable[Literal]#

Return an iterator over Literal classes.

node(uri: URI) Node#

Return the Node matching the uri.

nodes() Iterable[Node]#

Return an iterator over Node classes.

predicate(uri: URI) Predicate#

Return the Predicate matching the uri.

predicates() Iterable[Predicate]#

Return an iterator over Predicate classes.

predicates_at(node: Node) Iterator[Predicate]#

Return predicates that have domain node (or superclass thereof).

union(other: Schema) Schema#

Merge other and self into a new Schema. self takes precedence.