def test_indexed_all_words(self):
     sentence_one = [BasicWord('hi'), BasicWord('there'), BasicWord('guy')]
     sentence_two = [BasicWord('ho'), BasicWord('there')]
     paragraph = Paragraph([Sentence(sentence_one), Sentence(sentence_two)])
     all_sentences = [sentence_one, sentence_two]
     for s_index, w_index, word in paragraph.indexed_all_words():
         self.assertEqual(word, all_sentences[s_index][w_index])
    def test_init_reverts_countable_nouns_and_removes_tag(self):
        original_sentences = [
            Sentence([
                Noun('x').plural(),
                Noun('y'),
                Noun.uncountable_noun('z'),
                Noun.proper_noun('A', plural=True),
                Noun.uncountable_noun('q').definite()
            ])
        ]
        original_tags = Tags([StatusTag.HAS_PLURALS, StatusTag.RAW])
        original_paragraph = Paragraph(original_sentences, original_tags)
        pa = PluralsAssignment(original_paragraph)

        self.assertEqual(original_paragraph.sentence_list(),
                         original_sentences)
        self.assertEqual(original_paragraph.tags, original_tags)

        expected = [
            Sentence([
                Noun('x'),
                Noun('y'),
                Noun.uncountable_noun('z'),
                Noun.proper_noun('A', plural=True),
                Noun.uncountable_noun('q').definite()
            ])
        ]
        self.assertEqual(pa.raw.sentence_list(), expected)
        self.assertEqual(pa.raw.tags, Tags([StatusTag.RAW]))
 def test_all_words(self):
     sentence_one = [BasicWord('hi'), BasicWord('there')]
     sentence_two = [BasicWord('ho'), BasicWord('there')]
     paragraph = Paragraph([Sentence(sentence_one), Sentence(sentence_two)])
     all_words = sentence_one + sentence_two
     for index, word in enumerate(paragraph.all_words()):
         self.assertEqual(word, all_words[index])
    def test_set_sentence(self):
        tags = Tags([StatusTag.RAW])
        sentences = [Sentence(), Sentence(), Sentence()]
        new_sentence = Sentence([BasicWord('z')])

        paragraph = Paragraph(sentences, tags).set_sentence(1, new_sentence)
        expected = Paragraph([Sentence(), new_sentence, Sentence()], tags)
        self.assertEqual(paragraph, expected)
 def setUp(self):
     self.sentence_list = [
         Sentence([BasicWord('a'),
                   Verb('b'), BasicWord('c')]),
         Sentence([BasicWord('d'), Verb('e')])
     ]
     self.tags = Tags([StatusTag.RAW, StatusTag.HAS_PLURALS])
     self.paragraph = Paragraph(self.sentence_list, self.tags)
    def test_from_word_lists(self):
        word_lists = [[BasicWord('hi')], [BasicWord('ho')]]
        tags = Tags([StatusTag.RAW])
        paragraph = Paragraph.from_word_lists(word_lists, tags)
        self.assertEqual(paragraph.sentence_list(), [Sentence(lst) for lst in word_lists])
        self.assertEqual(paragraph.tags, tags)

        paragraph = Paragraph.from_word_lists(word_lists)
        self.assertEqual(paragraph.sentence_list(), [Sentence(lst) for lst in word_lists])
        self.assertEqual(paragraph.tags, Tags())
    def test_set(self):
        sentences = [Sentence([BasicWord('hi'), BasicWord('there')]), Sentence([BasicWord('ho')])]
        tags = Tags([StatusTag.NOUN_ERRORS])
        paragraph = Paragraph(sentences, tags)
        new_paragraph = paragraph.set(0, 1, BasicWord('new'))

        self.assertEqual(paragraph.sentence_list(), sentences)
        self.assertEqual(paragraph.tags, tags)

        expected = [Sentence([BasicWord('hi'), BasicWord('new')]), Sentence([BasicWord('ho')])]
        self.assertEqual(new_paragraph.sentence_list(), expected)
        self.assertEqual(new_paragraph.tags, tags)
 def test_create_chain_paragraph_output(self):
     random.seed(4567)
     answer = self.rp.create_chain_paragraph(4)
     sentences = [
         Sentence([Noun('water'),
                   Verb('eat'),
                   Noun('rice'), EXCLAMATION]),
         Sentence([
             Noun('rice'),
             Verb('give'), US,
             BasicWord.preposition('to'),
             Noun('cat'), PERIOD
         ]),
         Sentence([Noun('cat'),
                   Verb('eat'),
                   Noun('dog'), PERIOD]),
         Sentence([
             Noun('dog'),
             Verb('jump'),
             BasicWord.preposition('over'),
             Noun('sand'), PERIOD
         ]),
     ]
     expected = Paragraph(sentences, self.raw_tags)
     self.assertEqual(answer, expected)
