Skip to content

Commit 3466899

Browse files
committed
Merge branch 'develop'
2 parents c40c52b + d932a92 commit 3466899

File tree

10 files changed

+19
-15
lines changed

10 files changed

+19
-15
lines changed

examples/mutag.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
# generated for the entities without hashing as MUTAG is a short KG.
3636
walkers=[
3737
HALKWalker(
38-
2, None, n_jobs=2, random_state=RANDOM_STATE, md5_bytes=None
38+
2,
39+
None,
40+
n_jobs=2,
41+
sampler=WideSampler(),
42+
random_state=RANDOM_STATE,
43+
md5_bytes=None,
3944
)
4045
],
4146
verbose=1,

pyrdf2vec/embedders/word2vec.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Word2Vec(Embedder):
1919
_model: The gensim.models.word2vec model.
2020
Defaults to None.
2121
kwargs: The keyword arguments dictionary.
22-
Defaults to { min_count=0, negative=20, vector_size=500 }.
22+
Defaults to { min_count=0 }.
2323
2424
"""
2525

@@ -29,8 +29,6 @@ class Word2Vec(Embedder):
2929
def __init__(self, **kwargs):
3030
self.kwargs = {
3131
"min_count": 0,
32-
"negative": 20,
33-
"vector_size": 500,
3432
**kwargs,
3533
}
3634
self._model = W2V(**self.kwargs)

pyrdf2vec/rdf2vec.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ def get_walks(self, kg: KG, entities: Entities) -> List[List[SWalk]]:
160160
ValueError: If the provided entities aren't in the Knowledge Graph.
161161
162162
"""
163-
# Avoids duplicate entities for unnecessary walk extractions.
164-
entities = list(set(entities))
165163
if kg.skip_verify is False and not kg.is_exist(entities):
166164
if kg.mul_req:
167165
asyncio.run(kg.connector.close())

pyrdf2vec/walkers/anonymous.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class AnonymousWalker(RandomWalker):
2929
Defaults to UniformSampler.
3030
with_reverse: True to extracts parents and children hops from an
3131
entity, creating (max_walks * max_walks) more walks of 2 * depth,
32-
allowing also to centralize this entity in the walks. False otherwise.
32+
allowing also to centralize this entity in the walks. False
33+
otherwise.
3334
Defaults to False.
3435
3536
"""

pyrdf2vec/walkers/community.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def _dfs(
275275
sub_walk += (pred_obj[0], pred_obj[1])
276276
d = len(sub_walk) - 1
277277
walks.append(sub_walk)
278-
return list(set(walks))
278+
return list(walks)
279279

280280
def extract(
281281
self, kg: KG, entities: Entities, verbose: int = 0

pyrdf2vec/walkers/halk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def _extract(self, kg: KG, entity: Vertex) -> EntityWalks:
114114
"""
115115
return super()._extract(kg, entity)
116116

117+
# flake8: noqa: C901
117118
def _post_extract(self, res: List[EntityWalks]) -> List[List[SWalk]]:
118119
"""Post processed walks.
119120

pyrdf2vec/walkers/random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def _dfs(
115115
sub_walk += (pred_obj[0], pred_obj[1])
116116
d = len(sub_walk) - 1
117117
walks.append(sub_walk)
118-
return list(set(walks))
118+
return list(walks)
119119

120120
def extract_walks(self, kg: KG, entity: Vertex) -> List[Walk]:
121121
"""Extracts random walks for an entity based on Knowledge Graph using

pyrdf2vec/walkers/split.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import os
21
import re
32
from typing import Set
43

@@ -50,6 +49,7 @@ def __attrs_post_init__(self):
5049
if self.func_split is None:
5150
self.func_split = self.basic_split
5251

52+
# flake8: noqa: C901
5353
def basic_split(self, walks: List[Walk]) -> Set[SWalk]:
5454
"""Splits vertices of random walks for an entity based. To achieve
5555
this, each vertex (except the root node) is split according to symbols
@@ -77,8 +77,10 @@ def basic_split(self, walks: List[Walk]) -> Set[SWalk]:
7777
"""
7878
canonical_walks: Set[SWalk] = set()
7979
for walk in walks:
80-
tmp_vertices = []
81-
canonical_walk = [] if self.with_reverse else [walk[0].name]
80+
tmp_vertices = [] # type: ignore
81+
canonical_walk = []
82+
if self.with_reverse:
83+
canonical_walk = [walk[0].name]
8284
for i, _ in enumerate(walk[1::], 1):
8385
vertices = []
8486
if "http" in walk[i].name:

tests/walkers/test_anonymous.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ def test_extract(
6969
else:
7070
assert len(walks) <= max_walks
7171
for walk in walks:
72-
assert not walk[0].isnumeric()
73-
for obj in walk[2::2]:
72+
for obj in walk[1::2]:
7473
assert obj.isnumeric()
7574
if not with_reverse:
7675
assert walk[0] == root

tests/walkers/test_halk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
MAX_DEPTHS = range(15)
3030
KGS = [KG_LOOP, KG_CHAIN]
31-
MAX_WALKS = [None, 0, 1, 2, 3, 4, 5]
31+
MAX_WALKS = [None, 1, 2, 3, 4, 5]
3232
ROOTS_WITHOUT_URL = ["Alice", "Bob", "Dean"]
3333
WITH_REVERSE = [False, True]
3434

0 commit comments

Comments
 (0)