def __init__(self, extractor="RandomWordExtractor", ignore=True): assert extractor in ["RandomWordExtractor" ], self.extractor_not_valid_message() if extractor == "RandomWordExtractor": self.extractor = basic.RandomImportantWordExtractor() self.delete_char_perturb = perturbations.DeleteCharacterPerturbations() self.ignore = ignore
def __init__(self, extractor="RandomWordExtractor", probability=0.1, ignore=True): assert extractor in ["RandomWordExtractor" ], self.extractor_not_valid_message() if extractor == "RandomWordExtractor": self.extractor = basic.RandomImportantWordExtractor() self.typo_char_perturb = perturbations.TypoCharacterPerturbations() self.probability = probability self.ignore = ignore
def __init__(self, extractor="RandomWordExtractor", char_perturb=False, ignore=True): assert extractor in ["RandomWordExtractor" ], self.extractor_not_valid_message() if extractor == "RandomWordExtractor": self.extractor = basic.RandomImportantWordExtractor() self.char_perturb = char_perturb self.space_char_perturb = perturbations.InsertSpaceCharacterPerturbations( ) self.ignore = ignore
def __init__(self, extractor="RandomWordExtractor", seed=None, ignore=True): assert extractor in ["RandomWordExtractor" ], self.extractor_not_valid_message() if extractor == "RandomWordExtractor": self.extractor = basic.RandomImportantWordExtractor() self.visually_similar_char_perturb = perturbations.VisuallySimilarCharacterPerturbations( "unicode", "homoglyph") self.ignore = ignore self.seed = seed
def __init__(self, extractor="RandomWordExtractor", mid=False, ignore=True): assert extractor in ["RandomWordExtractor" ], self.extractor_not_valid_message() if extractor == "RandomWordExtractor": self.extractor = basic.RandomImportantWordExtractor() self.shuffle_char_perturb = perturbations.ShuffleCharacterPerturbations( ) self.mid = mid self.ignore = ignore
def test_random_extract(words, expected_result): random.seed(0) random_extractor = basic.RandomImportantWordExtractor() assert random_extractor.extract(words) == expected_result
def test_words_less_than_k_extract(): random_extractor = basic.RandomImportantWordExtractor() with pytest.raises(AssertionError): random_extractor.extract(["Hey", "There"], top_k=3)
def test_random_empty_extract(): random_extractor = basic.RandomImportantWordExtractor() with pytest.raises(AssertionError): random_extractor.extract([])