Exemplo n.º 9
0
    def test_error_maker_preposition_errors_p_error_gte_one(self):
        sentences = [
            Sentence([
                Pronoun.I,
                Verb('go'),
                BasicWord.preposition('with'), Pronoun.HIM, Punctuation.PERIOD
            ]),
            Sentence([
                Pronoun.HE,
                Verb('run'),
                BasicWord.preposition('over'), Pronoun.IT, Punctuation.PERIOD
            ])
        ]
        paragraph = Paragraph(sentences)
        error_maker = ErrorMaker(paragraph)

        error_paragraph = error_maker.preposition_errors(1.0).get_paragraph()
        expected = [
            Sentence([
                Pronoun.I,
                BasicWord.preposition('with'), Pronoun.HIM,
                Verb('go'), Punctuation.PERIOD
            ]),
            Sentence([
                Pronoun.HE,
                BasicWord.preposition('over'), Pronoun.IT,
                Verb('run'), Punctuation.PERIOD
            ])
        ]
        self.assertEqual(error_paragraph.sentence_list(), expected)
Exemplo n.º 10
0
    def test_error_maker_is_do_errors_p_error_gte_one(self):
        random.seed(4758)
        sentences = [
            Sentence([Pronoun.HE, Verb('play').third_person()]),
            Sentence([Verb('stop')]),
            Sentence([Pronoun.I, Verb('go').negative()]),
            Sentence([Pronoun.THEY, Verb('go').past_tense()]),
            Sentence([Pronoun.HIM,
                      Verb('go').past_tense().negative()])
        ]
        paragraph = Paragraph(sentences)
        error_maker = ErrorMaker(paragraph)

        error_paragraph = error_maker.is_do_errors(1.0).get_paragraph()
        expected = [
            Sentence([Pronoun.HE, BeVerb.IS,
                      Verb('play')]),
            Sentence([BeVerb.BE, Verb('stop')]),
            Sentence([Pronoun.I, BeVerb.AM_NOT,
                      Verb('go')]),
            Sentence([Pronoun.THEY, BeVerb.WERE,
                      Verb('go')]),
            Sentence([Pronoun.HIM, BeVerb.WAS_NOT,
                      Verb('go')])
        ]
        self.assertEqual(error_paragraph.sentence_list(), expected)
Exemplo n.º 11
0
    def test_error_maker_verb_errors_p_error_middle_value(self):
        random.seed(4758)
        sentences = [
            Sentence([Verb('play'), Verb('like').third_person()]),
            Sentence([
                Verb('cry').negative(),
                Verb('dry').negative().third_person()
            ]),
            Sentence([
                Verb('pry').past_tense(),
                Verb('fry').negative().past_tense()
            ])
        ]
        paragraph = Paragraph(sentences)
        error_maker = ErrorMaker(paragraph)

        error_paragraph = error_maker.verb_errors(0.5).get_paragraph()
        expected = [
            Sentence([Verb('play'), Verb('like').past_tense()]),
            Sentence([
                Verb('cry').negative(),
                Verb('dry').negative().third_person()
            ]),
            Sentence([Verb('pry'), Verb('fry').negative()])
        ]
        self.assertEqual(error_paragraph.sentence_list(), expected)
