I am working on chatbot, This chatbot return multiple results if found . Now I have added picture column in my database , that I have to fetch and shows results in chatbot as - answer + picture. I tried to change in elif block where I am passing result[0][1]:result[0][2],
[0] -means questions , [1] - means answers and [2] - means picture names which are stored in database , previously this bot shows correct result when I modify for picture related task then it does not work. I need your help , how I can modify below code to return result as answer + picture.
def refine_result(self,result):
‘’’
if results are more than one, perform similarity measurement
‘’’
from collections import Counter
link = "\n For more information and queries please contact : "
if not result:
return "No matching result for " + self.question + "," + link
elif (len(result)==1):
result4 =[{result[0][1]: result[0][2]}]
return json.dumps(result4)
else:
occurance = []
max_occurance = ""
max_score=0
for row in result:
i=0
for word in self.clean_text.split():
if word in row[0].lower():
i=i+1
occurance.append(i)
if (i>max_score):
max_score = i
max_occurance=row[1]
if occurance.count(max_score)==1:
return max_occurance
elif max_score==1:
return "\n Multiple results found for=>" + "\n*#".join(x[0] for x in result) + "\n*# Enter the specific one.\n"
else:
final_list = []
for idx, val in enumerate(occurance):
if val == max_score:
final_list.append(result[idx][0])
return "\n Multiple results found for=> \n" +"\n*#".join(x for x in final_list) + "\n*# Enter the specific one.\n"