由于在一些场景中,所有的字母都连在了一起,所以我们需要将字母分割成单词的形式。
1. 安装pip install -U symspellpy
2. 下载词典
curl -LJO /mammothb/symspellpy/master/symspellpy/frequency_dictionary_en_82_765.txt
curl -LJO /mammothb/symspellpy/master/symspellpy/frequency_bigramdictionary_en_243_342.txt
如果下载不了的话,也可以在CSDN上进行下载,链接为/download/herosunly/12326704。
3. 单词分割import pkg_resources
from symspellpy.symspellpy import SymSpell
sym_spell = SymSpell(max_dictionary_edit_distance=0, prefix_length=7)
dictionary_path = pkg_resources.resource_filename(
"symspellpy", "frequency_dictionary_en_82_765.txt")
sym_spell.load_dictionary(dictionary_path, term_index=0, count_index=1)
# a sentence without any spaces
input_term = "thequickbrownfoxjumpsoverthelazydog"
result = sym_spell.word_segmentation(input_term)
print("{}, {}, {}".format(result.corrected_string, result.distance_sum,
result.log_prob_sum))
作者:herosunly
如果觉得《python英语单词大全-使用Python进行英文单词分割》对你有帮助,请点赞、收藏,并留下你的观点哦!