Esempio n. 1
0
    def test_capitalize(self):
        word = BasicWord('abc', tags=self.preposition)
        self.assertEqual(word.capitalize(),
                         BasicWord('Abc', tags=self.preposition))

        capital = BasicWord('ABC')
        self.assertEqual(capital.capitalize(), capital)
Esempio n. 2
0
    def test_de_capitalize(self):
        word = BasicWord('ABC', tags=self.particle)
        self.assertEqual(word.de_capitalize(),
                         BasicWord('aBC', tags=self.particle))

        lower = BasicWord('abc')
        self.assertEqual(lower.de_capitalize(), lower)
Esempio n. 3
0
    def test_iteration_in_function(self):
        sentence = Sentence([BasicWord('I'), BeVerb.AM, Punctuation.PERIOD])
        self.assertTrue(BeVerb.AM in sentence)
        self.assertFalse(Punctuation.COMMA in sentence)

        self.assertIn(BasicWord('I'), sentence)
        self.assertNotIn(BeVerb.WERE, sentence)
 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])
Esempio n. 5
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_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 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)
Esempio n. 8
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)
    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)
Esempio n. 10
0
def get_word(
        submission_str: str,
        word: AbstractWord) -> Tuple[AbstractWord, Optional[Tuple[int, int]]]:
    location = find_word_group(word, submission_str)
    if location is None:
        return BasicWord('MISSING'), None
    sub_str = submission_str[slice(*location)]
    new_word = BasicWord(sub_str)
    return new_word, location
    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_init(self):
        sentence_list = [Sentence([BasicWord('hi')]), Sentence([BasicWord('ho')])]
        tags = Tags([StatusTag.RAW])

        paragraph = Paragraph(sentence_list, tags)
        self.assertEqual(paragraph.tags, tags)
        self.assertEqual(paragraph.sentence_list(), sentence_list)
        self.assertIsNot(paragraph.tags, tags)
        self.assertIsNot(paragraph.sentence_list(), sentence_list)

        old_sentence_list = paragraph.sentence_list()
        sentence_list[0] = Sentence([BasicWord('yo')])
        self.assertEqual(paragraph.sentence_list(), old_sentence_list)
        self.assertNotEqual(paragraph.sentence_list(), sentence_list)
Esempio n. 13
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))
Esempio n. 15
0
    def test_compare_by_sentence_allows_periods_to_replace_exclamation_points(
            self):
        answer = Paragraph([
            Sentence([BasicWord('a'), Punctuation.PERIOD]),
            Sentence([BasicWord('b'), Punctuation.PERIOD])
        ])
        submission = 'a! b!'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 0,
            'hint_paragraph': submission,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Esempio n. 16
0
    def test_compare_by_words_no_errors(self):
        answer = Paragraph([
            Sentence([BasicWord('a'), Punctuation.PERIOD]),
            Sentence([BasicWord('b'), Punctuation.PERIOD])
        ])
        submission = 'a. b.'
        hint_paragraph = 'a. b.'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_words()
        expected = {
            'error_count': 0,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
 def test_is_countable_noun_false(self):
     self.assertFalse(is_countable_noun(BasicWord('dog')))
     self.assertFalse(is_countable_noun(Noun.uncountable_noun('water')))
     self.assertFalse(
         is_countable_noun(Noun.proper_noun('Joe', plural=False)))
     self.assertFalse(
         is_countable_noun(Noun.proper_noun('the Joes', plural=True)))
Esempio n. 18
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')
Esempio n. 19
0
    def test_compare_by_sentence_answer_has_less_sentences(self):
        answer = Paragraph([
            Sentence([BasicWord('a'), Punctuation.PERIOD]),
            Sentence([BasicWord('b'), Punctuation.PERIOD])
        ])
        submission = 'a. c. b.'
        hint_paragraph = 'a. <bold>c.</bold> <bold>b.</bold>'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 2,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': -1
        }
        self.assertEqual(hints, expected)
    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)
Esempio n. 21
0
    def test_compare_by_sentence_will_find_the_final_sentence_with_missing_punctuation(
            self):
        answer = Paragraph([
            Sentence([BasicWord('a'), Punctuation.PERIOD]),
            Sentence([BasicWord('b'), Punctuation.PERIOD])
        ])
        submission = 'a. b'
        hint_paragraph = 'a. <bold>b</bold>'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 1,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
 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)])
