def Score(self, lenText): score = np.zeros(lenText) smooth_score = np.zeros(lenText) for i in range(1, lenText-1): # iterate over all wiindows (as many as num of sentences), # each can be potential segment boundary but first and last sentences maxim_i = np.maximum(0, i-self.winLength) maxim_f = np.maximum(1, i) minim = np.maximum(np.minimum(lenText, i + self.winLength), maxim_f) win_left_idx = [] win_right_idx = [] for x in range(maxim_i, maxim_f): # min and max to avoid index problems win_left_idx.append(x) for x in range(i, minim): # min and max to avoid index problems win_right_idx.append(x) if i > 1: win_l = [self.prep.speakers[win_left_idx[0] : win_left_idx[-1]], self.prep.sentLemma[win_left_idx[0] : win_left_idx[-1]]] #create win left_i else: #when i = 1 --> win_l is only the first el win_l = [[self.prep.speakers[0]], [self.prep.sentLemma[0]]] if i < lenText - 2: win_r = [self.prep.speakers[win_right_idx[0] : win_right_idx[-1] +1], self.prep.sentLemma[win_right_idx[0] : win_right_idx[-1] +1]] #create win left_i else: win_r = [[self.prep.speakers[-1]], [self.prep.sentLemma[-1]]] WC_l = self.WC(win_l) WC_r = self.WC(win_r) dist_wc = Help.Dist(WC_l, WC_r) WI_l = self.WI(win_l[1], win_l[0]) WI_r = self.WI(win_r[1], win_r[0]) dist_wi = Help.Dist(WI_l, WI_r) score[i] = dist_wc + dist_wi for i in range(1, lenText-1): temp_score = 0 #loc score for smoothing bound = self.SafeSmooth(i, len(score)) #check not to go out of size when smoothing low = bound[0] up = bound[1] for j in range(low, up): temp_score += score[j] smooth_score[i] = temp_score / (1 + self.smoothParam) return score, smooth_score
def ScoreSegment(self, segm): sum_c = [] c_idx = [] cat = Help.GenCat(self.Ns) #generate categories vector cat = cat[1:] #[0,0,0,0,0] not allowed, there's always at least one speaker #sum_c score per each cat, find min #c_idx idx of each cat, to find the cat corresp to min score for c in cat: sum_dist = Help.Dist(Help.Dstr(segm, self.Ns), Help.DstrId(self.Ns,c)) #score segments sum_c.append(sum_dist) c_idx.append(c) #c single category boolean vector used for calling dstr_id min_score = np.min(sum_c) min_cat = c_idx[np.argmin(sum_c)] # in the list of categories, take el of idx that minimizes the score return min_score, min_cat