bsfs.schema package#

class bsfs.schema.Literal(uri: URI, parent: Literal | None, **kwargs)#

Bases: Vertex

Literal type.

parent: Literal | None#
class bsfs.schema.Node(uri: URI, parent: Node | None, **kwargs)#

Bases: Vertex

Node type.

parent: Node | None#
class bsfs.schema.Predicate(uri: URI, parent: Predicate | None, domain: Node, range: Vertex, unique: bool, **kwargs)#

Bases: _Type

Predicate base type.

child(uri: URI, domain: Node | None = None, range: Vertex | None = None, unique: bool | None = None, **kwargs)#

Return a child of the current class.

domain: Node#
range: Vertex#
unique: bool#
class bsfs.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


Alias for field number 1


Alias for field number 0


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.


>>> 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.

bsfs.schema.from_string(schema_str: str) Schema#

Load and return a Schema from a string.

bsfs.schema.to_string(schema_inst: Schema, fmt: str = 'turtle') str#

Serialize a bsfs.schema.Schema to a string. See rdflib.Graph.serialize for viable formats (default: turtle).