我正在尝试对用户输入的自由文本执行拼写校正。看起来像 symspellpy 将“peditrition”更改为“media tuition”而不是儿科医生,将“news achor”更改为“news actor”而不是“news anchor”?有没有办法让 symspellpy 自动将正确的 peditrition 拼写给儿科医生而不是“media tuition
max_edit_distance_dictionary = 2
prefix_length = 7
max_edit_distance_lookup = 2
sym_spell = SymSpell(max_edit_distance_dictionary, prefix_length)
dictionary_path = pkg_resources.resource_filename("symspellpy", "frequency_dictionary_en_82_765.txt")
bigram_path = pkg_resources.resource_filename("symspellpy", "frequency_bigramdictionary_en_243_342.txt")
if not sym_spell.load_dictionary(dictionary_path, term_index=0,count_index=1):
print("Dictionary file not found")
if not sym_spell.load_bigram_dictionary(bigram_path, term_index=0,count_index=2):
print("Bigram dictionary file not found")
input_term = 'pediatrition'
suggestions = sym_spell.lookup_compound(input_term, max_edit_distance=2,
transfer_casing=True)
for suggestion in suggestions:
print(suggestion)
亲子关系
媒体学费:编辑距离 =3
儿科医生:编辑距离 =2
问题是“儿科医生”这个词只是不包含在使用的示例字典中,所以 SymSpell 不知道这些建议。这可以通过使用more complete dictionary,或者使用文本编辑器将单词添加到字典中,或者使用 CreateDictionaryEntry () 以编程方式添加单词来修复。
news acor新闻演员:编辑距离 =1
新闻锚点:编辑距离 =2
这里的问题是建议“新闻演员”的编辑距离比“新闻主播”小。SymSpell 总是选择编辑距离最小的建议,而only如果有多个建议与相同的编辑距离,则使用朴素贝叶斯概率来确定最有可能的建议。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(18条)