如何解决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 字:亚马逊,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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。