Exemplo n.º 12
0
    def test_error_maker_pronoun_errors_p_error_gte_one(self):
        sentences = [
            Sentence([
                Pronoun.I, Pronoun.ME, Pronoun.YOU, Pronoun.HE, Pronoun.HIM,
                Pronoun.SHE, Pronoun.HER, Pronoun.IT, Pronoun.WE, Pronoun.US,
                Pronoun.THEY, Pronoun.THEM
            ]),
            Sentence([
                CapitalPronoun.I, Pronoun.ME, CapitalPronoun.YOU,
                CapitalPronoun.HE, Pronoun.HIM, CapitalPronoun.SHE,
                Pronoun.HER, CapitalPronoun.IT, CapitalPronoun.WE, Pronoun.US,
                CapitalPronoun.THEY, Pronoun.THEM
            ])
        ]
        expected = [
            Sentence([
                Pronoun.ME, Pronoun.I, Pronoun.YOU, Pronoun.HIM, Pronoun.HE,
                Pronoun.HER, Pronoun.SHE, Pronoun.IT, Pronoun.US, Pronoun.WE,
                Pronoun.THEM, Pronoun.THEY
            ]),
            Sentence([
                CapitalPronoun.ME, Pronoun.I, CapitalPronoun.YOU,
                CapitalPronoun.HIM, Pronoun.HE, CapitalPronoun.HER,
                Pronoun.SHE, CapitalPronoun.IT, CapitalPronoun.US, Pronoun.WE,
                CapitalPronoun.THEM, Pronoun.THEY
            ])
        ]
        paragraph = Paragraph(sentences)
        error_maker = ErrorMaker(paragraph)

        error_paragraph = error_maker.pronoun_errors(1.0).get_paragraph()
        self.assertEqual(error_paragraph.sentence_list(), expected)

        error_paragraph = error_maker.pronoun_errors(1.1).get_paragraph()
        self.assertEqual(error_paragraph.sentence_list(), expected)
Exemplo n.º 13
0
    def test_error_maker_noun_errors_p_error_gte_one(self):
        random.seed(4758)
        sentences = [
            Sentence([Noun('a').definite(),
                      Noun.proper_noun('C')]),
            Sentence([Noun('d').indefinite(),
                      Noun('e').plural()]),
            Sentence([Noun.uncountable_noun('f')])
        ]
        paragraph = Paragraph(sentences)
        error_maker = ErrorMaker(paragraph)

        error_paragraph = error_maker.noun_errors(1.0).get_paragraph()
        expected = [
            Sentence(
                [Noun('a').indefinite(),
                 Noun.proper_noun('C').indefinite()]),
            Sentence([Noun('d'), Noun('e').indefinite()]),
            Sentence([Noun.uncountable_noun('f').indefinite()])
        ]
        self.assertEqual(error_paragraph.sentence_list(), expected)

        error_paragraph = error_maker.noun_errors(1.1).get_paragraph()
        expected = [
            Sentence([Noun('a'), Noun.proper_noun('C').definite()]),
            Sentence([Noun('d'), Noun('e').indefinite()]),
            Sentence([Noun.uncountable_noun('f').plural()])
        ]
        self.assertEqual(error_paragraph.sentence_list(), expected)
Exemplo n.º 14
0
    def test_error_maker_order_of_errors_preposition_errors_affect_is_do_errors(
            self):
        sentences = [
            Sentence([
                CapitalPronoun.I,
                Verb('play'), Punctuation.PERIOD,
                BasicWord.preposition('with'), Pronoun.HIM
            ]),
            Sentence([
                Noun('dog').definite(),
                Verb('play').third_person(), Punctuation.PERIOD,
                BasicWord.preposition('with'), Pronoun.HIM
            ]),
        ]
        error_maker = ErrorMaker(Paragraph(sentences))

        is_do_preposition = error_maker.is_do_errors(1.0).preposition_errors(
            1.0).get_paragraph()
        expected_str = 'I with him am play. the dog with him is play.'
        self.assertEqual(str(is_do_preposition), expected_str)

        preposition_is_do = error_maker.preposition_errors(1.0).is_do_errors(
            1.0).get_paragraph()
        expected_str = 'I with him is play. the dog with him is play.'
        self.assertEqual(str(preposition_is_do), expected_str)
