hydra.query module

A model for language-agnostic graph pattern queries.

class hydra.query.ComparisonConstraint(*values)

Bases: Enum

One of several comparison operators.

EQUAL = Name(value='equal')
GREATER_THAN = Name(value='greaterThan')
GREATER_THAN_OR_EQUAL = Name(value='greaterThanOrEqual')
LESS_THAN = Name(value='lessThan')
LESS_THAN_OR_EQUAL = Name(value='lessThanOrEqual')
NOT_EQUAL = Name(value='notEqual')
TYPE_ = Name(value='hydra.query.ComparisonConstraint')
class hydra.query.Edge(type: Annotated[Name, 'The name of a record type, for which the edge also specifies an out- and an in- projection'], out: Annotated[object, "The field representing the out-projection of the edge. Defaults to 'out'."], in_: Annotated[object, "The field representing the in-projection of the edge. Defaults to 'in'."])

Bases: object

An abstract edge based on a record type.

class Builder(_type: 'hydra.core.Name' = None, _out: 'Optional[hydra.core.Name]' = None, _in_: 'Optional[hydra.core.Name]' = None)

Bases: object

build()
in_(in_)
out(out)
type(type)
IN = Name(value='in')
OUT = Name(value='out')
TYPE = Name(value='type')
TYPE_ = Name(value='hydra.query.Edge')
static builder()
in_: Annotated[object, "The field representing the in-projection of the edge. Defaults to 'in'."]
out: Annotated[object, "The field representing the out-projection of the edge. Defaults to 'out'."]
type: Annotated[Name, 'The name of a record type, for which the edge also specifies an out- and an in- projection']
with_in_(in_)
with_out(out)
with_type(type)
class hydra.query.GraphPattern(graph: Annotated[Name, 'The name of the component graph'], patterns: Annotated[Sequence[Pattern], 'The patterns to match within the subgraph'])

Bases: object

A query pattern which matches within a designated component subgraph.

class Builder(_graph: 'hydra.core.Name' = None, _patterns: 'Sequence[Pattern]' = None)

Bases: object

build()
graph(graph)
patterns(patterns)
GRAPH = Name(value='graph')
PATTERNS = Name(value='patterns')
TYPE_ = Name(value='hydra.query.GraphPattern')
static builder()
graph: Annotated[Name, 'The name of the component graph']
patterns: Annotated[Sequence[Pattern], 'The patterns to match within the subgraph']
with_graph(graph)
with_patterns(patterns)
class hydra.query.NodeTerm(value: T)

Bases: Node[hydra.core.Term]

A graph term; an expression which is valid in the graph being matched

class hydra.query.NodeVariable(value: T)

Bases: Node[Variable]

A query variable, not to be confused with a variable term

class hydra.query.NodeWildcard

Bases: object

An anonymous variable which we do not care to join across patterns

class hydra.query.Node_

Bases: object

NodeTerm | NodeVariable | NodeWildcard

TERM = Name(value='term')
TYPE_ = Name(value='hydra.query.Node')
VARIABLE = Name(value='variable')
WILDCARD = Name(value='wildcard')
class hydra.query.Path

Bases: object

PathStep | PathRegex | PathInverse

INVERSE = Name(value='inverse')
REGEX = Name(value='regex')
STEP = Name(value='step')
TYPE_ = Name(value='hydra.query.Path')
class hydra.query.PathEquation(left: Annotated[Path, 'The left-hand side of the equation'], right: Annotated[Path, 'The right-hand side of the equation'])

Bases: object

A declared equivalence between two abstract paths in a graph.

class Builder(_left: 'Path' = None, _right: 'Path' = None)

Bases: object

build()
left(left)
right(right)
LEFT = Name(value='left')
RIGHT = Name(value='right')
TYPE_ = Name(value='hydra.query.PathEquation')
static builder()
left: Annotated[Path, 'The left-hand side of the equation']
right: Annotated[Path, 'The right-hand side of the equation']
with_left(left)
with_right(right)
class hydra.query.PathInverse(value: T)

Bases: Node[Path]

A path given by the inverse of another path

class hydra.query.PathRegex(value: T)

Bases: Node[RegexSequence]

A path given by a regular expression quantifier applied to another path

class hydra.query.PathStep(value: T)

Bases: Node[Step]

A path given by a single step

class hydra.query.Pattern

Bases: object

PatternTriple | PatternNegation | PatternConjunction | PatternDisjunction | PatternGraph

CONJUNCTION = Name(value='conjunction')
DISJUNCTION = Name(value='disjunction')
GRAPH = Name(value='graph')
NEGATION = Name(value='negation')
TRIPLE = Name(value='triple')
TYPE_ = Name(value='hydra.query.Pattern')
class hydra.query.PatternConjunction(value: T)

Bases: Node[Sequence[Pattern]]

The conjunction (‘and’) of several other patterns

class hydra.query.PatternDisjunction(value: T)

Bases: Node[Sequence[Pattern]]

The disjunction (inclusive ‘or’) of several other patterns

class hydra.query.PatternGraph(value: T)

Bases: Node[GraphPattern]

A pattern which matches within a named subgraph

class hydra.query.PatternImplication(antecedent: Annotated[Pattern, 'The pattern which, if it matches, triggers the constraint'], consequent: Annotated[Pattern, 'The pattern which must also match when the antecedent matches'])

Bases: object

A pattern which, if it matches in a given graph, implies that another pattern must also match. Query variables are shared between the two patterns.

ANTECEDENT = Name(value='antecedent')
class Builder(_antecedent: 'Pattern' = None, _consequent: 'Pattern' = None)

Bases: object

