예제 #1
0
def _load_classes(fname, corpus, split_mapping=None):
    return load_classes_txt(fname, corpus, split=split_mapping)
예제 #2
0
def _load_classes(fname, corpus, split_mapping=None):
    return load_classes_txt(fname, corpus, split=split_mapping)
예제 #3
0
파일: test_nlp.py 프로젝트: bootphon/tde
def test_collapse():
    is1 = [Interval(0, 1), Interval(2,3),
           Interval(4, 5)]
    assert(collapse(is1) == is1)
    is2 = [Interval(0, 1), Interval(1,2)]
    assert(collapse(is2) == [Interval(0, 2)])
    is3 = [Interval(0, 1), Interval(2, 3),
           Interval(0, 1.5)]
    assert(collapse(is3) == [Interval(0, 1.5),
                                     Interval(2,3)])
    is4 = [Interval(0, 1), Interval(2, 3),
           Interval(0, 10)]
    assert(collapse(is4) == [Interval(0.,10)])

corpus = load_corpus_txt('tests/mockdata/tiny.phn')
disc_clsdict = load_classes_txt('tests/mockdata/tiny.classes', corpus)
gold_clsdict = load_classes_txt('tests/mockdata/tiny.classes', corpus)

def test_cover():
    assert(cover(disc_clsdict) == 8.0)
    assert(cover(gold_clsdict) == 8.0)

def test_coverage():
    assert(coverage(disc_clsdict, gold_clsdict) == 1.0)

def test_ued():
    assert(ued('kitten', 'sitting') == 3)

def test_ned():
    assert(ned('kitten', 'sitting') == 3/7)
예제 #4
0
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_txt(fname, corpus, split=split_mapping)
        disc, errors = load_classes_txt(fname, corpus, split=None)
        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
예제 #5
0
from tde.util.reader import load_corpus_txt, load_classes_txt


def test_collapse():
    is1 = [Interval(0, 1), Interval(2, 3), Interval(4, 5)]
    assert (collapse(is1) == is1)
    is2 = [Interval(0, 1), Interval(1, 2)]
    assert (collapse(is2) == [Interval(0, 2)])
    is3 = [Interval(0, 1), Interval(2, 3), Interval(0, 1.5)]
    assert (collapse(is3) == [Interval(0, 1.5), Interval(2, 3)])
    is4 = [Interval(0, 1), Interval(2, 3), Interval(0, 10)]
    assert (collapse(is4) == [Interval(0., 10)])


corpus = load_corpus_txt('tests/mockdata/tiny.phn')
disc_clsdict = load_classes_txt('tests/mockdata/tiny.classes', corpus)
gold_clsdict = load_classes_txt('tests/mockdata/tiny.classes', corpus)


def test_cover():
    assert (cover(disc_clsdict) == 8.0)
    assert (cover(gold_clsdict) == 8.0)


def test_coverage():
    assert (coverage(disc_clsdict, gold_clsdict) == 1.0)


def test_ued():
    assert (ued('kitten', 'sitting') == 3)