Python 3.x 为什么符号拼写会发生变化;小儿科;至;媒体学”;而不是",;儿科医生;?

Python 3.x 为什么符号拼写会发生变化;小儿科;至;媒体学”;而不是",;儿科医生;?,python-3.x,spell-checking,Python 3.x,Spell Checking,我正在尝试对用户输入的自由文本执行拼写更正。这看起来像是将“小儿科”改为“媒体教学”而不是儿科医生,将“新闻主持人”改为“新闻演员”而不是“新闻主播”?有没有办法让symspellpy自动向儿科医生拼写正确的儿科医生,而不是“媒体学费”?以下是我在网上找到的一些示例的代码: max_edit_distance_dictionary = 2 prefix_length = 7 max_edit_distance_lookup = 2 sym_spell = SymSpell(max_edit_d

我正在尝试对用户输入的自由文本执行拼写更正。这看起来像是将“小儿科”改为“媒体教学”而不是儿科医生,将“新闻主持人”改为“新闻演员”而不是“新闻主播”?有没有办法让symspellpy自动向儿科医生拼写正确的儿科医生,而不是“媒体学费”?以下是我在网上找到的一些示例的代码:

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)

pediatrition

媒体教程:编辑距离=3

儿科医生:编辑距离=2

问题是“儿科医生”这个词不包含在使用过的示例词典中,所以SymSpell不知道这些建议。可以通过使用或使用文本编辑器将单词添加到词典中,或使用CreateDictionaryEntry()以编程方式添加单词来解决此问题

新闻acor

新闻参与者:编辑距离=1

新闻主播:编辑距离=2

这里的问题是,建议“新闻演员”比“新闻主播”的编辑距离小。SymSpell始终选择编辑距离最小的建议,并且仅当存在多个编辑距离相同的建议时它使用朴素贝叶斯概率来确定最可能的建议