Skip to content

AnyShortestPath

relationalai.semantics.std.path

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

Methods

.per()

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

Group the matching paths.

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

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

Raises:

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

.paths()

AnyShortestPath.paths() -> DerivedColumn

Return one shortest PathTraversal per group.

For each group (see AnyShortestPath.per) containing at least one matching path, yields exactly one shortest such path. When a group has more than one shortest path, which one it yields 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_shortest()
.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

AnyShortestPathGroupedPathSelectorPathSelectorabc.ABC