pyrdf2vec.samplers.sampler module¶
- class pyrdf2vec.samplers.sampler.Sampler(inverse=False, split=False)¶
Bases:
abc.ABC
Base class of the sampling strategies.
- _is_support_remote¶
True if the sampling strategy can be used with a remote Knowledge Graph, False Otherwise Defaults to False.
- _random_state¶
The random state to use to keep random determinism with the sampling strategy. Defaults to None.
- _vertices_deg¶
The degree of the vertices. Defaults to {}.
- _visited¶
Tags vertices that appear at the max depth or of which all their children are tagged. Defaults to set.
- inverse¶
True if the inverse algorithm must be used, False otherwise. Defaults to False.
- split¶
True if the split algorithm must be used, False otherwise. Defaults to False.
- abstract fit(kg)¶
Fits the sampling strategy.
- Parameters
kg (
KG
) – The Knowledge Graph.- Raises
SamplerNotSupported – If there is an attempt to use an invalid sampling strategy to a remote Knowledge Graph.
- Return type
- abstract get_weight(hop)¶
Gets the weight of a hop in the Knowledge Graph.
- Parameters
hop (
Tuple
[Any
,Any
]) – The hop of a vertex in a (predicate, object) form to get the weight.- Returns
The weight of a given hop.
- Raises
NotImplementedError – If this method is called, without having provided an implementation.
- get_weights(hops)¶
Gets the weights of the provided hops.
- sample_hop(kg, walk, is_last_hop, is_reverse=False)¶
Samples an unvisited random hop in the (predicate, object) form, according to the weight of hops for a given walk.
- Parameters
kg (
KG
) – The Knowledge Graph.walk (
Tuple
[Any
,...
]) – The walk with one or several vertices.is_last_hop (
bool
) – True if the next hop to be visited is the last one for the desired depth, False otherwise.is_reverse (
bool
) – True to get the parent neighbors instead of the child neighbors, False otherwise. Defaults to False.
- Return type
- Returns
An unvisited hop in the (predicate, object) form.