pyrdf2vec.walkers.walker module

class pyrdf2vec.walkers.walker.Walker(max_depth, max_walks=None, sampler=NOTHING, n_jobs=None, *, with_reverse=False, random_state=None)

Bases: abc.ABC

Base class of the walking strategies.

_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.

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. This doesn’t work with NGramWalker and WLWalker. Defaults to False.

extract(kg, entities, verbose=0)

Fits the provided sampling strategy and then calls the private _extract method that is implemented for each of the walking strategies.

Parameters
  • kg (KG) – The Knowledge Graph.

  • entities (List[str]) – The entities to be extracted from the Knowledge Graph.

  • verbose (int) – The verbosity level. 0: does not display anything; 1: display of the progress of extraction and training of walks; 2: debugging. Defaults to 0.

Return type

List[List[Tuple[str, ...]]]

Returns

The 2D matrix with its number of rows equal to the number of provided entities; number of column equal to the embedding size.

Raises

WalkerNotSupported – If there is an attempt to use an invalid walking strategy to a remote Knowledge Graph.

exception pyrdf2vec.walkers.walker.WalkerNotSupported

Bases: Exception

Base exception class for the lack of support of a walking strategy for the extraction of walks via a SPARQL endpoint server.