def get_error_segments(self, \ correct_sentence_index, \ error_segments = None): if not self.sentences_ready: #TODO Exception here print "We do not have the correct sentences" exit(-1) correct_sentence = self.sentences_ready[correct_sentence_index] correct_sentence.norm_segments() self.sentences_ready[0].norm_segments() if len(correct_sentence.segments) != \ len(self.sentences_ready[0].segments): #TODO Exception here print "Error sentences to be compared must have the same number of frames." exit(-1) if isinstance(error_segments, list): self.error_segments = error_segments else: self.error_segments = [] correct_segments = None recognized_segments = None start_time = None confusion_region = False for frame in range(len(correct_sentence.segments)): if correct_sentence.segments[frame].score != \ self.sentences_ready[0].segments[frame].score: if not confusion_region: # print correct_sentence.segments[frame].state # print self.sentences_ready[0].segments[frame].state confusion_region = True correct_segments = [] recognized_segments = [] start_time = frame # print correct_sentence.segments[frame].state # print self.sentences_ready[0].segments[frame].state correct_segments.append(correct_sentence.segments[frame]) recognized_segments.append(self.sentences_ready[0].segments[frame]) elif confusion_region: confusion_region = False util.add_error_segment(self.error_segments, \ ErrorSegment(correct_segments,\ recognized_segments, \ start_time, \ self.file_name)) return self.error_segments
def parse_error_segment_file(self, error_segment_file): """ Expected a file like this: error_file_name;start_time;correct_segments:recognized_segments; ... And return a list with all error segments found. """ error_segments = [] for self.line in open(error_segment_file): arguments = self.line.split(';') error_segment = \ ErrorSegment(self.read_segment(arguments[2]),\ self.read_segment(arguments[3]),\ int(arguments[1]),\ arguments[0]) util.add_error_segment(error_segments, error_segment) return error_segments