python - Python-搜索两个关键字列表
问题描述
我怎样才能在两个列表上应用模糊搜索,这可以给我下面的输出。这两个列表如下:
list_of_keys=['azure', 'job', 'matlab', 'javascript', 'http', 'android', 'amazon', 'apache spark']
result=['apache http server', 'angularjs', 'azure bot service', 'amazon s3', 'android sdk', 'android studio', 'amazon cloudfront']
所需输出:
简历中的 1 个单词:apache spark,JSON 数据中的单词:apache http 服务器
简历中的 2 个单词:amazon,JSON 数据中的单词:amazon s3,amazon cloudfront
简历中的 3 个单词:http,JSON 数据中的单词:apache http 服务器
我正在寻找一种模糊的搜索方法。我想要的是两个列表中是否有任何匹配,例如,如果“apache spark”与结果列表“apache http server”匹配,那么它应该作为输出打印:来自简历的单词:apache spark,来自 JSON 数据的单词:apache http server . 同样,如果 amazon 匹配,那么它应该打印为输出:简历中的单词:amazon,JSON 数据中的单词:amazon s3,amazon cloudfront,并且还显示分数/值。我一直在互联网上搜索,但找不到任何东西。您在这方面的帮助将不胜感激。
我使用了这种简单的方法:
for item in list_of_keys:
for item1 in result:
if item in item1:
print("Word from Resume: ", item, ", Word from JSON data: ", item1)
print ("****************\n")
我使用的第二种方法,但它没有从第二个列表中搜索任何内容:
以下代码适用于无法正常工作的 FuzzyWuzzy Search
def match_term(term, list_of_keys, min_score=0):
# -1 score in case I don't get any matches
max_score = -1
# return empty for no match
max_name = ''
# iterate over all names in the other
for term2 in list_of_keys:
# find the fuzzy match score
score = fuzz.token_sort_ratio(term, term2)
# checking if I am above my threshold and have a better score
if (score > min_score) & (score > max_score):
max_name = term2
max_score = score
return (max_name, max_score)
# list for dicts for easy dataframe creation
dict_list = []
#iterating over the sales file
for name in list_of_keys:
#use the defined function above to find the best match, also set the threshold to a chosen #
match = match_term(name, result, 94)
#new dict for storing data
dict_ = {}
dict_.update({'Resume': name})
dict_.update({'JSON Data': match[0]})
dict_.update({'score': match[1]})
dict_list.append(dict_)
print(dict_list)
解决方案
推荐阅读
- python - 错误:不允许使用 `tf.Tensor` 作为 Python `bool`:AutoGraph 确实转换了此函数
- c# - 在.Net中创建大型未知json的实体类
- javascript - 在 JavaScript 中合并两种状态的最有效方法是什么
- c# - 无法在 c# 中打印来自同一类的属性
- google-apps-script - 如何优化达到运行时间限制的代码?
- html - 更改嵌入文本的文本属性
- php - Wordpress 更改联系表格 7 html 输出
- python - 使用 Tensorflow、Pandas 和梯度下降优化器设置约束优化
- r - 使用用户创建函数中的文本作为从其他数据框创建数据框的基础
- reactjs - 如何使用 jest 测试类方法?