1010
1111@attr .s
1212class WideSampler (Sampler ):
13+ """Wide sampling node-centric sampling strategy which gives priority to
14+ walks containing edges with the highest degree of predicates and
15+ objects. The degree of a predicate and an object being defined by the
16+ number of predicates and objects present in its neighborhood, but also by
17+ their number of occurrence in a Knowledge Graph.
18+
19+ Attributes:
20+ _is_support_remote: True if the sampling strategy can be used with a
21+ remote Knowledge Graph, False Otherwise
22+ Defaults to False.
23+ _random_state: The random state to use to keep random determinism with
24+ the sampling strategy.
25+ Defaults to None.
26+ _vertices_deg: The degree of the vertices.
27+ Defaults to {}.
28+ _visited: Tags vertices that appear at the max depth or of which all
29+ their children are tagged.
30+ Defaults to set.
31+ inverse: True if the inverse algorithm must be used, False otherwise.
32+ Defaults to False.
33+ split: True if the split algorithm must be used, False otherwise.
34+ Defaults to False.
35+
36+ """
1337
1438 _pred_degs : DefaultDict [str , int ] = attr .ib (
1539 init = False , repr = False , factory = lambda : defaultdict (dict )
@@ -24,14 +48,16 @@ class WideSampler(Sampler):
2448 )
2549
2650 def fit (self , kg : KG ) -> None :
27- """Since the weights are uniform, this function does nothing.
51+ """Fits the sampling strategy by couting the number of available
52+ neighbors for each vertex, but also by counting the number of
53+ occurrence that a predicate and an object appears in the Knowledge
54+ Graph.
2855
2956 Args:
3057 kg: The Knowledge Graph.
3158
3259 """
3360 super ().fit (kg )
34-
3561 for vertex in kg ._vertices :
3662 if vertex .predicate :
3763 self ._neighbor_counts [vertex .name ] = len (
@@ -53,10 +79,14 @@ def get_weight(self, hop: Hop) -> float:
5379 """Gets the weight of a hop in the Knowledge Graph.
5480
5581 Args:
56- hop: The hop (pred, obj) to get the weight.
57-
82+ hop: The hop of a vertex in a (predicate, object) form to get the
83+ weight.
5884 Returns:
59- The weight for a given hop.
85+ The weight of a given hop.
86+
87+ Raises:
88+ ValueError: If there is an attempt to access the weight of a hop
89+ without the sampling strategy having been trained.
6090
6191 """
6292 if not (self ._pred_degs and self ._obj_degs and self ._neighbor_counts ):
0 commit comments