Skip to content

Traverse Engine

TraverseEngine

Update the current cursor by following the first of the neighbors that points to the current cursor. Possible use cases to filter parameter: a. traverse.get_neighbors(..., filter=custom_filter) -> The custom_filter will be applied to Links b. traverse.get_neighbors(..., filter=(custom_filter1, custom_filter2)) -> The custom_filter1 will be applied to Links and custom_filter2 will be applied to Targets c. traverse.get_neighbors(..., filter=(None, custom_filter2)) -> The custom_filter2 will only be applied to Targets. This way there is no filter to Links d. traverse.get_neighbors(..., filter=(custom_filter1, None)) -> The custom_filter1 will be applied to Links. This case is equal case a

Other Parameters:

Name Type Description
link_type str

Filter links if named_type matches with this parameter.

cursor_position int

Sets the position of the cursor, return the links after this position.

target_type str

Filter links if one of the targets matches with this parameter.

filter tuple(Callable[[Dict], bool], Callable[[Dict], bool])

Tuple containing filter function for links at pos 0 and filter function for targets at pos 1. Used to filter the results after applying all other filters.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: The current cursor. A Python dict with all atom data.

get()

Returns the current cursor.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: The current cursor. A Python dict with all atom data.

Returns all links that have the current cursor as one of their targets, that is, any links that point to the cursor.

Other Parameters:

Name Type Description
link_type str

Filter links if named_type matches with this parameter.

cursor_position int

Sets the position of the cursor, return the links after this position.

target_type str

Filter links if one of the targets matches with this parameter.

filter Callable[[Dict], bool]

Function used to filter the results after applying all other filters.

chunk_size int

Chunk size. Defaults to 500.

Returns:

Name Type Description
Iterator Iterator

An iterator that contains the links that match the criteria.

Examples:

>>> def has_score(atom):
        if 'score' in atom and score > 0.5:
            return True
        return False
>>> links = traverse_engine.get_links(
        link_type='Ex',
        cursor_position=2,
        target_type='Sy',
        filter=has_score
    )
>>> next(links)

get_neighbors(**kwargs)

Get all of "neighbors" that pointing to current cursor. Possible use cases to filter parameter: a. traverse.get_neighbors(..., filter=custom_filter) -> The custom_filter will be applied to Links b. traverse.get_neighbors(..., filter=(custom_filter1, custom_filter2)) -> The custom_filter1 will be applied to Links and custom_filter2 will be applied to Targets c. traverse.get_neighbors(..., filter=(None, custom_filter2)) -> The custom_filter2 will only be applied to Targets. This way there is no filter to Links d. traverse.get_neighbors(..., filter=(custom_filter1, None)) -> The custom_filter1 will be applied to Links. This case is equal case a

Other Parameters:

Name Type Description
link_type str

Filter links if named_type matches with this parameter.

cursor_position int

Sets the position of the cursor, return the links after this position.

target_type str

Filter links if one of the targets matches with this parameter.

filter tuple(Callable[[Dict], bool], Callable[[Dict], bool])

Tuple containing filter function for links at pos 0 and filter function for targets at pos 1. Used to filter the results after applying all other filters.

Returns:

Name Type Description
Iterator Iterator

An iterator that contains the neighbors that match the criteria.

Examples:

>>> neighbors = traverse_engine.get_neighbors(
        link_type='Ex',
        cursor_position=2,
        target_type='Sy',
        filter=(link_filter, target_filter)
    )
>>> next(neighbors)

goto(handle)

Reset current cursor to the passed handle.

Parameters:

Name Type Description Default
handle str

The handle of the atom to go to.

required

Raises:

Type Description
AtomDoesNotExist

If the corresponding atom doesn't exist.

Returns:

Type Description
Dict[str, Any]

Dict[str, Any]: The current cursor. A Python dict with all atom data.

Examples:

>>> traverse_engine.goto('asd1234567890')
>>> {
        'handle': 'asd1234567890',
        'type': 'AI,
        'composite_type_hash': 'd99asd1234567890',
        'name': 'snet',
        'named_type': 'AI'
    }