Exemplo n.º 15
0
    def test_error_maker_punctuation_errors_p_error_middle_value(self):
        random.seed(5812)
        sentences = [
            Sentence([CapitalPronoun.I,
                      Verb('go'), Punctuation.PERIOD]),
            Sentence([CapitalPronoun.HE,
                      Verb('run'), Punctuation.EXCLAMATION]),
            Sentence([Noun('dog').definite().capitalize(),
                      Punctuation.PERIOD]),
            Sentence([BasicWord('A'), Punctuation.PERIOD])
        ]
        paragraph = Paragraph(sentences)
        error_maker = ErrorMaker(paragraph)

        error_paragraph = error_maker.punctuation_errors(0.5).get_paragraph()

        expected = [
            Sentence([CapitalPronoun.I,
                      Verb('go'), Punctuation.PERIOD]),
            Sentence([CapitalPronoun.HE,
                      Verb('run'), Punctuation.COMMA]),
            Sentence([Noun('dog').definite(), Punctuation.COMMA]),
            Sentence([BasicWord('a'), Punctuation.PERIOD])
        ]
        self.assertEqual(error_paragraph.sentence_list(), expected)
    def test_create_chain_paragraph_loop_safety_finally_returns_paragraph_with_repeat_words(
            self):
        random.seed(4564)
        verb_list = [
            VerbGroup(verb=Verb('give'),
                      preposition=None,
                      objects=2,
                      particle=None)
        ]

        repeats = RandomParagraph(0.0, verb_list, [Noun('joe'), Noun('bob')])
        paragraph = repeats.create_chain_paragraph(3)
        sentences = [
            Sentence(
                [Noun('bob'),
                 Verb('give'),
                 Noun('joe'),
                 Noun('bob'), PERIOD]),
            Sentence(
                [Noun('bob'),
                 Verb('give'),
                 Noun('bob'),
                 Noun('joe'), PERIOD]),
            Sentence(
                [Noun('joe'),
                 Verb('give'),
                 Noun('bob'),
                 Noun('joe'), PERIOD]),
        ]
        expected = Paragraph(sentences, self.raw_tags)
        self.assertEqual(expected, paragraph)
 def test_create_pool_paragraph_output(self):
     random.seed(3)
     paragraph = self.rp.create_pool_paragraph(2, 5)
     sentences = [
         Sentence([Noun('pig'),
                   Verb('eat'),
                   Noun('sand'), PERIOD]),
         Sentence(
             [Noun('pig'),
              Verb('give'),
              Noun('milk'),
              Noun('cat'), PERIOD]),
         Sentence([
             Noun('pig'),
             Verb('jump'),
             BasicWord.preposition('over'),
             Noun('water'), PERIOD
         ]),
         Sentence([Noun('sand'), Verb('eat'), IT, PERIOD]),
         Sentence([
             Noun('sand'),
             Verb('give'),
             Noun('water'),
             BasicWord.preposition('to'),
             Noun('milk'), EXCLAMATION
         ])
     ]
     expected = Paragraph(sentences, self.raw_tags)
     self.assertEqual(paragraph, expected)
Exemplo n.º 18
0
 def _to_paragraph(cls, python_dict):
     sentence_list = [
         cls._to_sentence(sentence)
         for sentence in python_dict['sentence_list']
     ]
     tags = cls._to_status_tags(python_dict['tags'])
     return Paragraph(sentence_list, tags)
Exemplo n.º 19
0
 def test_find(self):
     paragraph = Paragraph.from_word_lists([
         [BasicWord('x'), BasicWord('y')],
         [BasicWord('z'), BasicWord('y'), BasicWord('x')],
         [BasicWord('q')]
     ])
     self.assertEqual(paragraph.find(BasicWord('x')), [(0, 0), (1, 2)])
Exemplo n.º 20
0
    def test_init(self):
        answer_paragraph = Paragraph([Sentence([BasicWord('a')])])
        submission_str = 'b'

        comparitor = ParagraphComparison(answer_paragraph, submission_str)
        self.assertEqual(comparitor.answer, answer_paragraph)
        self.assertEqual(comparitor.submission, 'b')
    def create_pool_paragraph(self, pool_size: int,
                              num_sentences: int) -> Paragraph:
        subjects = self.get_subject_pool(pool_size)

        sentences = []
        for _ in range(num_sentences):
            subj = random.choice(subjects)
            sentences.append(self._word_maker.sentence(subj, self._p_pronoun))
        return Paragraph(sentences, self._raw_tag)
