python - 搜索词的字符串相似度分数

标签 python

下面是我的示例数据及其产品 ID。对于产品,如果用户从库中输入任何相关关键字,那么最相关的产品应该返回顶部链接。应该使用什么来查找字符串相似性分数。如果相似度为 80%,则得分应为 3,如果相似度为 50%,则得分应为 2,如果不匹配 1。

搜索库: {'100001': ['Bullet01', '用于各种 90° 连接和家庭维修项目的多功能连接器', 'Bullet02', '比单独使用角钉或螺钉紧固更坚固', ['Not', 'angles', 'make ','关节','更强','也','提供','一致','直','角','辛普森','强','领带','提供','宽', 'variety', 'angles', 'various', 'sizes', 'thicknesses', 'handle', 'light', 'duty', 'jobs', 'projects', 'structural', 'connection', '需要', 'Some', 'bent', 'skewed', 'match', 'project', 'For', 'outdoor', 'projects', 'moisture', 'present', 'use', 'ZMAX', 'zinc', 'coated', 'connectors', 'provide', 'extra', 'resistance', 'corrosion', 'look', 'Z', 'end', 'model', 'number', 'Versatile ', 'connector', 'various', 'connections', 'home', 'repair', 'projectsStronger', 'angled', 'nailing', 'screw', 'fastening', 'aloneHelp', 'ensure', 'joints', 'consistently', 'straight', 'strongDimensions', 'x', 'x', 'Made', 'Gauge', 'steelGalvanized', 'extra', 'corrosion', 'resistanceInstall', 'd ', 'common', 'nails', 'x', 'Strong', 'Drive', 'SD', 'screws'], 'Simpson Strong-Tie 12-Gauge Angle', 'Simpson Strong-Tie 12-Gauge角度']}

搜索词:{'100001': ['尖括号', 'l 括号']}

最佳答案

下面是如何在 python 中获得两个字符串之间的相似度

from difflib import SequenceMatcher

string1 = "hello"
string2 = "hellx"

print (SequenceMatcher(None, string1, string2).ratio())

#prints 0.8

关于python - 搜索词的字符串相似度分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36431148/

相关文章:

python - 如何删除 gridLayout (QT) 内的间距?

python - 如何对文件中的多个字符串进行多次修改并输出到新文件

python - 基于用户输入的菱形形状

python - matplotlib.widgets 按钮在类中不起作用

python - 将元组字典转换为 numpy 矩阵

python - 如何在 VS Code 中安装外部 python 库?

python - 尝试使用棉花糖使用 data_key 加载数据时出现“丢失数据”

python - python plot get_loc(self,key,method,tolerance)错误

python - Python 写的 3D OpenGL 游戏能不能好看跑得快?

python - 如何转发/填充 Pandas DataFrame 列/系列中的特定值?