예제 #1
0
    def test_get_be_verb_past_tense_plural_subject(self):
        plural_subj = [
            Noun('cat').plural(),
            Noun.proper_noun('the Joes', plural=True), Pronoun.YOU,
            CapitalPronoun.YOU, Pronoun.WE, Pronoun.US, CapitalPronoun.WE,
            CapitalPronoun.US, Pronoun.THEY, Pronoun.THEM, CapitalPronoun.THEY,
            CapitalPronoun.THEM
        ]
        for subj in plural_subj:
            sentence = Sentence([subj, Verb('go').past_tense()])
            self.assertEqual(get_be_verb(sentence), BeVerb.WERE)

            sentence = Sentence([subj, Verb('go').negative().past_tense()])
            self.assertEqual(get_be_verb(sentence), BeVerb.WERE_NOT)
예제 #2
0
    def test_assign_objects_no_objects_particle_or_preposition(self):
        verb_group = VerbGroup(verb=Verb('chill'),
                               preposition=BasicWord.preposition('out'),
                               objects=0,
                               particle=None)
        self.assertEqual(
            assign_objects(verb_group, []),
            [Verb('chill'), BasicWord.preposition('out')])

        verb_group = VerbGroup(verb=Verb('run'),
                               preposition=None,
                               objects=0,
                               particle=BasicWord.particle('away'))
        self.assertEqual(assign_objects(verb_group, []),
                         [Verb('run'), BasicWord.particle('away')])
예제 #3
0
    def test_get_be_verb_present_tense_singular_subject(self):
        singular_subj = [
            Noun('cat').definite(),
            Noun('cat').indefinite(),
            Noun.uncountable_noun('water'),
            Noun.proper_noun('Joe'), Pronoun.HE, Pronoun.HIM, Pronoun.SHE,
            Pronoun.HER, Pronoun.IT, CapitalPronoun.HE, CapitalPronoun.HIM,
            CapitalPronoun.SHE, CapitalPronoun.HER, CapitalPronoun.IT
        ]
        for subj in singular_subj:
            sentence = Sentence([subj, Verb('go')])
            self.assertEqual(get_be_verb(sentence), BeVerb.IS)

            sentence = Sentence([subj, Verb('go').negative()])
            self.assertEqual(get_be_verb(sentence), BeVerb.IS_NOT)
예제 #4
0
    def test_negative_basic_verb(self):
        verb = Verb('play')
        self.assertEqual(verb.negative(),
                         Verb("don't play", '', 'play', tags=self.negative))

        verb = Verb('have', 'had')
        self.assertEqual(verb.negative(),
                         Verb("don't have", 'had', 'have', tags=self.negative))
예제 #5
0
    def test_third_person_basic_verb(self):
        verb = Verb('play')
        self.assertEqual(verb.third_person(),
                         Verb('plays', '', 'play', tags=self.third_person))

        verb = Verb('go', 'went')
        self.assertEqual(verb.third_person(),
                         Verb('goes', 'went', 'go', tags=self.third_person))
예제 #6
0
 def test_makes_copy_of_input_list(self):
     random.seed(148)
     for index in range(4):
         self.countable[index] = Noun('oops')
         self.uncountable[index] = Noun('oops')
         self.verbs[index] = VerbGroup(Verb('a'), BasicWord('b'),
                                       BasicWord('c'), 4)
     answer = self.generator.predicate()
     expected = [
         Verb('lend'),
         Noun('dog'),
         BasicWord.preposition('to'),
         Noun('milk'), PERIOD
     ]
     self.assertEqual(answer, expected)
    def test_p_negative_gte_one(self):
        expected_list = [
            Sentence([BasicWord('a'),
                      Verb('b').negative(),
                      BasicWord('c')]),
            Sentence([BasicWord('d'), Verb('e').negative()])
        ]

        to_test = assign_random_negatives(self.paragraph, p_negative=1.0)
        self.assertEqual(to_test.sentence_list(), expected_list)
        self.assertEqual(to_test.tags, self.tags.add(StatusTag.HAS_NEGATIVES))

        to_test = assign_random_negatives(self.paragraph, p_negative=1.1)
        self.assertEqual(to_test.sentence_list(), expected_list)
        self.assertEqual(to_test.tags, self.tags.add(StatusTag.HAS_NEGATIVES))
