小编典典

将相似词归为一组的好策略是什么?

redis

假设我有一个电影名称清单,其中包含拼写错误和类似这样的小变化-

 "Pirates of the Caribbean: The Curse of the Black Pearl"
 "Pirates of the carribean"
 "Pirates of the Caribbean: Dead Man's Chest"
 "Pirates of the Caribbean trilogy"
 "Pirates of the Caribbean"
 "Pirates Of The Carribean"

如何最好使用python和/或redis分组或查找此类单词集?


阅读 329

收藏
2020-06-20

共1个答案

小编典典

看看“模糊匹配”。下面的线程中的一些很棒的工具可以计算字符串之间的相似度。

我特别喜欢difflib模块

>>> get_close_matches('appel', ['ape', 'apple', 'peach', 'puppy'])
['apple', 'ape']
>>> import keyword
>>> get_close_matches('wheel', keyword.kwlist)
['while']
>>> get_close_matches('apple', keyword.kwlist)
[]
>>> get_close_matches('accept', keyword.kwlist)
['except']
2020-06-20