refactor(typo-generator): 调整词典文件路径获取方式以提高通用性
将 `dict.txt` 的路径获取方式从依赖 `rjieba` 包的相对路径改为基于项目根目录的相对路径。这避免了因 `rjieba` 包内部结构变化而导致路径失效的问题,增强了代码的健壮性和可移植性。
This commit is contained in:
@@ -254,7 +254,8 @@ class ChineseTypoGenerator:
|
|||||||
all_combinations = itertools.product(*candidates)
|
all_combinations = itertools.product(*candidates)
|
||||||
|
|
||||||
# 获取rjieba词典和词频信息
|
# 获取rjieba词典和词频信息
|
||||||
dict_path = os.path.join(os.path.dirname(rjieba.__file__), "dict.txt")
|
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||||
|
dict_path = os.path.join(base_dir, "depends-data", "dict.txt")
|
||||||
valid_words = {} # 改用字典存储词语及其频率
|
valid_words = {} # 改用字典存储词语及其频率
|
||||||
with open(dict_path, encoding="utf-8") as f:
|
with open(dict_path, encoding="utf-8") as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
|
|||||||
Reference in New Issue
Block a user