bsfs.query.ast.filter_ module#

Filter AST.

Note that it is easily possible to construct an AST that is inconsistent with a given schema. Furthermore, it is possible to construct a semantically invalid AST which that cannot be parsed correctly or includes contradicting statements. The AST nodes do not (and cannot) check such issues.

For example, consider the following AST:

>>> Any(ns.bse.collection,
...     And(
...         Equals('hello'),
...         Is('hello world'),
...         Any(ns.bse.tag, Equals('world')),
...         Any(ns.bst.label, Equals('world')),
...         All(ns.bst.label, Not(Equals('world'))),
...     )
... )

This AST has multiple issues that are not verified upon its creation: * A condition on a non-literal. * A Filter on a literal. * Conditions exclude each other * The predicate along the branch have incompatible domains and ranges.

class bsfs.query.ast.filter_.All(predicate: PredicateExpression | URI, expr: FilterExpression)#

Bases: _Branch

All (and at least one) triples match.

class bsfs.query.ast.filter_.And(*expr: FilterExpression | Iterable[FilterExpression] | Iterator[FilterExpression])#

Bases: _Agg

All conditions match.

class bsfs.query.ast.filter_.Any(predicate: PredicateExpression | URI, expr: FilterExpression)#

Bases: _Branch

Any (and at least one) triple matches.

class bsfs.query.ast.filter_.EndsWith(value: Any)#

Bases: _Value

Value ends with a given string.

class bsfs.query.ast.filter_.Equals(value: Any)#

Bases: _Value

Value matches exactly. NOTE: Value must correspond to literal type.

class bsfs.query.ast.filter_.FilterExpression#

Bases: _Expression

Generic Filter expression.

class bsfs.query.ast.filter_.GreaterThan(threshold: float, strict: bool = True)#

Bases: _Bounded

Value is (strictly) larger than threshold. Assumes a Number literal.

class bsfs.query.ast.filter_.Has(predicate: PredicateExpression | URI, count: FilterExpression | int | None = None)#

Bases: FilterExpression

Has predicate N times

count: FilterExpression#
predicate: PredicateExpression#
class bsfs.query.ast.filter_.Is(value: Any)#

Bases: _Value

Match the URI of a node.

class bsfs.query.ast.filter_.LessThan(threshold: float, strict: bool = True)#

Bases: _Bounded

Value is (strictly) smaller than threshold. Assumes a Number literal.

class bsfs.query.ast.filter_.Not(expr: FilterExpression)#

Bases: FilterExpression

Invert a statement.

expr: FilterExpression#
class bsfs.query.ast.filter_.OneOf(*expr: PredicateExpression | URI)#

Bases: PredicateExpression, Collection

A set of predicate alternatives.

The predicates’ domains must be ascendants or descendants of each other. The overall domain is the most specific one.

The predicate’s domains must be ascendants or descendants of each other. The overall range is the most generic one.

expr: Set[PredicateExpression]#
class bsfs.query.ast.filter_.Or(*expr: FilterExpression | Iterable[FilterExpression] | Iterator[FilterExpression])#

Bases: _Agg

At least one condition matches.

class bsfs.query.ast.filter_.Predicate(predicate: URI, reverse: bool | None = False)#

Bases: PredicateExpression

A single predicate.

predicate: URI#
reverse: bool#
class bsfs.query.ast.filter_.PredicateExpression#

Bases: _Expression

Generic Predicate expression.

class bsfs.query.ast.filter_.StartsWith(value: Any)#

Bases: _Value

Value begins with a given string.

class bsfs.query.ast.filter_.Substring(value: Any)#

Bases: _Value

Value matches a substring NOTE: value must be a string.