Skip to content

AnyPath

relationalai.semantics.std.path

Selects at most one matching path per group. Built by PathPattern.any.

Methods

.per()

AnyPath.per(*args: Value) -> AnyPath

Group the matching paths.

AnyPath.paths returns at most one path per group, and this call defines the groups. Required before .paths().

Currently the only supported grouping is the pattern’s endpoint pair, .per(initial_node, final_node) with the pattern’s initial and final endpoint identifiers in that order; any other grouping raises.

Returns:

  • AnyPath - This selector (self), to allow chaining .paths().

Raises:

  • relationalai.util.error.RAIException - PathPerAppliedTwiceError if .per(...) has already been applied to this selector.

.paths()

AnyPath.paths() -> DerivedColumn

Return one PathTraversal per group.

For each group (see AnyPath.per) containing at least one matching path, yields exactly one such path; which one is arbitrary.

Unlike AllPaths.paths, the number of results is bounded by the number of groups. With the currently supported endpoint-pair grouping, it is bounded by the number of connected pairs; computing these paths is polynomial in the size of the graph, not exponential.

Returns:

Raises:

  • relationalai.util.error.RAIException - PathSelectorPerError if .per(...) is missing or not yet supported. Currently, the only supported grouping is the pattern’s endpoint pair, .per(initial_node, final_node) with the pattern’s initial and final endpoint identifiers in that order; any other grouping raises.

Examples:

reached_person = Person.ref()
p = (
m.path(Person.follows.repeat(1, 5), reached_person)
.where(Person.name == "Alice")
.any()
.per(Person, reached_person)
.paths()
)
m.where(p).select(p, p.length, reached_person.name)

Notes:

Only the path’s endpoint identifiers unify with the enclosing scope. Filters on interior nodes must be attached with PathPattern.where on the pattern; a filter referencing interior nodes placed in an enclosing Model.where cannot be routed into the path and raises.

Inheritance Hierarchy

AnyPathGroupedPathSelectorPathSelectorabc.ABC