Beispiel #1
0
 def test_generate_paragraphs_probability_pronouns_zero(self):
     config = {'probability_pronoun': 0.0, 'paragraph_size': 1}
     to_test = ParagraphsGenerator(config, self.word_lists)
     answer, error = to_test.generate_paragraphs()
     nouns, pronouns = count_nouns_and_pronouns(answer)
     self.assertEqual(nouns, 2)
     self.assertEqual(pronouns, 0)
Beispiel #2
0
    def test_init(self):
        to_test = ParagraphsGenerator(self.config_state, self.word_lists)
        for key, value in self.config_state.items():
            self.assertEqual(to_test.get(key), value)

        self.assertEqual(to_test.get_nouns(), self.word_lists.nouns)
        self.assertEqual(to_test.get_verbs(), self.word_lists.verbs)
Beispiel #3
0
 def test_generate_paragraphs_probability_negative_verb_zero(self):
     config = {
         'probability_pronoun': 0.0,
         'paragraph_size': 4,
         'probability_negative_verb': 0.0
     }
     word_lists = DummyWordLists(self.countable_nouns, self.verbs)
     to_test = ParagraphsGenerator(config, word_lists)
     answer, error = to_test.generate_paragraphs()
     negative_verb = count_word_tags(answer, WordTag.NEGATIVE)
     self.assertEqual(negative_verb, 0)
Beispiel #4
0
 def test_generate_paragraphs_probability_plural_noun_zero(self):
     config = {
         'probability_pronoun': 0.0,
         'paragraph_size': 1,
         'probability_plural_noun': 0.0
     }
     word_lists = DummyWordLists(self.countable_nouns, self.verbs)
     to_test = ParagraphsGenerator(config, word_lists)
     answer, error = to_test.generate_paragraphs()
     plural_noun = count_word_tags(answer, WordTag.PLURAL)
     self.assertEqual(plural_noun, 0)
Beispiel #5
0
 def test_generate_paragraph_type_chain(self):
     config = {
         'paragraph_size': 5,
         'paragraph_type': 'chain',
         'probability_pronoun': 1.0
     }
     answer, error = ParagraphsGenerator(
         config, self.word_lists).generate_paragraphs()
     first_sentence = answer.get_sentence(0)
     expected_subject = first_sentence.get(-2).subject().capitalize()
     for index in range(1, len(answer)):
         current_sentence = answer.get_sentence(index)
         self.assertEqual(current_sentence.get(0), expected_subject)
         expected_subject = current_sentence.get(-2).subject().capitalize()
Beispiel #6
0
    def test_generate_paragraphs_paragraph_type_pool_pool_size_two(self):
        random.seed(243758)
        config = {
            'paragraph_size': 5,
            'paragraph_type': 'pool',
            'pool_size': 2,
            'probability_pronoun': 1.0
        }
        answer, error = ParagraphsGenerator(
            config, self.word_lists).generate_paragraphs()

        subjects = set()
        for _, w_index, word in answer.indexed_all_words():
            if w_index == 0:
                subjects.add(word)
        self.assertEqual(len(subjects), 2)
Beispiel #7
0
 def test_generate_paragraphs_paragraph_size(self):
     for paragraph_size in range(1, 5):
         config = {'paragraph_size': paragraph_size}
         answer, error = ParagraphsGenerator(
             config, self.word_lists).generate_paragraphs()
         self.assertEqual(len(answer), paragraph_size)
         self.assertEqual(len(error), paragraph_size)
Beispiel #8
0
 def test_generate_paragraphs_probability_pronouns_middle(self):
     random.seed(32487590)
     config = {'probability_pronoun': 0.5, 'paragraph_size': 2}
     answer, error = ParagraphsGenerator(
         config, self.word_lists).generate_paragraphs()
     nouns, pronouns = count_nouns_and_pronouns(answer)
     self.assertEqual(nouns, 2)
     self.assertEqual(pronouns, 2)
Beispiel #9
0
    def test_generate_paragraphs_paragraph_type_pool_pool_size_one(self):
        config = {
            'paragraph_size': 5,
            'paragraph_type': 'pool',
            'pool_size': 1,
            'probability_pronoun': 1.0
        }
        answer, error = ParagraphsGenerator(
            config, self.word_lists).generate_paragraphs()

        subject = answer.sentence_list()[0].word_list()[
            0]  # type: AbstractPronoun
        for _, w_index, word in answer.indexed_all_words():
            if w_index == 0:
                self.assertEqual(word, subject)
            else:
                self.assertNotEqual(word, subject)
