Example #1
0
    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))
Example #2
0
    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)
Example #3
0
    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])
Example #4
0
    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))
Example #5
0
    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)
Example #6
0
    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()
Example #7
0
    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])
Example #8
0
    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()
Example #9
0
    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)
Example #10
0
 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]))
Example #11
0
    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))
Example #12
0
    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))
Example #13
0
 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]))")
Example #14
0
    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]))
Example #15
0
 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])
Example #16
0
    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))
Example #17
0
    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))
Example #18
0
    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])')
Example #19
0
 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]))
Example #20
0
 def __init__(self, value, tags=None):
     self._value = value
     if tags is None:
         tags = Tags()
     self._tags = tags
Example #21
0
 def particle(cls, value):
     return cls(value, Tags([WordTag.SEPARABLE_PARTICLE]))
Example #22
0
 def preposition(cls, value):
     return cls(value, Tags([WordTag.PREPOSITION]))
Example #23
0
 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)
Example #24
0
 def proper_noun(cls, value, plural=False):
     tags = Tags([WordTag.PROPER])
     if plural:
         tags = tags.add(WordTag.PLURAL)
     return cls(value, '', '', tags)
Example #25
0
 def uncountable_noun(cls, value):
     return cls(value, '', '', Tags([WordTag.UNCOUNTABLE]))
Example #26
0
 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([]))
Example #27
0
 def test_tags(self):
     test = DummyWord('a', Tags([WordTag.PAST, WordTag.PROPER]))
     self.assertEqual(test.tags, Tags([WordTag.PAST, WordTag.PROPER]))
Example #28
0
 def test_init_empty_tags(self):
     word = BasicWord('hi')
     self.assertEqual(word.value, 'hi')
     self.assertEqual(word.tags, Tags())
Example #29
0
 def __init__(self, value, tags=None):
     self._value = value
     if not tags:
         tags = Tags()
     self._tags = tags.copy()
Example #30
0
 def setUp(self):
     self.preposition = Tags([WordTag.PREPOSITION])
     self.particle = Tags([WordTag.SEPARABLE_PARTICLE])