Esempio n. 1
0
    def test_assign_preposition(self):
        random.seed(1234)
        verb_list = [{
            'verb': Verb('jump'),
            'preposition': BasicWord.preposition('on'),
            'objects': 1,
            'particle': None
        }]
        generator = RandomSentences(verb_list,
                                    self.countable + self.uncountable)
        answer = generator.sentence()
        self.assertEqual(answer, [
            Noun('sand'),
            Verb('jump'),
            BasicWord.preposition('on'), US, PERIOD
        ])

        answer = generator.sentence()
        expected = [
            Noun('cat'),
            Verb('jump'),
            BasicWord.preposition('on'),
            Noun('frog'), PERIOD
        ]
        self.assertEqual(answer, expected)
Esempio n. 2
0
def get_verb_dict(str_lst):
    str_lst = _make_list_correct_len_with_nulls(str_lst)

    raw_infinitive, raw_past, preposition_str, obj_num_str = str_lst

    infinitive, particle_inf = split_verb(raw_infinitive)
    past_tense, particle_past = split_verb(raw_past)

    _raise_error_for_bad_particles(particle_inf, particle_past, infinitive)

    if past_tense == 'null':
        past_tense = ''
    verb = Verb(infinitive, past_tense, '')

    if particle_inf == '':
        particle = None
    else:
        particle = BasicWord.particle(particle_inf)

    if preposition_str == 'null':
        preposition = None
    else:
        preposition = BasicWord.preposition(preposition_str)

    if obj_num_str == 'null':
        obj_num = 1
    else:
        obj_num = int(obj_num_str)

    return {'verb': verb, 'preposition': preposition, 'objects': obj_num, 'particle': particle}
Esempio n. 3
0
    def test_two_objects_second_obj_is_never_pronoun(self):
        random.seed(456)
        verb_list = [
            {
                'verb': Verb('bring'),
                'preposition': BasicWord.preposition('to'),
                'objects': 2,
                'particle': None
            },
            {
                'verb': Verb('give'),
                'preposition': None,
                'objects': 2,
                'particle': None
            },
        ]
        generator = RandomSentences(verb_list,
                                    self.countable + self.uncountable)
        answer = generator.predicate(1.0)
        self.assertEqual(answer, [Verb('give'), HER, Noun('dog'), EXCLAMATION])

        answer = generator.predicate(1.0)
        self.assertEqual(answer, [
            Verb('bring'), ME,
            BasicWord.preposition('to'),
            Noun('sand'), PERIOD
        ])

        answer = generator.predicate(1.0)
        self.assertEqual(
            answer,
            [Verb('give'), HIM, Noun('milk'), EXCLAMATION])
Esempio n. 4
0
    def test_assign_preposition_insert_preposition_true(self):
        random.seed(7890)
        verb_list = [{
            'verb': Verb('bring'),
            'preposition': BasicWord.preposition('to'),
            'objects': 2,
            'particle': None
        }]
        generator = RandomSentences(verb_list,
                                    self.countable + self.uncountable)
        answer = generator.sentence()
        self.assertEqual(answer, [
            Noun('milk'),
            Verb('bring'),
            Noun('water'),
            BasicWord.preposition('to'),
            Noun('rice'), EXCLAMATION
        ])

        answer = generator.sentence()
        self.assertEqual(answer, [
            Noun('water'),
            Verb('bring'),
            Noun('dog'),
            BasicWord.preposition('to'),
            Noun('milk'), PERIOD
        ])
 def test_create_pool_paragraph_output(self):
     random.seed(3)
     paragraph = self.rp.create_pool_paragraph(2, 5)
     expected = [[Noun('pig'),
                  Verb('eat'),
                  Noun('sand'), PERIOD],
                 [
                     Noun('pig'),
                     Verb('give'),
                     Noun('cat'),
                     BasicWord.preposition('to'),
                     Noun('dog'), PERIOD
                 ],
                 [
                     Noun('sand'),
                     Verb('jump'),
                     BasicWord.preposition('over'),
                     Noun('milk'), EXCLAMATION
                 ], [Noun('sand'), Verb('eat'), HIM, PERIOD],
                 [
                     Noun('sand'),
                     Verb('jump'),
                     BasicWord.preposition('over'),
                     Noun('milk'), EXCLAMATION
                 ]]
     self.assertEqual(paragraph, expected)
