Exemplo n.º 1
0
def test_save_modified():
    filename = 'squad_v2_sample.json'
    dataset = get_dataset_obj()
    dataset.load(get_file_path(filename))

    # Reversing two times equals to original input
    composed = compose(Reverser(), Reverser())
    modified = dataset.apply(composed)

    with tempfile.TemporaryDirectory() as dirname:
        test_file_path = os.path.join(dirname, 'test')
        dataset.save(modified, test_file_path)

        assert filecmp.cmp(get_file_path(filename), test_file_path, shallow=False)
Exemplo n.º 2
0
def test_save_modified():

    dataset = CoNLL()
    dataset.load(get_file_path())

    # Reversing two times equals to original input
    composed = compose(Reverser(), Reverser())
    modified = dataset.apply(composed)

    with tempfile.TemporaryDirectory() as dirname:
        test_file_path = os.path.join(dirname, 'test.txt')
        dataset.save(modified, test_file_path)

        assert filecmp.cmp(get_file_path(), test_file_path, shallow=False)
Exemplo n.º 3
0
def test_apply_reverser():
    dataset = SampleDataset()
    dataset.load()

    modified = dataset.apply(Reverser())

    assert len(modified) == 2
    assert modified[0].split()[0] == "gninnaM"
Exemplo n.º 4
0
def test_modify_mask_non_ne():
    dataset = CoNLL()
    dataset.load(get_file_path())

    modified = dataset.apply(Reverser(), apply_to_ne=True)

    assert modified[0]['tokens'][0] == 'UE'
    assert modified[0]['tokens'][1] == 'rejects'
    assert modified[1]['tokens'][0] == 'reteP'
Exemplo n.º 5
0
def test_modify_mask_ne():
    dataset = CoNLL()
    dataset.load(get_file_path())

    modified = dataset.apply(Reverser(), apply_to_ne=False)

    assert modified[0]['tokens'][0] == 'EU'
    assert modified[0]['tokens'][1] == 'stcejer'
    assert modified[1]['tokens'][0] == 'Peter'
Exemplo n.º 6
0
def test_modify():
    dataset = SNLI()
    dataset.load(get_file_path())

    modified = dataset.apply(Reverser())

    assert modified[2]['sentence1'] == 'sihT hcruhc riohc sgnis ot eht sessam sa yeht '\
                                       'gnis suoyoj sgnos morf eht koob ta a .hcruhc'
    assert len(modified) == 3
    assert sorted(modified[0].keys()) == \
           ['annotator_labels', 'captionID', 'gold_label', 'pairID',
            'sentence1', 'sentence1_binary_parse', 'sentence1_parse',
            'sentence2', 'sentence2_binary_parse', 'sentence2_parse']
Exemplo n.º 7
0
def test_sentence():
    sentence = "this is a sample sentence."
    transformed = Reverser()(sentence)

    assert transformed == "siht si a elpmas .ecnetnes"
Exemplo n.º 8
0
def test_single_word():
    assert Reverser()("Language") == "egaugnaL"
Exemplo n.º 9
0
def test_single_word_piglatin_first():
    composed = compose(PigLatin(), Reverser())

    assert composed("Language") == "yalegaugna"
Exemplo n.º 10
0
def test_single_word_reverser_first_combined():
    composed = compose(Reverser(), PigLatin(), Reverser())
    assert composed("Language") == "yaelanguag"
Exemplo n.º 11
0
def test_single_word_reverser_first():
    composed = compose(Reverser(), PigLatin())
    assert composed("Language") == "gaugnaleay"