예제 #8
0
 def test_make_verb_error_present_third_person(self):
     random.seed(6)
     verb = Verb('play').third_person()
     plus_ed = [2, 8]
     plus_ed_plus_s = [0, 7]
     for index in range(10):
         to_test = make_verb_error(verb)
         if index in plus_ed:
             self.assertEqual(Verb('played', '', 'play', tags=self.past),
                              to_test)
         elif index in plus_ed_plus_s:
             self.assertEqual(Verb('playeds', '', 'play', tags=self.past),
                              to_test)
         else:
             self.assertEqual(Verb('play'), to_test)
 def test_eq_true(self):
     verb = Verb('go')
     objects = 1
     preposition = None
     particle = BasicWord.particle('x')
     to_test = VerbGroup(verb, preposition, particle, objects)
     self.assertEqual(to_test, VerbGroup(verb, preposition, particle, objects))
예제 #10
0
 def test_make_verb_error_present_negative_not_third_person(self):
     random.seed(6)
     verb = Verb('play').negative()
     plus_ed = [1, 6]
     for index in range(10):
         to_test = make_verb_error(verb)
         if index in plus_ed:
             self.assertEqual(
                 Verb("didn't play", '', 'play', tags=self.negative_past),
                 to_test)
         else:
             self.assertEqual(
                 Verb("doesn't play",
                      '',
                      'play',
                      tags=self.negative_third_person), to_test)
    def test_eq_false(self):
        verb = Verb('go')
        objects = 1
        preposition = None
        particle = BasicWord.particle('x')
        to_test = VerbGroup(verb, preposition, particle, objects)

        new_verb = Verb('z')
        new_objects = 2
        new_preposition = BasicWord.preposition('x')
        new_particle = BasicWord.particle('y')

        self.assertNotEqual(to_test, VerbGroup(new_verb, preposition, particle, objects))
        self.assertNotEqual(to_test, VerbGroup(verb, new_preposition, particle, objects))
        self.assertNotEqual(to_test, VerbGroup(verb, preposition, new_particle, objects))
        self.assertNotEqual(to_test, VerbGroup(verb, preposition, particle, new_objects))
예제 #12
0
 def test_assign_objects_one_object_particle_and_preposition(self):
     verb_group = VerbGroup(verb=Verb('put'),
                            preposition=BasicWord.preposition('with'),
                            objects=1,
                            particle=BasicWord.particle('up'))
     self.assertEqual(assign_objects(verb_group, [IT]), [
         Verb('put'),
         BasicWord.particle('up'),
         BasicWord.preposition('with'), IT
     ])
     self.assertEqual(assign_objects(verb_group, [Noun('dog')]), [
         Verb('put'),
         BasicWord.particle('up'),
         BasicWord.preposition('with'),
         Noun('dog')
     ])
예제 #13
0
 def test_make_verb_error_negative_past_tense(self):
     random.seed(6)
     verb = Verb('play').negative().past_tense()
     plus_s = [1, 2, 6, 7, 8]
     for index in range(10):
         to_test = make_verb_error(verb)
         if index in plus_s:
             self.assertEqual(
                 Verb("doesn't play",
                      '',
                      'play',
                      tags=self.negative_third_person), to_test)
         else:
             self.assertEqual(
                 Verb("don't play", '', 'play', tags=self.negative),
                 to_test)