Esempio n. 23
0
    def test_compare_by_sentence_can_identify_period_comma_exclamation_question(
            self):
        answer = Paragraph([
            Sentence([BasicWord('a'), Punctuation.PERIOD]),
            Sentence([BasicWord('b'), Punctuation.EXCLAMATION]),
            Sentence([BasicWord('c'), Punctuation.QUESTION]),
            Sentence([BasicWord('d'), Punctuation.COMMA])
        ])
        submission = 'a, b, c, d,'
        hint_paragraph = '<bold>a,</bold> <bold>b,</bold> <bold>c,</bold> d,'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 3,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Esempio n. 24
0
    def test_compare_by_sentence_one_sentence_different_by_internals(self):
        answer = Paragraph([
            Sentence([BasicWord('Hello'), Punctuation.PERIOD]),
            Sentence([
                BasicWord('I'),
                BasicWord('am'),
                BasicWord('man'), Punctuation.PERIOD
            ])
        ])
        submission = 'Hello. I am mans.'
        hint_paragraph = 'Hello. <bold>I am mans.</bold>'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 1,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)
Esempio n. 25
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)
Esempio n. 26
0
 def test_to_dict_with_tagless_BasicWord_in_sentence(self):
     paragraph = Paragraph([Sentence([BasicWord('x'), BasicWord('y')])])
     word_list = [{
         'class': 'BasicWord',
         'value': 'x',
         'tags': []
     }, {
         'class': 'BasicWord',
         'value': 'y',
         'tags': []
     }]
     expected = {
         'class': 'Paragraph',
         'sentence_list': [{
             'class': 'Sentence',
             'word_list': word_list
         }],
         'tags': [],
     }
     self.assertEqual(Serializer.to_dict(paragraph), expected)
 def test_get_countable_nouns(self):
     sentence_list = [
         Sentence(
             [Noun.uncountable_noun('water'),
              BasicWord('is'),
              Noun('pig')]),
         Sentence([Noun.proper_noun('Joe'),
                   Noun('pig'),
                   Noun('dog')])
     ]
     paragraph = Paragraph(sentence_list)
     self.assertEqual(get_countable_nouns(paragraph),
                      [Noun('pig'), Noun('dog')])
Esempio n. 28
0
    def test_error_maker_preposition_errors_p_error_middle_value(self):
        random.seed(5812)
        sentences = [
            Sentence([Verb('go'),
                      BasicWord.preposition('with'), Pronoun.ME]),
            Sentence([
                Verb('go'),
                BasicWord.preposition('over'),
                BasicWord('there')
            ]),
            Sentence([Verb('go'),
                      BasicWord.preposition('into'), Pronoun.IT]),
            Sentence([
                Verb('go'),
                BasicWord.preposition('under'),
                BasicWord('that')
            ])
        ]
        paragraph = Paragraph(sentences)
        error_maker = ErrorMaker(paragraph)

        error_paragraph = error_maker.preposition_errors(0.5).get_paragraph()
        expected = [
            Sentence([Verb('go'),
                      BasicWord.preposition('with'), Pronoun.ME]),
            Sentence([
                BasicWord.preposition('over'),
                BasicWord('there'),
                Verb('go')
            ]),
            Sentence([BasicWord.preposition('into'), Pronoun.IT,
                      Verb('go')]),
            Sentence([
                Verb('go'),
                BasicWord.preposition('under'),
                BasicWord('that')
            ])
        ]
        self.assertEqual(error_paragraph.sentence_list(), expected)
    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)
Esempio n. 30
0
    def test_compare_by_sentence_commas_are_counted_as_sentences(self):
        answer = Paragraph(
            [Sentence([BasicWord(wd), Punctuation.PERIOD]) for wd in 'ABC'])
        submission = 'A, B. C,'
        hint_paragraph = '<bold>A,</bold> B. <bold>C,</bold>'

        comparitor = ParagraphComparison(answer, submission)
        hints = comparitor.compare_by_sentences()
        expected = {
            'error_count': 2,
            'hint_paragraph': hint_paragraph,
            'missing_sentences': 0
        }
        self.assertEqual(hints, expected)