def get_countable_nouns(paragraph: Paragraph) -> List[Noun]:
    out = []  # Sets are untestable with random.seed
    for word in paragraph.all_words():  # type: Noun
        if is_countable_noun(word):
            base_word = word.to_basic_noun()
            if base_word not in out:
                out.append(base_word)

    return out
 def test_create_answer_paragraph_makes_grammatically_correct_paragraph_if_base_paragraph_word_order_is_ok(self):
     base_sentences = [Sentence([Pronoun.HE, Verb('like'), Noun('dog'), Punctuation.PERIOD]),
                       Sentence([Noun('dog'), Verb('go'), BasicWord.preposition('to'), Noun('house'),
                                 Punctuation.PERIOD])]
     base_paragraph = Paragraph(base_sentences)
     answer = create_answer_paragraph('', base_paragraph)
     with_plurals = PluralsAssignment(base_paragraph).assign_plural([])
     grammatical = Grammarizer(with_plurals).grammarize_to_present_tense()
     self.assertEqual(answer, grammatical)
    def test_create_answer_paragraph_makes_paragraph_according_to_plurals_in_paragraph_str(self):
        base_sentences = [Sentence([Noun('dog'), Verb('like'), Noun('cat'), Punctuation.PERIOD])]
        base_paragraph = Paragraph(base_sentences)
        paragaph_str = 'A dog like cats,'
        answer = create_answer_paragraph(paragaph_str, base_paragraph)

        with_plurals = PluralsAssignment(base_paragraph).assign_plural([Noun('cat')])
        expected = Grammarizer(with_plurals).grammarize_to_present_tense()
        self.assertEqual(answer, expected)
Exemplo n.º 25
0
    def test_iteration(self):
        sentence_list = [Sentence([BasicWord('hi')]), Sentence([BasicWord('ho')])]
        tags = Tags([StatusTag.RAW])
        paragraph = Paragraph(sentence_list, tags)
        for index, sentence in enumerate(paragraph):
            self.assertEqual(sentence, sentence_list[index])

        self.assertTrue(sentence_list[0] in paragraph)
        self.assertFalse(Sentence([BasicWord('hope')]) in paragraph)
    def test_create_answer_paragraph_picks_plural_when_plural_and_singular_present(self):
        base_sentences = [Sentence([Noun('dog'), Verb('like'), Noun('dog'), Punctuation.PERIOD])]
        base_paragraph = Paragraph(base_sentences)

        with_plurals = PluralsAssignment(base_paragraph).assign_plural([Noun('dog')])
        expected = Grammarizer(with_plurals).grammarize_to_present_tense()
        for paragraph_Str in ('dogs like a dog.', 'a dog like dogs.'):
            answer = create_answer_paragraph(paragraph_Str, base_paragraph)
            self.assertEqual(answer, expected)
    def test_create_answer_paragraph_can_pick_plural_when_paragraph_str_has_capital_letters(self):
        base_sentences = [Sentence([Noun('dog'), Verb('like'), Noun('cat'), Punctuation.PERIOD])]
        base_paragraph = Paragraph(base_sentences)
        paragaph_str = 'DOGS like CATS'
        answer = create_answer_paragraph(paragaph_str, base_paragraph)

        with_plurals = PluralsAssignment(base_paragraph).assign_plural([Noun('dog'), Noun('cat')])
        expected = Grammarizer(with_plurals).grammarize_to_present_tense()
        self.assertEqual(answer, expected)
    def test_create_answer_paragraph_is_in_past_tense_if_has_tag_simple_past(self):
        base_sentences = [Sentence([Noun('dog'), Verb('like'), Noun('cat'), Punctuation.PERIOD])]
        base_paragraph = Paragraph(base_sentences, Tags([StatusTag.SIMPLE_PAST]))
        paragaph_str = 'A dog liked cats,'
        answer = create_answer_paragraph(paragaph_str, base_paragraph)

        with_plurals = PluralsAssignment(base_paragraph).assign_plural([Noun('cat')])
        expected = Grammarizer(with_plurals).grammarize_to_past_tense()
        self.assertEqual(answer, expected)
Exemplo n.º 29
0
 def test_to_obj_with_tagged_BasicWord_in_sentence(self):
     paragraph = Paragraph([
         Sentence([
             BasicWord('x', Tags([tag for tag in WordTag])),
             BasicWord('y')
         ])
     ])
     as_dict = Serializer.to_dict(paragraph)
     self.assertEqual(Serializer.to_obj(as_dict), paragraph)
Exemplo n.º 30
0
 def test_compare_by_sentence_paragraph_str_eq_submission_str(self):
     answer_paragraph = Paragraph([Sentence([BasicWord('a')])])
     submission_str = str(answer_paragraph)
     comparitor = ParagraphComparison(answer_paragraph, submission_str)
     comparison = comparitor.compare_by_sentences()
     expected = {
         'error_count': 0,
         'hint_paragraph': submission_str,
         'missing_sentences': 0
     }
     self.assertEqual(comparison, expected)