def choose_best_action(self, list_of_words):
min_distance = 3
best_matching_action = None
tf_idf_shelve = shelve.open(self.tf_idf_shelve_file_name)
current_sentence_centroid = self.compute_list_of_words_centroid(list_of_words)
for action,centroid in tf_idf_shelve[CENTROID].iteritems():
distance = cosine(centroid,current_sentence_centroid)
print action,distance
if distance <= min_distance:
min_distance = distance
best_matching_action = action
tf_idf_shelve.close()
return current_sentence_centroid, best_matching_action, min_distance
评论列表
文章目录