def has_true_and_false(self): tags = Tags([WordTag.PAST, WordTag.DEFINITE]) self.assertTrue(tags.has(WordTag.DEFINITE)) self.assertTrue(tags.has(WordTag.PAST)) self.assertFalse(tags.has(WordTag.THIRD_PERSON))
def test_to_list_is_sorted(self): all_tags = sorted(WordTag.__members__.values()) shuffled = all_tags[:] random.shuffle(shuffled) test = Tags(shuffled) self.assertEqual(test.to_list(), all_tags)
def setUp(self): self.past = Tags([WordTag.PAST]) self.third_person = Tags([WordTag.THIRD_PERSON]) self.negative = Tags([WordTag.NEGATIVE]) self.negative_past = Tags([WordTag.NEGATIVE, WordTag.PAST]) self.negative_third_person = Tags([WordTag.NEGATIVE, WordTag.THIRD_PERSON])
def test_definite_adds_definite_tag(self): tags = Tags([WordTag.PLURAL, WordTag.PAST]) expected_tags = Tags([WordTag.PLURAL, WordTag.PAST, WordTag.DEFINITE]) noun = Noun('x', tags=tags) self.assertEqual(noun.definite(), Noun('the x', '', 'x', tags=expected_tags))
def test_repr(self): tag_list = [WordTag.DEFINITE, WordTag.PAST] reverse = [WordTag.PAST, WordTag.DEFINITE] expected = 'Tags([WordTag.DEFINITE, WordTag.PAST])' self.assertEqual(repr(Tags(tag_list)), expected) self.assertEqual(repr(Tags(reverse)), expected)
def __init__(self, value, irregular_plural='', base='', tags=None): self._value = value self._irregular = irregular_plural if not base: base = value self._base = base if not tags: tags = Tags() self._tags = tags.copy()
def test_add_element_not_present(self): tags = Tags() new_tags = tags.add(WordTag.PAST) self.assertEqual(tags.to_list(), []) self.assertEqual(new_tags.to_list(), [WordTag.PAST]) new_tags = new_tags.add(WordTag.DEFINITE) self.assertEqual(new_tags.to_list(), [WordTag.DEFINITE, WordTag.PAST])
def __init__(self, value, irregular_past='', infinitive='', tags=None): self._value = value self._irregular_past = irregular_past if not infinitive: infinitive = value self._inf = infinitive if tags is None: tags = Tags() self._tags = tags.copy()
def test_proper_noun_singular_class_method(self): test_1 = Noun.proper_noun('Joe') test_2 = Noun.proper_noun('Joe', plural=False) expected = Noun('Joe', '', 'Joe', Tags([WordTag.PROPER])) self.assertEqual(test_1, expected) self.assertEqual(test_2, expected)
def indefinite(self): if self.has_tags(WordTag.INDEFINITE): return self article = 'a ' if any(self.value.startswith(vowel) for vowel in 'aeiouAEIOU'): article = 'an ' return Noun(article + self.value, self.irregular_plural, self.base_noun, Tags([WordTag.INDEFINITE]))
def test_has_tags_one_tag(self): test = DummyWord('', tags=Tags([WordTag.UNCOUNTABLE])) self.assertTrue(test.has_tags()) self.assertTrue(test.has_tags(WordTag.UNCOUNTABLE)) self.assertFalse(test.has_tags(WordTag.PLURAL)) self.assertFalse(test.has_tags(WordTag.PLURAL, WordTag.UNCOUNTABLE)) self.assertFalse(test.has_tags(WordTag.PLURAL, WordTag.PROPER))
def test_indefinite_only_has_indefinite_tag(self): uncountable = Noun.uncountable_noun('water') self.assertEqual(uncountable.tags, Tags([WordTag.UNCOUNTABLE])) proper = Noun.proper_noun('Joes', plural=True) self.assertEqual(proper.tags, self.plural_proper) self.assertEqual(uncountable.indefinite(), Noun('a water', '', 'water', tags=self.indefinite)) self.assertEqual(proper.indefinite(), Noun('a Joes', '', 'Joes', tags=self.indefinite))
def test_repr(self): self.assertEqual(repr(Noun('bob')), "Noun('bob', '', 'bob', Tags([]))") self.assertEqual( repr(Noun.uncountable_noun('bob')), "Noun('bob', '', 'bob', Tags([WordTag.UNCOUNTABLE]))") self.assertEqual( repr(Noun.proper_noun('Bob', plural=True)), "Noun('Bob', '', 'Bob', Tags([WordTag.PLURAL, WordTag.PROPER]))") self.assertEqual(repr(Noun('a', 'b', 'c', Tags([WordTag.PLURAL]))), "Noun('a', 'b', 'c', Tags([WordTag.PLURAL]))")
def test_equality(self): tags = Tags([WordTag.THIRD_PERSON, WordTag.DEFINITE]) equal_tags = Tags( [WordTag.DEFINITE, WordTag.THIRD_PERSON, WordTag.THIRD_PERSON]) self.assertEqual(tags.to_list(), equal_tags.to_list()) self.assertEqual(tags, equal_tags) self.assertNotEqual( tags, Tags([WordTag.THIRD_PERSON, WordTag.DEFINITE, WordTag.PAST]))
def setUp(self): self.indefinite = Tags([WordTag.INDEFINITE]) self.definite = Tags([WordTag.DEFINITE]) self.plural = Tags([WordTag.PLURAL]) self.definite_plural = Tags([WordTag.DEFINITE, WordTag.PLURAL]) self.definite_uncountable = Tags( [WordTag.DEFINITE, WordTag.UNCOUNTABLE]) self.proper = Tags([WordTag.PROPER]) self.plural_proper = Tags([WordTag.PLURAL, WordTag.PROPER])
def test_plural_adds_plural_tag(self): noun = Noun('dog', tags=Tags()) definite = Noun('the dog', '', 'dog', tags=self.definite) proper = Noun('Joe', tags=self.proper) self.assertEqual(noun.plural(), Noun('dogs', '', 'dog', tags=self.plural)) self.assertEqual( definite.plural(), Noun('the dogs', '', 'dog', tags=self.definite_plural)) self.assertEqual(proper.plural(), Noun('Joes', '', 'Joe', tags=self.plural_proper))
def test_plural_removes_uncountable_tag(self): noun = Noun('water', tags=Tags([WordTag.UNCOUNTABLE])) self.assertEqual(noun.plural(), Noun('waters', '', 'water', tags=self.plural)) definite = Noun('the water', '', 'water', tags=self.definite_uncountable) self.assertEqual( definite.plural(), Noun('the waters', '', 'water', tags=self.definite_plural))
def test_init_no_repeat_values(self): one_tag = Tags([WordTag.PAST]) repeat = Tags([WordTag.PAST, WordTag.PAST]) self.assertEqual(one_tag.to_list(), [WordTag.PAST]) self.assertEqual(repeat.to_list(), [WordTag.PAST]) self.assertEqual(one_tag, repeat) self.assertEqual(repr(repeat), 'Tags([WordTag.PAST])')
def test_init(self): test = Verb('a', 'b', 'c', Tags([WordTag.NEGATIVE])) self.assertEqual(test.value, 'a') self.assertEqual(test.irregular_past, 'b') self.assertEqual(test.infinitive, 'c') self.assertEqual(test.tags, Tags([WordTag.NEGATIVE]))
def __init__(self, value, tags=None): self._value = value if tags is None: tags = Tags() self._tags = tags
def particle(cls, value): return cls(value, Tags([WordTag.SEPARABLE_PARTICLE]))
def preposition(cls, value): return cls(value, Tags([WordTag.PREPOSITION]))
def test_copy(self): tags = Tags([WordTag.THIRD_PERSON, WordTag.PAST]) new_tags = tags.copy() self.assertIsNot(tags, new_tags) self.assertEqual(tags, new_tags)
def proper_noun(cls, value, plural=False): tags = Tags([WordTag.PROPER]) if plural: tags = tags.add(WordTag.PLURAL) return cls(value, '', '', tags)
def uncountable_noun(cls, value): return cls(value, '', '', Tags([WordTag.UNCOUNTABLE]))
def test_init_empty_values(self): test = Verb('a') self.assertEqual(test.value, 'a') self.assertEqual(test.irregular_past, '') self.assertEqual(test.infinitive, 'a') self.assertEqual(test.tags, Tags([]))
def test_tags(self): test = DummyWord('a', Tags([WordTag.PAST, WordTag.PROPER])) self.assertEqual(test.tags, Tags([WordTag.PAST, WordTag.PROPER]))
def test_init_empty_tags(self): word = BasicWord('hi') self.assertEqual(word.value, 'hi') self.assertEqual(word.tags, Tags())
def __init__(self, value, tags=None): self._value = value if not tags: tags = Tags() self._tags = tags.copy()
def setUp(self): self.preposition = Tags([WordTag.PREPOSITION]) self.particle = Tags([WordTag.SEPARABLE_PARTICLE])