Skip to content

Commit 5d9c04d

Browse files
committed
Solve the problem for wildcards at 'get_sememes_by_word()'
1 parent 56e833d commit 5d9c04d

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

HowNet/Standards.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import sys
44
from typing import Dict, Any
55

6-
from .pack.submit_user import util
7-
from .pack.submit_user.main import sense_similarity, word_similarity
86
from anytree import RenderTree
7+
98
from .SememeTreeParser import GenSememeTree
9+
from .pack.submit_user import util
10+
from .pack.submit_user.main import sense_similarity, word_similarity
1011

1112

1213
class HowNetDict(object):
@@ -25,7 +26,7 @@ def __init__(self, use_sim=False):
2526
self.ids = dict()
2627
with open(data_dir, 'rb') as origin_dict:
2728
word_dict = pickle.load(origin_dict)
28-
#self.max_count = len(word_dict) + 10
29+
# self.max_count = len(word_dict) + 10
2930
for key in word_dict:
3031
now_dict = word_dict[key]
3132
en_word = now_dict["en_word"].strip()
@@ -59,9 +60,11 @@ def __getitem__(self, item):
5960
:param item: target word.
6061
:return:(List) candidates HowNet annotation, if the target word does not exist, return an empty list.
6162
"""
62-
if item == "I WANT ALL!" or item == "*":
63-
return list(self.ids.values())
6463
res = list()
64+
if item == "I WANT ALL!" or item == "*":
65+
for item in self.ids.values():
66+
res.extend(item)
67+
return res
6568
if item in self.en_map:
6669
res.extend(self.en_map[item])
6770
if item in self.ch_map:
@@ -155,8 +158,6 @@ def visualize_sememe_trees(self, word, K=None):
155158
for pre, fill, node in tree:
156159
print("%s[%s]%s" % (pre, node.role, node.name))
157160

158-
159-
160161
def get_sememes_by_word(self, word, structured=False, lang="ch", merge=False, expanded_layer=-1):
161162
"""
162163
Given specific word, you can get corresponding HowNet annotation.
@@ -194,10 +195,12 @@ def get_sememes_by_word(self, word, structured=False, lang="ch", merge=False, ex
194195
else:
195196
if item[name] not in result:
196197
result[item[name]] = set()
197-
result[item[name]] |= set(self._expand_tree(GenSememeTree(item["Def"]), lang, expanded_layer))
198+
result[item[name]] |= set(
199+
self._expand_tree(GenSememeTree(item["Def"]), lang, expanded_layer))
198200
except Exception as e:
201+
print(word)
199202
print("Wrong Item:", item)
200-
#print("Generate Sememe Tree Failed for", item["No"])
203+
# print("Generate Sememe Tree Failed for", item["No"])
201204
print("Exception:", e)
202205
raise e
203206
if merge:

0 commit comments

Comments
 (0)