def match_template(self, question, templates): """ 参数:question 问题 templates 该问句匹配的所有的模板 """ # 计算每一个模板和当前模板的编辑距离 arr = ((edit_dis(question, template0), template0) for template0 in templates) # edit_dis()返回编辑距离 # 选择编辑距离最小的模板 dis, temp = min(arr) return temp
def _eva_metrics(self, trajs, batch, graph, metrics): for i, item in enumerate(batch): success = 0 traj = trajs[i] gt_traj = item["route_panoids"] ed = edit_dis(traj, gt_traj) ed = 1 - ed / max(len(traj), len(gt_traj)) target_list = list(nx.all_neighbors(graph, gt_traj[-1])) + [gt_traj[-1]] if traj[-1] in target_list: success = 1 metrics[0] += 1 metrics[2] += ed metrics[1] += nx.dijkstra_path_length(graph, traj[-1], gt_traj[-1]) if self.opts.CLS: metrics[3] += self.cal_cls(graph, traj, gt_traj) if self.opts.DTW: dtw_group = self.cal_dtw(graph, traj, gt_traj, success) for j in range(-3, 0): metrics[j] += dtw_group[j]
def match_template(self, question, templates): arr = ((edit_dis(question, template0), template0) for template0 in templates) dis, temp = min(arr) return temp