Esempio n. 6
0
 def test_connect_words_no_punctuation(self):
     lst = [
         Pronoun.I,
         BasicWord('like'),
         BasicWord('big'),
         BasicWord('butts')
     ]
     self.assertEqual(connect_words(lst), 'I like big butts')
    def test_is_word_in_sentence_other(self):
        sentence = [BasicWord('tom'), Verb('dick'), Noun('harry')]
        self.assertTrue(is_word_in_sentence(BasicWord('tom'), sentence))
        self.assertTrue(is_word_in_sentence(Verb('dick'), sentence))
        self.assertTrue(is_word_in_sentence(Noun('harry'), sentence))

        self.assertFalse(is_word_in_sentence(Noun('tom'), sentence))
        self.assertFalse(is_word_in_sentence(BasicWord('dick'), sentence))
        self.assertFalse(is_word_in_sentence(Verb('harry'), sentence))
Esempio n. 8
0
 def test_get_verb_dict_phrasal_verb(self):
     answer = get_verb_dict(['take away', 'took away', 'from'])
     self.assertEqual(
         answer, {
             'verb': Verb('take', 'took', ''),
             'preposition': BasicWord.preposition('from'),
             'particle': BasicWord.particle('away'),
             'objects': 1
         })
 def test_requires_third_person_no_subject(self):
     answer = [
         Verb('STOP'),
         BasicWord('in'),
         Noun('name').definite(),
         BasicWord('of'),
         Noun('love'), period, period, period
     ]
     self.assertFalse(requires_third_person(answer))
Esempio n. 10
0
def get_present_be_verb(sentence):
    subj_index = find_subject(sentence)
    if subj_index == -1:
        return BasicWord('be')
    subj = sentence[subj_index]
    if requires_third_person(sentence):
        return BasicWord('is')
    elif subj in (Pronoun.I, Pronoun.ME, CapitalPronoun.I, CapitalPronoun.ME):
        return BasicWord('am')
    else:
        return BasicWord('are')
Esempio n. 11
0
 def test_connect_words_with_punctuation(self):
     lst = [
         BasicWord('on').capitalize(),
         BasicWord('Tuesday'), Punctuation.COMMA, Pronoun.I,
         Verb('see', 'saw', '').past_tense(),
         Noun('A').indefinite(), Punctuation.COMMA,
         Noun('B').indefinite(), Punctuation.COMMA,
         BasicWord('and'),
         Noun('C').indefinite(), Punctuation.EXCLAMATION
     ]
     self.assertEqual(connect_words(lst),
                      "On Tuesday, I saw an A, a B, and a C!")
    def test_find_subject_limitations(self):
        sentence = [
            BasicWord('to'),
            BasicWord('boldly'),
            Verb('save_paragraphs_to_pdf')
        ]
        self.assertEqual(find_subject(sentence), 1)

        sentence = [
            BasicWord('to'),
            BasicWord('boldly'),
            BasicWord('save_paragraphs_to_pdf')
        ]
        self.assertEqual(find_subject(sentence), -1)
 def test_get_present_be_verb_are(self):
     predicate = [Verb('play'), period]
     subjs = [
         you, them, they, we, us,
         BasicWord('You'),
         BasicWord('They'),
         BasicWord('We'),
         Noun.proper_noun('The Guys', plural=True),
         Noun('dog').plural(),
         Noun('dog').definite().plural(),
         Noun('dog').plural().capitalize()
     ]
     for subj in subjs:
         self.assertEqual(get_present_be_verb([subj] + predicate),
                          BasicWord('are'))
Esempio n. 14
0
    def test_assign_objects_one_object_particle(self):
        verb_dict = {
            'verb': Verb('pick'),
            'preposition': None,
            'objects': 1,
            'particle': BasicWord.particle('up')
        }
        self.assertEqual(
            assign_objects(verb_dict, [IT]),
            [Verb('pick'), IT, BasicWord.particle('up')])

        self.assertEqual(
            assign_objects(verb_dict, [Noun('dog')]),
            [Verb('pick'), BasicWord.particle('up'),
             Noun('dog')])
Esempio n. 15
0
    def test_assign_objects_two_objects_preposition(self):
        verb_dict = {
            'verb': Verb('bring'),
            'preposition': BasicWord.preposition('to'),
            'objects': 2,
            'particle': None
        }
        self.assertEqual(assign_objects(verb_dict, [HIM, IT]),
                         [Verb('bring'), HIM,
                          BasicWord.preposition('to'), IT])

        self.assertEqual(assign_objects(verb_dict,
                                        [Noun('cat'), Noun('dog')]), [
                                            Verb('bring'),
                                            Noun('cat'),
                                            BasicWord.preposition('to'),
                                            Noun('dog')
                                        ])