예제 #14
0
 def test_find_verb_group_submission_str_irregular_past(self):
     submission_str = 'I went home.'
     base_verb = Verb('go', 'went')
     answer = find_verb_group(base_verb, submission_str)
     start = submission_str.find('went')
     end = start + len('went')
     self.assertEqual(answer, (start, end))
예제 #15
0
 def test_find_word_group_verb(self):
     word = Verb('play')
     submission_str = "a didn't play."
     answer = find_word_group(word, submission_str)
     start = 2
     end = start + len("didn't play")
     self.assertEqual(answer, (start, end))
예제 #16
0
 def test_find_verb_group_upper_case(self):
     submission_str = 'the dogs Play.'
     word = Verb('play')
     answer = find_verb_group(word, submission_str)
     start = len('the Dogs ')
     end = start + len('Play')
     self.assertEqual(answer, (start, end))
예제 #17
0
    def test_compare_by_words_extra_word_errors(self):
        answer = Paragraph([
            Sentence([Verb('go', 'went'), Punctuation.PERIOD]),
            Sentence([Verb('play'), Punctuation.PERIOD])
        ])
        submission = "I go. play it."
        hint_paragraph = "<bold>I</bold> go. play <bold>it</bold>."

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 2,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
예제 #18
0
    def test_compare_by_words_punctuation_errors(self):
        answer = Paragraph([
            Sentence([Verb('go', 'went'), Punctuation.PERIOD]),
            Sentence([Verb('play'), Punctuation.PERIOD])
        ])
        submission = "go, play "
        hint_paragraph = "go<bold>,</bold> play <bold>MISSING</bold>"

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 2,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
예제 #19
0
    def test_assign_objects_two_objects_preposition(self):
        verb_group = VerbGroup(verb=Verb('bring'),
                               preposition=BasicWord.preposition('to'),
                               objects=2,
                               particle=None)
        self.assertEqual(assign_objects(verb_group, [HIM, IT]),
                         [Verb('bring'), HIM,
                          BasicWord.preposition('to'), IT])

        self.assertEqual(
            assign_objects(verb_group, [Noun('cat'), Noun('dog')]), [
                Verb('bring'),
                Noun('cat'),
                BasicWord.preposition('to'),
                Noun('dog')
            ])
예제 #20
0
    def test_compare_by_word_punctuation_allows_period_and_exclamation_point_to_be_switched(
            self):
        answer = Paragraph([
            Sentence([Verb('go', 'went'), Punctuation.PERIOD]),
            Sentence([Verb('go', 'went'), Punctuation.EXCLAMATION])
        ])
        submission = "go! go."

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 0,
            'hint_paragraph': submission,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
예제 #21
0
 def test_find_verb_group_submission_str_special_rule_regular_past_tense(
         self):
     submission_str = 'He babied me.'
     word = Verb('baby')
     answer = find_verb_group(word, submission_str)
     start = submission_str.find('babied')
     end = start + len('babied')
     self.assertEqual(answer, (start, end))
 def test_create_chain_paragraph_assigns_random_subj_if_no_obj(self):
     random.seed(11)
     verb_list = [
         VerbGroup(verb=Verb('jump'),
                   preposition=None,
                   objects=0,
                   particle=None)
     ]
     rp = RandomParagraph(0.2, verb_list, self.countable + self.uncountable)
     answer = rp.create_chain_paragraph(3)
     sentences = [
         Sentence([Noun('sand'), Verb('jump'), EXCLAMATION]),
         Sentence([Noun('frog'), Verb('jump'), EXCLAMATION]),
         Sentence([Noun('pig'), Verb('jump'), PERIOD])
     ]
     expected = Paragraph(sentences, self.raw_tags)
     self.assertEqual(expected, answer)
