900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > python英语单词大全-使用Python进行英文单词分割

python英语单词大全-使用Python进行英文单词分割

时间:2021-11-10 20:27:31

相关推荐

python英语单词大全-使用Python进行英文单词分割

由于在一些场景中,所有的字母都连在了一起,所以我们需要将字母分割成单词的形式。

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。