Esempio n. 16
0
 def test_get_verb_dict_no_null_values(self):
     answer = get_verb_dict(['fly', 'flew', 'with', '2'])
     self.assertEqual(
         answer, {
             'verb': Verb('fly', 'flew', ''),
             'preposition': BasicWord.preposition('with'),
             'objects': 2,
             'particle': None
         })
Esempio n. 17
0
 def test_get_verb_dict_phrasal_verb_single_value(self):
     answer = get_verb_dict(['pick up'])
     self.assertEqual(
         answer, {
             'verb': Verb('pick'),
             'preposition': None,
             'particle': BasicWord.particle('up'),
             'objects': 1
         })
Esempio n. 18
0
    def test_assign_objects_no_objects_particle_or_preposition(self):
        verb_dict = {
            'verb': Verb('chill'),
            'preposition': BasicWord.preposition('out'),
            'objects': 0,
            'particle': None
        }
        self.assertEqual(
            assign_objects(verb_dict, []),
            [Verb('chill'), BasicWord.preposition('out')])

        verb_dict = {
            'verb': Verb('run'),
            'preposition': None,
            'objects': 0,
            'particle': BasicWord.particle('away')
        }
        self.assertEqual(assign_objects(verb_dict, []),
                         [Verb('run'), BasicWord.particle('away')])
    def test_find_subject_on_standard_predicate(self):

        predicate = [
            Verb('give'),
            Noun('frog'),
            BasicWord.preposition('to'),
            Noun('pig'), period
        ]

        self.assertEqual(find_subject(predicate), -1)
Esempio n. 20
0
 def test_verbs_with_insert_preposition(self):
     filename = os.path.join(TESTS_FILES, 'bring_to.csv')
     answer = verbs(filename)
     bring_to = {
         'verb': Verb('bring', 'brought', ''),
         'preposition': BasicWord.preposition('to'),
         'objects': 2,
         'particle': None
     }
     self.assertEqual(answer, [bring_to])
Esempio n. 21
0
 def test_complex_case(self):
     lst = [
         Pronoun.US.subject().capitalize(),
         Verb('eat', 'ate', '').negative().past_tense(),
         Noun('cake').plural().capitalize().definite(),
         BasicWord('or'),
         Noun('octopus', 'octopodes').definite().plural().capitalize(),
         Punctuation.PERIOD
     ]
     self.assertEqual(connect_words(lst),
                      "We didn't eat the Cakes or The octopodes.")
Esempio n. 22
0
    def test_is_punctuation(self):
        punctuation = [p for p in Punctuation]
        bold_punctuation = [p.bold() for p in Punctuation]
        other = [
            BasicWord('.'), Pronoun.I,
            Pronoun.I.bold(),
            Noun('.'),
            Noun('hi').bold(),
            Verb('.'),
            Verb('play').bold()
        ]
        false_positive = BasicWord('.').bold()

        for word in punctuation:
            self.assertTrue(is_punctuation(word))
        for word in bold_punctuation:
            self.assertTrue(is_punctuation(word))
        for word in other:
            self.assertFalse(is_punctuation(word))

        self.assertTrue(is_punctuation(false_positive))
Esempio n. 23
0
    def test_random_sentences_sentence_with_phrasal_verb_one_obj_and_preposition(
            self):
        random.seed(456123)
        verb_list = [{
            'verb': Verb('put'),
            'preposition': BasicWord.preposition('with'),
            'objects': 1,
            'particle': BasicWord.particle('up')
        }]
        generator = RandomSentences(verb_list,
                                    self.countable + self.uncountable)
        answer = generator.sentence()
        expected = [
            Noun('pig'),
            Verb('put'),
            BasicWord.particle('up'),
            BasicWord.preposition('with'), YOU, PERIOD
        ]
        self.assertEqual(answer, expected)

        answer = generator.sentence()
        expected = [
            Noun('water'),
            Verb('put'),
            BasicWord.particle('up'),
            BasicWord.preposition('with'),
            Noun('pig'), EXCLAMATION
        ]
        self.assertEqual(answer, expected)
