def test_interval_errors(self): assert (check_intervals(self.d2, self.m1) == ([ FragmentToken('a', Interval(0.5, 1.5), 'm1') ], [])) assert (check_intervals(self.d4, self.m1) == ([ FragmentToken('a', Interval(0.5, 2.5), 'm1') ], []))
def load_disc(fname, corpus, split_file, truncate, verbose): with verb_print(' loading discovered classes', verbose, True, True, True): split_mapping = load_split(split_file) disc, errors = _load_classes(fname, corpus, split_mapping) if not truncate: errors_found = len(errors) > 0 if len(errors) > 100: print 'There were more than 100 interval errors found.' print 'Printing only the first 100.' print errors = errors[:100] for fragment in sorted(errors, key=lambda x: (x.name, x.interval.start)): print ' error: {0} [{1:.3f}, {2:.3f}]'.format( fragment.name, fragment.interval.start, fragment.interval.end) if not truncate and errors_found: print 'There were errors in {0}. Use option -f to'\ ' automatically skip invalid intervals.'.format(fname) sys.exit() if truncate: with verb_print(' checking discovered classes and truncating'): disc, filename_errors, interval_errors = \ truncate_intervals(disc, corpus, split_mapping) else: with verb_print(' checking discovered classes', verbose, True, True, True): filename_errors, interval_errors = \ check_intervals(disc, split_mapping) if not truncate: filename_errors = sorted(filename_errors, key=lambda x: (x.name, x.interval.start)) interval_errors = sorted(interval_errors, key=lambda x: (x.name, x.interval.start)) interval_error = len(interval_errors) > 0 filename_error = len(filename_errors) > 0 errors_found = filename_error or interval_error if interval_error: print banner('intervals found in {0} outside of valid' ' splits'.format(fname)) if len(interval_errors) > 100: print 'There were more than 100 interval errors found.' print 'Printing only the first 100.' print interval_errors = interval_errors[:100] for fragment in sorted(interval_errors, key=lambda x: (x.name, x.interval.start)): print ' error: {0} [{1:.3f}, {2:.3f}]'.format( fragment.name, fragment.interval.start, fragment.interval.end) if filename_error: print banner('unknown filenames found in {0}'.format(fname)) if len(filename_errors) > 100: print 'There were more than 100 filename errors found.' print 'Printing only the first 100.' print filename_errors = filename_errors[:100] for fragment in sorted(filename_errors, key=lambda x: (x.name, x.interval.start)): print ' error: {0}'.format(fragment.name) if not truncate and errors_found: print 'There were errors in {0}. Use option -f to automatically skip invalid intervals.'.format( fname) sys.exit() return disc
def test_bad_filename(self): assert (check_intervals(self.d3, self.m1) == ([], ['b']))
def test_good_interval(self): assert (check_intervals(self.d1, self.m1) == ([], []))
def load_disc(fname, corpus, split_file, truncate, verbose): with verb_print(' loading discovered classes', verbose, True, True, True): split_mapping = load_split(split_file) disc, errors = _load_classes(fname, corpus, split_mapping) if not truncate: errors_found = len(errors) > 0 if len(errors) > 100: print 'There were more than 100 interval errors found.' print 'Printing only the first 100.' print errors = errors[:100] for fragment in sorted(errors, key=lambda x: (x.name, x.interval.start)): print ' error: {0} [{1:.3f}, {2:.3f}]'.format( fragment.name, fragment.interval.start, fragment.interval.end) if not truncate and errors_found: print 'There were errors in {0}. Use option -f to'\ ' automatically skip invalid intervals.'.format(fname) sys.exit() if truncate: with verb_print(' checking discovered classes and truncating'): disc, filename_errors, interval_errors = \ truncate_intervals(disc, corpus, split_mapping) else: with verb_print(' checking discovered classes', verbose, True, True, True): filename_errors, interval_errors = \ check_intervals(disc, split_mapping) if not truncate: filename_errors = sorted(filename_errors, key=lambda x: (x.name, x.interval.start)) interval_errors = sorted(interval_errors, key=lambda x: (x.name, x.interval.start)) interval_error = len(interval_errors) > 0 filename_error = len(filename_errors) > 0 errors_found = filename_error or interval_error if interval_error: print banner('intervals found in {0} outside of valid' ' splits'.format(fname)) if len(interval_errors) > 100: print 'There were more than 100 interval errors found.' print 'Printing only the first 100.' print interval_errors = interval_errors[:100] for fragment in sorted(interval_errors, key=lambda x: (x.name, x.interval.start)): print ' error: {0} [{1:.3f}, {2:.3f}]'.format( fragment.name, fragment.interval.start, fragment.interval.end) if filename_error: print banner('unknown filenames found in {0}' .format(fname)) if len(filename_errors) > 100: print 'There were more than 100 filename errors found.' print 'Printing only the first 100.' print filename_errors = filename_errors[:100] for fragment in sorted(filename_errors, key=lambda x: (x.name, x.interval.start)): print ' error: {0}'.format(fragment.name) if not truncate and errors_found: print 'There were errors in {0}. Use option -f to automatically skip invalid intervals.'.format(fname) sys.exit() return disc