pyrdf2vec.walkers.random module

class pyrdf2vec.walkers.random.RandomWalker(max_depth, max_walks=None, sampler=NOTHING, n_jobs=None, *, with_reverse=False, random_state=None, md5_bytes=8)

Bases: pyrdf2vec.walkers.walker.Walker

Random walking strategy which extracts walks from a root node using the Depth First Search (DFS) algorithm if a maximum number of walks is specified, otherwise the Breadth First Search (BFS) algorithm is used.

_is_support_remote

True if the walking strategy can be used with a remote Knowledge Graph, False Otherwise Defaults to True.

kg

The global KG used later on for the worker process. Defaults to None.

max_depth

The maximum depth of one walk.

max_walks

The maximum number of walks per entity. Defaults to None.

md5_bytes

The number of bytes to keep after hashing objects in MD5. Hasher allows to reduce the memory occupied by a long text. If md5_bytes is None, no hash is applied. Defaults to 8.

random_state

The random state to use to keep random determinism with the walking strategy. Defaults to None.

sampler

The sampling strategy. Defaults to UniformSampler.

with_reverse

True to extracts parents and children hops from an entity, creating (max_walks * max_walks) walks of 2 * depth, allowing also to centralize this entity in the walks. False otherwise. Defaults to False.

extract_walks(kg, entity)

Extracts random walks for an entity based on Knowledge Graph using the Depth First Search (DFS) algorithm if a maximum number of walks is specified, otherwise the Breadth First Search (BFS) algorithm is used.

Parameters
  • kg (KG) – The Knowledge Graph.

  • entity (Vertex) – The root node to extract walks.

Return type

List[Tuple[Any, ...]]

Returns

The list of unique walks for the provided entity.