示例#1
0
 def test_errors(self, aug_toks):
     for num in [-1, 2.0]:
         with pytest.raises(ValueError):
             _ = transforms.substitute_word_synonyms(aug_toks, num=num)
     for obj in [["foo", "bar"], "foo bar"]:
         with pytest.raises(TypeError):
             _ = transforms.substitute_word_synonyms(obj, num=1)
示例#2
0
 def test_num_int(self, aug_toks):
     for num in [1, 3]:
         new_aug_toks = transforms.substitute_word_synonyms(aug_toks,
                                                            num=num)
         assert isinstance(new_aug_toks, list)
         assert len(new_aug_toks) == len(aug_toks)
         assert all(
             isinstance(aug_tok, aug_utils.AugTok)
             for aug_tok in new_aug_toks)
         assert any(aug_tok.text != new_aug_tok.text
                    for aug_tok, new_aug_tok in zip(aug_toks, new_aug_toks))
示例#3
0
 def test_pos(self, aug_toks):
     for pos in ["NOUN", ("NOUN", "VERB", "ADJ", "ADV")]:
         new_aug_toks = transforms.substitute_word_synonyms(aug_toks,
                                                            num=1,
                                                            pos=pos)
         assert isinstance(new_aug_toks, list)
         assert len(new_aug_toks) == len(aug_toks)
         assert all(
             isinstance(aug_tok, aug_utils.AugTok)
             for aug_tok in new_aug_toks)
         assert any(aug_tok.text != new_aug_tok.text
                    for aug_tok, new_aug_tok in zip(aug_toks, new_aug_toks))
示例#4
0
 def test_num_float(self, aug_toks):
     for num in [0.1, 0.3]:
         _ = transforms.substitute_word_synonyms(aug_toks, num=num)
示例#5
0
 def test_noop(self, aug_toks):
     for num in [0, 0.0]:
         new_aug_toks = transforms.substitute_word_synonyms(aug_toks,
                                                            num=num)
         for aug_tok, new_aug_tok in zip(aug_toks, new_aug_toks):
             assert aug_tok.text == new_aug_tok.text