Esempio n. 24
0
    def test_random_sentences_sentence_with_phrasal_verb_two_obj_and_preposition(
            self):
        random.seed(789)
        verb_list = [{
            'verb': Verb('throw'),
            'preposition': BasicWord.preposition('for'),
            'objects': 2,
            'particle': BasicWord.particle('away')
        }]
        generator = RandomSentences(verb_list,
                                    self.countable + self.uncountable)
        answer = generator.sentence()
        expected = [
            Noun('dog'),
            Verb('throw'), US,
            BasicWord.particle('away'),
            BasicWord.preposition('for'),
            Noun('water'), EXCLAMATION
        ]
        self.assertEqual(answer, expected)

        answer = generator.sentence()
        expected = [
            Noun('rice'),
            Verb('throw'),
            BasicWord.particle('away'),
            Noun('water'),
            BasicWord.preposition('for'),
            Noun('frog'), PERIOD
        ]
        self.assertEqual(answer, expected)
    def test_find_subject_on_standard_sentence(self):
        sentence = [
            Noun('cow'),
            Verb('give'),
            Noun('frog'),
            BasicWord.preposition('to'),
            Noun('pig'), period
        ]

        self.assertEqual(find_subject(sentence), 0)

        words = [Noun('orangutan'), Noun('bunny')]
        self.assertEqual(find_subject(words + sentence), 2)
Esempio n. 26
0
 def test_create_chain_paragraph_output(self):
     random.seed(4567)
     answer = self.rp.create_chain_paragraph(4)
     expected = [
         [Noun('water'),
          Verb('eat'),
          Noun('rice'), EXCLAMATION],
         [
             Noun('rice'),
             Verb('give'), US,
             BasicWord.preposition('to'),
             Noun('cat'), PERIOD
         ],
         [Noun('cat'), Verb('eat'),
          Noun('dog'), PERIOD],
         [
             Noun('dog'),
             Verb('jump'),
             BasicWord.preposition('over'),
             Noun('sand'), PERIOD
         ],
     ]
     self.assertEqual(answer, expected)
Esempio n. 27
0
    def test_sentence(self):
        random.seed(1)
        answer = self.generator.sentence()
        self.assertEqual(
            answer,
            [I, Verb('jump'),
             BasicWord.preposition('over'), IT, PERIOD])

        answer = self.generator.sentence()
        self.assertEqual(
            answer,
            [Noun('frog'), Verb('eat'),
             Noun('milk'), PERIOD])

        answer = self.generator.sentence()
        expected = [
            Noun('dog'),
            Verb('give'),
            Noun('frog'),
            BasicWord.preposition('to'),
            Noun('cat'), PERIOD
        ]
        self.assertEqual(answer, expected)
Esempio n. 28
0
    def test_predicate(self):
        random.seed(5)
        answer = self.generator.predicate()
        self.assertEqual(
            answer,
            [Verb('jump'),
             BasicWord.preposition('over'),
             Noun('dog'), PERIOD])

        answer = self.generator.predicate()
        self.assertEqual(
            answer,
            [Verb('give'), Noun('pig'),
             Noun('sand'), PERIOD])

        answer = self.generator.predicate()
        expected = [
            Verb('give'),
            Noun('frog'),
            BasicWord.preposition('to'),
            Noun('pig'), PERIOD
        ]
        self.assertEqual(answer, expected)
 def test_get_present_be_verb_is(self):
     predicate = [Verb('play').third_person(), period]
     p_nouns = [he, him, she, her, it]
     capital_p_nouns = [p_noun.capitalize() for p_noun in p_nouns]
     subjs = [
         Noun.uncountable_noun('water'),
         Noun('dog').definite(),
         Noun('dog').capitalize(),
         Noun('dog').indefinite(),
         Noun('Joe')
     ]
     for subj in p_nouns + capital_p_nouns + subjs:
         self.assertEqual(get_present_be_verb([subj] + predicate),
                          BasicWord('is'))
Esempio n. 30
0
 def test_makes_copy_of_input_list(self):
     random.seed(148)
     for index in range(4):
         self.countable[index] = 'oops'
         self.uncountable[index] = 'oops'
         self.verbs[index] = 'oops'
     answer = self.generator.sentence()
     expected = [
         Noun('dog'),
         Verb('give'),
         Noun('water'),
         BasicWord.preposition('to'),
         Noun('frog'), PERIOD
     ]
     self.assertEqual(answer, expected)