예제 #23
0
 def test_make_verb_error_present_negative_third_person(self):
     random.seed(6)
     verb = Verb('play').negative().third_person()
     plus_ed = [2, 8]
     plus_ed_plus_s = [0, 7]
     for index in range(10):
         to_test = make_verb_error(verb)
         if index in plus_ed:
             self.assertEqual(
                 Verb("didn't play", '', 'play', tags=self.negative_past),
                 to_test)
         elif index in plus_ed_plus_s:
             self.assertEqual(
                 Verb("didn't plays", '', "play", tags=self.negative_past),
                 to_test)
         else:
             self.assertEqual(Verb('play').negative(), to_test)
예제 #24
0
    def test_error_maker_is_do_errors_p_error_lte_zero(self):
        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(0.0).get_paragraph()
        self.assertEqual(error_paragraph.sentence_list(), sentences)

        error_paragraph = error_maker.is_do_errors(-1.0).get_paragraph()
        self.assertEqual(error_paragraph.sentence_list(), sentences)
예제 #25
0
    def test_negative_past_verb(self):
        verb = Verb('played', '', 'play', tags=self.past)
        self.assertEqual(
            verb.negative(),
            Verb("didn't play", '', 'play', tags=self.negative_past))

        verb = Verb('went', 'went', 'go', tags=self.past)
        self.assertEqual(
            verb.negative(),
            Verb("didn't go", 'went', 'go', tags=self.negative_past))
예제 #26
0
 def test_find_verb_group_all_prefixes(self):
     prefixes = ["Don't", "don't", "Doesn't", "doesn't", "Didn't", "didn't"]
     verb = Verb('play')
     for prefix in prefixes:
         submission_str = f'the cat {prefix} play here.'
         answer = find_verb_group(verb, submission_str)
         start = len('the cat ')
         end = start + len(f'{prefix} play')
         self.assertEqual(answer, (start, end))
예제 #27
0
 def test_assign_objects_two_objects_particle_and_preposition(self):
     verb_group = VerbGroup(verb=Verb('throw'),
                            preposition=BasicWord.preposition('for'),
                            objects=2,
                            particle=BasicWord.particle('away'))
     self.assertEqual(assign_objects(verb_group, [HIM, IT]), [
         Verb('throw'), HIM,
         BasicWord.particle('away'),
         BasicWord.preposition('for'), IT
     ])
     self.assertEqual(
         assign_objects(verb_group, [Noun('cat'), Noun('dog')]), [
             Verb('throw'),
             BasicWord.particle('away'),
             Noun('cat'),
             BasicWord.preposition('for'),
             Noun('dog')
         ])
예제 #28
0
 def test_compare_sentences(self):
     sentence = Sentence([
         Noun('dog').definite().capitalize(),
         Verb('play').third_person(), Punctuation.PERIOD
     ])
     submission_str = 'The dog plays.'
     answer = compare_sentences(sentence, submission_str)
     expected = {'hint_sentence': submission_str, 'error_count': 0}
     self.assertEqual(answer, expected)
예제 #29
0
 def test_compare_sentences_missing_punctuation(self):
     sentence = Sentence([Verb('go').capitalize(), Punctuation.PERIOD])
     submission_str = 'Go'
     answer = compare_sentences(sentence, submission_str)
     expected = {
         'hint_sentence': 'Go <bold>MISSING</bold>',
         'error_count': 1
     }
     self.assertEqual(answer, expected)
예제 #30
0
def find_verb_group(word: Verb, submission_str):
    prefixes = ["don't", "doesn't", "didn't"]
    all_prefixes = prefixes + [word.capitalize() for word in prefixes]
    prefix_regex = '({})'.format('|'.join(all_prefixes))

    base_word = word.to_basic_verb()

    base_value = base_word.value
    third_person_value = base_word.third_person().value
    past_value = base_word.past_tense().value

    base_regex = _get_dual_case(base_value)
    plural_regex = _get_dual_case(third_person_value)
    past_regex = _get_dual_case(past_value)

    word_regex = f'({base_regex}|{plural_regex}|{past_regex})'

    return _find_from_regex(prefix_regex, word_regex, submission_str)