Exemple #1
0
def test_simple(alignments):
    # various tests on the class OneHotProcessor
    ali1 = alignments['S01F1522_0001']
    phn1 = ali1.get_tokens_inventory()
    all_tokens = alignments.get_tokens_inventory()

    # no tokens_set specification, used the ones from ali1
    proc = onehot.OneHotProcessor(tokens=phn1)
    feat1 = proc.process(ali1)
    assert proc.ndims == feat1.ndims == len(phn1)
    assert feat1.shape == (ali1.tokens.shape[0], len(phn1))
    assert all(feat1.data.sum(axis=1) == 1)
    assert np.array_equal(feat1.times, ali1.times)
    assert set(feat1.properties['onehot'].keys()) == set(
        ['token2index', 'tokens'])

    # tokens_set used is the one from the whole alignment collection
    feat2 = onehot.OneHotProcessor(tokens=all_tokens).process(ali1)
    assert feat2.shape == (
        ali1.tokens.shape[0], len(all_tokens))
    assert all(feat2.data.sum(axis=1) != 0)
    assert np.array_equal(feat1.times, feat2.times)

    # another alignment with the whole tokens_set
    ali2 = alignments['S01F1522_0002']
    feat3 = onehot.OneHotProcessor(tokens=all_tokens).process(ali2)
    assert feat3.shape == (ali2.tokens.shape[0], len(all_tokens))
    assert all(feat3.data.sum(axis=1) == 1)
    assert feat2.shape[1] == feat3.shape[1]
    assert feat1.shape[1] < feat3.shape[1]
Exemple #2
0
def test_params(params):
    proc = onehot.OneHotProcessor(**params)
    assert params == proc.get_params()

    proc = onehot.OneHotProcessor()
    proc.set_params(**params)
    assert params == proc.get_params()
Exemple #3
0
def test_bad_tokens(alignments):
    phn = alignments.get_tokens_inventory()
    phn.remove('SIL')

    # a token missing in the provided inventory
    proc = onehot.OneHotProcessor(tokens=phn)
    with pytest.raises(ValueError):
        proc.process(alignments['S01F1522_0001'])