Esempio n. 1
0
    def test_create_paragraph_probability_plural_noun(self):
        create_test_csvs(['dog', 'cat'], ['water'], ['like'], ['Abbey Normal'])
        self.config_state['probability_pronoun'] = 0.0
        self.config_state['probability_plural_noun'] = 1.0

        pg = ParagraphsGenerator(self.config_state)
        answer = pg.create_paragraph()
        noun_values = [
            'Dogs', 'The dogs', 'dogs', 'the dogs', 'Cats', 'The cats', 'cats',
            'the cats', 'Water', 'The water', 'water', 'the water',
            'Abbey Normal'
        ]
        for sentence in answer:
            self.assertIn(sentence[0].value, noun_values)
            self.assertIn(sentence[2].value, noun_values)

        pg.update_options({'probability_plural_noun': 0.0})
        answer = pg.create_paragraph()
        noun_values = [
            'A dog', 'The dog', 'a dog', 'the dog', 'A cat', 'The cat',
            'a cat', 'the cat', 'Water', 'The water', 'water', 'the water',
            'Abbey Normal'
        ]
        for sentence in answer:
            self.assertIn(sentence[0].value, noun_values)
            self.assertIn(sentence[2].value, noun_values)
Esempio n. 2
0
    def test_create_paragraph_paragraph_size(self):
        self.config_state['paragraph_size'] = 5
        pg = ParagraphsGenerator(self.config_state)
        for _ in range(3):
            self.assertEqual(len(pg.create_paragraph()), 5)

        pg.update_options({'paragraph_size': 2})
        for _ in range(3):
            self.assertEqual(len(pg.create_paragraph()), 2)
Esempio n. 3
0
    def test_create_paragraph_probability_negative_verb(self):
        create_test_csvs(['dog', 'cat'], ['water'], ['like'], ['Mom'])
        self.config_state['probability_pronoun'] = 0.0
        self.config_state['probability_plural_noun'] = 0.0
        self.config_state['probability_negative_verb'] = 1.0

        pg = ParagraphsGenerator(self.config_state)
        answer = pg.create_paragraph()
        verb_value = "doesn't like"
        for sentence in answer:
            self.assertEqual(verb_value, sentence[1].value)

        pg.update_options({'probability_negative_verb': 0.0})
        answer = pg.create_paragraph()
        verb_value = "likes"
        for sentence in answer:
            self.assertEqual(verb_value, sentence[1].value)
Esempio n. 4
0
    def test_create_paragraph_probability_pronoun(self):
        create_test_csvs(['dog'], ['water'], ['like'], [])
        self.config_state['probability_pronoun'] = 0.0

        pg = ParagraphsGenerator(self.config_state)
        for _ in range(10):
            paragraph = pg.create_paragraph()
            for sentence in paragraph:
                self.assertIsInstance(sentence[0], Noun)
                self.assertIsInstance(sentence[2], Noun)

        pg.update_options({'probability_pronoun': 1.0})
        for _ in range(10):
            paragraph = pg.create_paragraph()
            for sentence in paragraph:
                self.assertIsInstance(sentence[0], CapitalPronoun)
                self.assertIsInstance(sentence[2], Pronoun)
Esempio n. 5
0
    def test_create_paragraph_tense(self):
        create_test_csvs(['dog', 'cat'], ['water'], ['like'], ['Dad'])
        self.config_state['probability_pronoun'] = 0.0
        self.config_state['probability_negative_verb'] = 0.0
        self.config_state['tense'] = 'simple_past'

        pg = ParagraphsGenerator(self.config_state)
        answer = pg.create_paragraph()
        verb_value = "liked"
        for sentence in answer:
            self.assertEqual(verb_value, sentence[1].value)
Esempio n. 6
0
    def test_create_paragraph_pool_paragraph(self):
        seed(8908)
        create_test_csvs(['dog', 'cat'], ['water'], ['like'],
                         ['My Great-Aunt Fanny'])
        self.config_state['probability_pronoun'] = 0.0
        self.config_state['paragraph_type'] = 'pool'
        self.config_state['subject_pool'] = 1

        pg = ParagraphsGenerator(self.config_state)
        answer = pg.create_paragraph()
        for sentence in answer:
            self.assertIn('cat', sentence[0].value)
            self.assertIsInstance(sentence[2], Noun)
            self.assertNotIn('cat', sentence[2].value)

        pg.update_options({'subject_pool': 2})
        answer = pg.create_paragraph()
        values = ['Water', 'The water', 'My Great-Aunt Fanny']
        for sentence in answer:
            self.assertIn(sentence[0].value, values)
            self.assertIsInstance(sentence[2], Noun)
Esempio n. 7
0
    def test_create_paragraph_word_lists(self):
        seed(1234)
        create_test_csvs(['dog'], ['water'], ['like'], ['Frank'])
        self.config_state['probability_pronoun'] = 0.0
        self.config_state['paragraph_size'] = 2

        pg = ParagraphsGenerator(self.config_state)

        raw_answer = pg.create_paragraph()
        answer = [[word.value for word in sentence] for sentence in raw_answer]
        self.assertEqual(answer, [['Water', "doesn't like", 'Frank', '.'],
                                  ['Frank', 'likes', 'the water', '.']])

        raw_answer = pg.create_paragraph()
        answer = [[word.value for word in sentence] for sentence in raw_answer]
        self.assertEqual(answer, [['Frank', "doesn't like", 'a dog', '.'],
                                  ['The dog', 'likes', 'Frank', '.']])

        raw_answer = pg.create_paragraph()
        answer = [[word.value for word in sentence] for sentence in raw_answer]
        self.assertEqual(answer, [['Water', 'likes', 'Frank', '!'],
                                  ['Frank', 'likes', 'a dog', '.']])
Esempio n. 8
0
    def test_create_paragraph_chain_paragraph(self):
        seed(4569)
        create_test_csvs(['dog'], ['water'], ['like'], [])
        self.config_state['probability_pronoun'] = 0.0
        self.config_state['paragraph_type'] = 'chain'

        pg = ParagraphsGenerator(self.config_state)
        answer = pg.create_paragraph()
        for index, sentence in enumerate(answer):
            if index == 0:
                self.assertEqual(sentence[0].value, 'Water')
                self.assertEqual(sentence[2].value, 'a dog')
            elif index % 2 == 0:
                self.assertEqual(sentence[0].value, 'The water')
                self.assertEqual(sentence[2].value, 'the dog')
            else:
                self.assertEqual(sentence[0].value, 'The dog')
                self.assertEqual(sentence[2].value, 'the water')