antecedent(antecedent)
build()
consequent(consequent)
CONSEQUENT = Name(value='consequent')
TYPE_ = Name(value='hydra.query.PatternImplication')
antecedent: Annotated[Pattern, 'The pattern which, if it matches, triggers the constraint']
static builder()
consequent: Annotated[Pattern, 'The pattern which must also match when the antecedent matches']
with_antecedent(antecedent)
with_consequent(consequent)
class hydra.query.PatternNegation(value: T)

Bases: Node[Pattern]

The negation of another pattern

class hydra.query.PatternTriple(value: T)

Bases: Node[TriplePattern]

A subject/predicate/object pattern

class hydra.query.Query(variables: Annotated[Sequence[Variable], 'The variables selected by the query'], patterns: Annotated[Sequence[Pattern], 'The patterns to be matched'])

Bases: object

A SELECT-style graph pattern matching query.

class Builder(_variables: 'Sequence[Variable]' = None, _patterns: 'Sequence[Pattern]' = None)

Bases: object

build()
patterns(patterns)
variables(variables)
PATTERNS = Name(value='patterns')
TYPE_ = Name(value='hydra.query.Query')
VARIABLES = Name(value='variables')
static builder()
patterns: Annotated[Sequence[Pattern], 'The patterns to be matched']
variables: Annotated[Sequence[Variable], 'The variables selected by the query']
with_patterns(patterns)
with_variables(variables)
class hydra.query.Range(min: Annotated[int, 'The minimum value (inclusive)'], max: Annotated[int, 'The maximum value (inclusive)'])

Bases: object

A range from min to max, inclusive.

class Builder(_min: 'int' = None, _max: 'int' = None)

Bases: object

build()
max(max)
min(min)
MAX = Name(value='max')
MIN = Name(value='min')
TYPE_ = Name(value='hydra.query.Range')
static builder()
max: Annotated[int, 'The maximum value (inclusive)']
min: Annotated[int, 'The minimum value (inclusive)']
with_max(max)
with_min(min)
class hydra.query.RegexQuantifier

Bases: object

RegexQuantifierOne | RegexQuantifierZeroOrOne | RegexQuantifierZeroOrMore | RegexQuantifierOneOrMore | RegexQuantifierExactly | RegexQuantifierAtLeast | RegexQuantifierRange

AT_LEAST = Name(value='atLeast')
EXACTLY = Name(value='exactly')
ONE = Name(value='one')
ONE_OR_MORE = Name(value='oneOrMore')
RANGE = Name(value='range')
TYPE_ = Name(value='hydra.query.RegexQuantifier')
ZERO_OR_MORE = Name(value='zeroOrMore')
ZERO_OR_ONE = Name(value='zeroOrOne')
class hydra.query.RegexQuantifierAtLeast(value: T)

Bases: Node[int]

The {n,} quantifier; matches at least n occurrences

class hydra.query.RegexQuantifierExactly(value: T)

Bases: Node[int]

The {n} quantifier; matches exactly n occurrences

class hydra.query.RegexQuantifierOne

Bases: object

No quantifier; matches a single occurrence

class hydra.query.RegexQuantifierOneOrMore

Bases: object

The + quantifier; matches one or more occurrences

class hydra.query.RegexQuantifierRange(value: T)

Bases: Node[Range]

The {n, m} quantifier; matches between n and m (inclusive) occurrences

class hydra.query.RegexQuantifierZeroOrMore

Bases: object

The * quantifier; matches any number of occurrences

class hydra.query.RegexQuantifierZeroOrOne

Bases: object

The ? quanifier; matches zero or one occurrence

class hydra.query.RegexSequence(path: Annotated[Path, 'The path to which the quantifier applies'], quantifier: Annotated[RegexQuantifier, 'The quantifier'])

Bases: object

A path with a regex quantifier.

class Builder(_path: 'Path' = None, _quantifier: 'RegexQuantifier' = None)

Bases: object

build()
path(path)
quantifier(quantifier)
PATH = Name(value='path')
QUANTIFIER = Name(value='quantifier')
TYPE_ = Name(value='hydra.query.RegexSequence')
static builder()
path: Annotated[Path, 'The path to which the quantifier applies']
quantifier: Annotated[RegexQuantifier, 'The quantifier']
with_path(path)
with_quantifier(quantifier)
class hydra.query.Step

Bases: object

StepEdge | StepProject | StepCompare

COMPARE = Name(value='compare')
EDGE = Name(value='edge')
PROJECT = Name(value='project')
TYPE_ = Name(value='hydra.query.Step')
class hydra.query.StepCompare(value: T)

Bases: Node[ComparisonConstraint]

A comparison of two terms

class hydra.query.StepEdge(value: T)

Bases: Node[Edge]

An out-to-in traversal of an abstract edge

class hydra.query.StepProject(value: T)

Bases: Node[hydra.core.Projection]

A projection from a record through one of its fields

class hydra.query.TriplePattern(subject: Annotated[Node_, 'The subject of the pattern'], predicate: Annotated[Path, 'The predicate (property) of the pattern'], object: Annotated[Node_, 'The object of the pattern'])

Bases: object

A subject/predicate/object pattern.

class Builder(_subject: 'Node_' = None, _predicate: 'Path' = None, _object: 'Node_' = None)

Bases: object

build()
object(object)
predicate(predicate)
subject(subject)
OBJECT = Name(value='object')
PREDICATE = Name(value='predicate')
SUBJECT = Name(value='subject')
TYPE_ = Name(value='hydra.query.TriplePattern')
static builder()
object: Annotated[Node_, 'The object of the pattern']
predicate: Annotated[Path, 'The predicate (property) of the pattern']
subject: Annotated[Node_, 'The subject of the pattern']
with_object(object)
with_predicate(predicate)
with_subject(subject)
class hydra.query.Variable(value: T)

Bases: Node[str]

A query variable.

TYPE_ = Name(value='hydra.query.Variable')