jina.types.arrays.traversable

class jina.types.arrays.traversable.TraversableSequence[source]

Bases: object

A mixin used for traversing a Sequence[Traversable].

A mixin used for traversing a Sequence[Traversable].

traverse(traversal_paths)[source]

Return an Iterator of :class:TraversableSequence of the leaves when applying the traversal_paths. Each :class:TraversableSequence is either the root Documents, a ChunkArray or a MatchArray.

Parameters

traversal_paths (Iterable[str]) – a list of string that represents the traversal path

Yield

:class:TraversableSequence of the leaves when applying the traversal_paths.

Example on traversal_paths:

  • [r]: docs in this TraversableSequence

  • [m]: all match-documents at adjacency 1

  • [c]: all child-documents at granularity 1

  • [cc]: all child-documents at granularity 2

  • [mm]: all match-documents at adjacency 2

  • [cm]: all match-document at adjacency 1 and granularity 1

  • [r, c]: docs in this TraversableSequence and all child-documents at granularity 1

Return type

Iterable[TraversableSequence]

traverse_flattened_per_path(traversal_paths)[source]

Returns a flattened :class:TraversableSequence per path in :param:traversal_paths with all Documents, that are reached by the path.

Parameters

traversal_paths (Iterable[str]) – a list of string that represents the traversal path

Yield

:class:TraversableSequence containing the document of all leaves per path.

Return type

Iterable[TraversableSequence]

traverse_flatten(traversal_paths)[source]

Returns a single flattened :class:TraversableSequence with all Documents, that are reached via the :param:traversal_paths.

Warning

When defining the :param:traversal_paths with multiple paths, the returned :class:Documents are determined at once and not on the fly. This is a different behavior then in :method:traverse and :method:traverse_flattened_per_path!

Parameters

traversal_paths (Iterable[str]) – a list of string that represents the traversal path

Return type

TraversableSequence

Returns

a singel :class:TraversableSequence containing the document of all leaves when applying the traversal_paths.