drepr.models.path#

Classes

Expr(expr)

IndexExpr(val[, is_optional])

Path(steps)

RangeExpr(start, end, step)

SetIndexExpr(vals)

WildcardExpr(value[, names, module, ...])

class Expr(expr: 'str')[source]#

Bases: object

Parameters:

expr (str) –

expr: str#
class RangeExpr(start: 'Union[int, Expr]', end: 'Optional[Union[int, Expr]]', step: 'Union[int, Expr]')[source]#

Bases: object

Parameters:
start: Union[int, Expr]#
end: Optional[Union[int, Expr]]#
step: Union[int, Expr]#
is_select_all() bool[source]#
Return type:

bool

class IndexExpr(val: 'Union[str, int, Expr]', is_optional: 'bool' = False)[source]#

Bases: object

Parameters:
val: Union[str, int, Expr]#
is_optional: bool = False#
class SetIndexExpr(vals: 'Set[Union[str, int, Expr]]')[source]#

Bases: object

Parameters:

vals (Set[Union[str, int, Expr]]) –

vals: Set[Union[str, int, Expr]]#
class WildcardExpr(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

Values = '*'#
Names = '*~'#
class Path(steps: 'List[StepExpr]')[source]#

Bases: object

Parameters:

steps (List[Union[RangeExpr, IndexExpr, SetIndexExpr, WildcardExpr]]) –

steps: List[Union[RangeExpr, IndexExpr, SetIndexExpr, WildcardExpr]]#
static deserialize(raw: dict) Path[source]#

Deserialize a dictionary to get back the Path object :param raw: :return:

Parameters:

raw (dict) –

Return type:

Path

is_step_optional(step_index: int)[source]#
Parameters:

step_index (int) –

has_optional_steps() bool[source]#

Check if this path has any optional steps, an optional step is a step that the key may not appear in the data source

Return type:

bool

get_optional_steps() list[int][source]#

Get the indices of optional steps in this path in sorted order

Return type:

list[int]

has_same_or_less_optional_steps(path: Path) bool[source]#

Check if another path has the same or less optional steps as this path.

In order for two paths to share the same optional steps, any previous steps of the optional step must be the same and the number of optional steps must be the same.

In order for this path to have less optional steps than the other path, the number of optional steps must be less and the previous steps of the optional steps must be the same.

Parameters:

path (Path) –

Return type:

bool

get_nary_steps() list[int][source]#

Obtain a list of indices of steps that select more than one elements

Return type:

list[int]

to_lang_format(use_json_path: bool = False) Union[list, str][source]#

Convert this Path object into the path object in the D-REPR language

Parameters:

use_json_path (bool) – whether we should use the JSONPath or our new notation

Returns:

Return type:

Union[list, str]