Skip to content

PathTraversal

relationalai.semantics.std.path
PathTraversal = PathLibrary.Type('PathTraversal', super_types=[Hash])

A single enumerated path: a unique per-path identifier plus the nodes and edges visited.

Produced by PathPattern.all_paths, one value per matching path. Read the per-path details via its properties (each accessed on a result p):

  • p.length (Integer): the number of hops (edges) in the path.
  • p.nodes(index, concept)index (Integer), concept (semantics.frontend.core.AnyEntity): the node visited at each position, from 0 (source) to p.length (destination). Cast it back to a concept to read properties, e.g., Person(p.nodes).name.
  • p.relationships(index, relationship)index (Integer), relationship (String): the name of the relationship traversed at each 0-indexed hop, e.g. "Person.follows". For a relationship inherited from a parent concept, the name references the defining concept.
  • p.relationship_fields(index, field_index, field)index (Integer), field_index (Integer), field (semantics.frontend.core.AnyEntity): the entity-typed auxiliary fields of higher-arity edges. index is the hop; field_index is the field’s position within that edge’s relationship (source is field 0). Binary edges and value-typed (non-entity) fields produce no rows here.

The relationship at hop i traverses from p.nodes(i) to p.nodes(i+1); p.nodes and the index fields are all 0-indexed.

Examples

PathTraversal can type a relationship field like any other concept:

ShortPath = m.Relationship(f"{PathTraversal:path} is short")
p = m.path(Person.follows.repeat(1, 5)).all_paths()
m.where(p.length <= 2).define(ShortPath(p))
m.select(ShortPath.length, Person(ShortPath.nodes).name)