Beispiel #10
0
 def test_retains_no_definite_assigned_to_uncountable_nouns(self):
     random.seed(33784)
     config = {
         'error_probability': 0.0,
         'probability_pronoun': 0.0,
         'paragraph_size': 1
     }
     verb_groups = [VerbGroup(Verb('play'), None, None, 1)]
     nouns = [Noun.uncountable_noun('water')]
     word_lists = DummyWordLists(nouns, verb_groups)
     answer, error = ParagraphsGenerator(config,
                                         word_lists).generate_paragraphs()
     expected_sentences = [
         Sentence([
             Noun.uncountable_noun('water').capitalize(),
             Verb('play').third_person(),
             Noun.uncountable_noun('water'), Punctuation.PERIOD
         ])
     ]
     self.assertEqual(expected_sentences, answer.sentence_list())
Beispiel #11
0
 def test_init_default_config_state(self):
     default = {
         'error_probability': 0.2,
         'noun_errors': True,
         'pronoun_errors': True,
         'verb_errors': True,
         'punctuation_errors': True,
         'is_do_errors': False,
         'preposition_transpose_errors': False,
         'tense': 'simple_present',
         'probability_plural_noun': 0.2,
         'probability_negative_verb': 0.3,
         'probability_pronoun': 0.3,
         'paragraph_type': 'chain',
         'subject_pool': 5,
         'paragraph_size': 15,
     }
     to_test = ParagraphsGenerator({}, self.word_lists)
     for key, value in default.items():
         self.assertEqual(to_test.get(key), value)
Beispiel #12
0
 def test_generate_paragraphs_probability_plural_noun_middle(self):
     random.seed(324870)
     config = {
         'probability_pronoun': 0.0,
         'paragraph_size': 1,
         'probability_plural_noun': 0.5
     }
     word_lists = DummyWordLists(self.countable_nouns, self.verbs)
     answer, error = ParagraphsGenerator(config,
                                         word_lists).generate_paragraphs()
     plural_noun = count_word_tags(answer, WordTag.PLURAL)
     self.assertEqual(plural_noun, 1)
Beispiel #13
0
 def test_generate_paragraphs_probability_negative_verb_middle(self):
     random.seed(32470)
     config = {
         'probability_pronoun': 0.0,
         'paragraph_size': 4,
         'probability_negative_verb': 0.5
     }
     word_lists = DummyWordLists(self.countable_nouns, self.verbs)
     answer, error = ParagraphsGenerator(config,
                                         word_lists).generate_paragraphs()
     negative_verb = count_word_tags(answer, WordTag.NEGATIVE)
     self.assertEqual(negative_verb, 2)
Beispiel #14
0
 def test_generate_paragraphs_error_probability_one_all_errors_set_false(
         self):
     config = {'error_probability': 1.0}
     errors = {
         key: False
         for key in [
             'noun_errors', 'pronoun_errors', 'verb_errors',
             'punctuation_errors', 'is_do_errors',
             'preposition_transpose_errors'
         ]
     }
     config.update(errors)
     answer, error = ParagraphsGenerator(
         config, self.word_lists).generate_paragraphs()
     self.assertEqual(answer, error)
Beispiel #15
0
    def test_punctuation_errors(self):
        errors_keys = [
            'noun_errors', 'pronoun_errors', 'verb_errors', 'is_do_errors',
            'preposition_transpose_errors', 'punctuation_errors'
        ]
        config = {key: False for key in errors_keys}
        config.update({
            'error_probability': 1.0,
            'paragraph_size': 1,
            'punctuation_errors': 1.0
        })

        answer, error = ParagraphsGenerator(
            config, self.word_lists).generate_paragraphs()
        self.assert_only_error_has_one_error_tag(answer, error,
                                                 StatusTag.PUNCTUATION_ERRORS)
Beispiel #16
0
 def test_generate_paragraphs_error_probability_middle(self):
     random.seed(34578)
     config = {
         'error_probability': 0.5,
         'verb_errors': True,
         'paragraph_size': 4
     }
     answer, error = ParagraphsGenerator(
         config, self.word_lists).generate_paragraphs()
     error_count = 0
     for error_sentence, sentence in zip(error, answer):
         error_verb = error_sentence.get(error_sentence.get_verb())
         answer_verb = sentence.get(sentence.get_verb())
         if error_verb != answer_verb:
             error_count += 1
     self.assertEqual(error_count, 2)
Beispiel #17
0
 def test_generate_paragraphs_error_probability_one_with_errors(self):
     config = {'error_probability': 1.0, 'verb_errors': True}
     answer, error = ParagraphsGenerator(
         config, self.word_lists).generate_paragraphs()
     self.assertNotEqual(answer.sentence_list(), error.sentence_list())
Beispiel #18
0
 def test_generate_paragraphs_tense_simple_past(self):
     config = {'paragraph_size': 5, 'tense': 'simple_past'}
     answer, error = ParagraphsGenerator(
         config, self.word_lists).generate_paragraphs()
     past_count = count_word_tags(answer, WordTag.PAST)
     self.assertEqual(past_count, 5)