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_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)
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)
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)
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)
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)
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)
def _create_errors(self, answer): preposition_errors_config_to_method_name = {'preposition_transpose_errors': 'preposition_errors'} error_types = ['noun_errors', 'pronoun_errors', 'verb_errors', 'is_do_errors', 'punctuation_errors'] config_name_to_method_name = {key: key for key in error_types} config_name_to_method_name.update(preposition_errors_config_to_method_name) methods = [value for key, value in config_name_to_method_name.items() if self.get(key)] error_maker = ErrorMaker(answer) p_error = self.get('error_probability') for method in methods: error_maker = getattr(error_maker, method)(p_error) return error_maker
def test_error_maker_preposition_error_does_not_affect_others(self): sentences = [ Sentence([ Verb('a'), Noun('a'), BeVerb.AM, Pronoun.HIM, CapitalPronoun.ME, Punctuation.COMMA ]) ] error_maker = ErrorMaker(Paragraph(sentences)) error_paragraph = error_maker.preposition_errors(1.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences)
def test_error_maker_pronoun_error_does_not_affect_others(self): sentences = [ Sentence([ BasicWord.preposition('a'), Verb('a'), Noun('a'), Punctuation.COMMA, BeVerb.AM ]) ] error_maker = ErrorMaker(Paragraph(sentences)) error_paragraph = error_maker.pronoun_errors(1.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences)
def test_error_maker_pronoun_errors_p_error_lte_zero(self): sentences = [ Sentence([Pronoun.HE, Pronoun.THEY, Pronoun.ME, Pronoun.YOU]) ] paragraph = Paragraph(sentences) error_maker = ErrorMaker(paragraph) error_paragraph = error_maker.pronoun_errors(0.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences) error_paragraph = error_maker.pronoun_errors(-1.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences)
def test_error_maker_pronoun_error_p_error_middle(self): random.seed(47534) sentences = [ Sentence([Pronoun.I, Pronoun.HE]), Sentence([Pronoun.US, Pronoun.THEM]) ] paragraph = Paragraph(sentences) error_maker = ErrorMaker(paragraph) error_paragraph = error_maker.pronoun_errors(0.5).get_paragraph() expected = [ Sentence([Pronoun.ME, Pronoun.HE]), Sentence([Pronoun.US, Pronoun.THEY]) ] self.assertEqual(error_paragraph.sentence_list(), expected)
def test_regression_test_verb_error_is_do_error(self): random.seed(11) paragraph = Paragraph( [Sentence([Pronoun.HE, Verb('play').negative().third_person()])]) error_maker = ErrorMaker(paragraph) verb_error = error_maker.verb_errors(1.0) verb_is_do_error = verb_error.is_do_errors(1.0) expected_verb_error = "he didn't plays" expected_verb_is_do_error = "he was not play" self.assertEqual(str(verb_error.get_paragraph()), expected_verb_error) self.assertEqual(str(verb_is_do_error.get_paragraph()), expected_verb_is_do_error)
def test_error_maker_verb_errors_retains_capital_letters_in_first_word( self): sentences = [ Sentence([Verb('A'), Verb('b')]), Sentence([Verb('d'), Verb('e')]), Sentence([Verb('F'), Verb('g')]) ] error_maker = ErrorMaker(Paragraph(sentences)) error_pargraph = error_maker.pronoun_errors(1.0).get_paragraph() capitals = [0, 2] for index, sentence in enumerate(error_pargraph): first_word = sentence.get(0) if index in capitals: self.assertEqual(first_word.capitalize(), first_word) else: self.assertNotEqual(first_word.capitalize(), first_word)
def test_error_maker_pronoun_errors_retains_capital_letters_in_first_word( self): sentences = [ Sentence([CapitalPronoun.I, Pronoun.ME]), Sentence([Pronoun.HIM, Pronoun.HE]), Sentence([CapitalPronoun.HER, Pronoun.THEY]) ] error_maker = ErrorMaker(Paragraph(sentences)) error_pargraph = error_maker.pronoun_errors(1.0).get_paragraph() capitals = [0, 2] for index, sentence in enumerate(error_pargraph): first_word = sentence.get(0) if index in capitals: self.assertEqual(first_word.capitalize(), first_word) else: self.assertNotEqual(first_word.capitalize(), first_word)
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)
def test_error_maker_noun_errors_p_error_lte_zero(self): sentences = [ Sentence([ Noun('a'), Noun('b').plural(), Noun.uncountable_noun('c'), Noun.proper_noun('e') ]) ] paragraph = Paragraph(sentences) error_maker = ErrorMaker(paragraph) error_paragraph = error_maker.noun_errors(0.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences) error_paragraph = error_maker.noun_errors(-1.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences)
def test_error_maker_noun_error_p_error_middle(self): random.seed(475456) sentences = [ Sentence([Noun('a').definite(), Noun.proper_noun('C')]), Sentence([Noun('d').indefinite(), Noun('e').plural()]) ] paragraph = Paragraph(sentences) error_maker = ErrorMaker(paragraph) error_paragraph = error_maker.noun_errors(0.5).get_paragraph() expected = [ sentences[0], Sentence([Noun('d'), Noun('e').plural().indefinite()]) ] self.assertEqual(error_paragraph.sentence_list(), expected)
def test_error_maker_preposition_errors_complex_case(self): sentence = Sentence([ Pronoun.I, Verb('pick'), Pronoun.IT, BasicWord.particle('up'), BasicWord.preposition('with'), Noun('toe').indefinite(), Punctuation.PERIOD ]) expected = Sentence([ Pronoun.I, BasicWord.preposition('with'), Noun('toe').indefinite(), Verb('pick'), Pronoun.IT, BasicWord.particle('up'), Punctuation.PERIOD ]) error_paragraph = ErrorMaker(Paragraph( [sentence])).preposition_errors(1.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), [expected])
def test_error_maker_punctuation_errors_p_error_lte_zero(self): sentences = [ Sentence([ CapitalPronoun.I, Verb('go'), Pronoun.HIM, Punctuation.PERIOD ]), Sentence([ CapitalPronoun.HE, Verb('run'), Pronoun.IT, Punctuation.EXCLAMATION ]) ] paragraph = Paragraph(sentences) error_maker = ErrorMaker(paragraph) error_paragraph = error_maker.punctuation_errors(0.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences) error_paragraph = error_maker.punctuation_errors(-1.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences)
def test_error_maker_empty_paragraph(self): paragraph = Paragraph([]) error_maker = ErrorMaker(paragraph) self.assertEqual( error_maker.noun_errors(1.0).get_paragraph().sentence_list(), []) self.assertEqual( error_maker.pronoun_errors(1.0).get_paragraph().sentence_list(), []) self.assertEqual( error_maker.verb_errors(1.0).get_paragraph().sentence_list(), []) self.assertEqual( error_maker.is_do_errors(1.0).get_paragraph().sentence_list(), []) self.assertEqual( error_maker.preposition_errors( 1.0).get_paragraph().sentence_list(), []) self.assertEqual( error_maker.punctuation_errors( 1.0).get_paragraph().sentence_list(), [])
def test_error_maker_preposition_errors_retains_capital_letters_in_first_word( self): sentences = [ Sentence([Verb('Go'), BasicWord.preposition('with'), Pronoun.HIM]), Sentence([Verb('go'), BasicWord.preposition('with'), Pronoun.HIM]), Sentence([Verb('Eat'), BasicWord.preposition('at'), Noun("Joe's")]) ] error_maker = ErrorMaker(Paragraph(sentences)) error_pargraph = error_maker.pronoun_errors(1.0).get_paragraph() capitals = [0, 2, 3] for index, sentence in enumerate(error_pargraph): first_word = sentence.get(0) if index in capitals: self.assertEqual(first_word.capitalize(), first_word) else: self.assertNotEqual(first_word.capitalize(), first_word)
def test_error_maker_is_do_errors_p_error_middle_value(self): random.seed(5812) sentences = [ Sentence([Pronoun.I, Verb('go')]), Sentence([Pronoun.YOU, Verb('go')]), Sentence([Pronoun.HE, Verb('go')]), Sentence([Pronoun.WE, Verb('go')]) ] paragraph = Paragraph(sentences) error_maker = ErrorMaker(paragraph) error_paragraph = error_maker.is_do_errors(0.5).get_paragraph() expected = [ Sentence([Pronoun.I, Verb('go')]), Sentence([Pronoun.YOU, BeVerb.ARE, Verb('go')]), Sentence([Pronoun.HE, BeVerb.IS, Verb('go')]), Sentence([Pronoun.WE, Verb('go')]) ] self.assertEqual(error_paragraph.sentence_list(), expected)
def test_error_maker_verb_errors_p_error_lte_zero(self): 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.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences) error_paragraph = error_maker.verb_errors(-1.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences)
def test_error_maker_preposition_errors_p_error_lte_zero(self): sentences = [ Sentence([ Pronoun.I, Verb('go'), BasicWord.preposition('with'), Pronoun.HIM ]), Sentence([ Pronoun.HE, Verb('run'), BasicWord.preposition('over'), Pronoun.IT ]) ] paragraph = Paragraph(sentences) error_maker = ErrorMaker(paragraph) error_paragraph = error_maker.preposition_errors(0.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences) error_paragraph = error_maker.preposition_errors(-1.0).get_paragraph() self.assertEqual(error_paragraph.sentence_list(), sentences)
def test_error_maker_order_of_errors_affects_verb_errors_is_do_errors( self): random.seed(4958) sentences = [ Sentence([CapitalPronoun.I, Verb('play'), Punctuation.PERIOD]), Sentence([CapitalPronoun.I, Verb('play'), Punctuation.PERIOD]), Sentence([ Noun('dog').definite(), Verb('play').third_person(), Punctuation.PERIOD ]), Sentence([ Noun('dog').definite(), Verb('play').third_person(), Punctuation.PERIOD ]), Sentence([CapitalPronoun.I, Verb('play'), Punctuation.PERIOD]), Sentence([ Noun('dog').definite(), Verb('play').third_person(), Punctuation.PERIOD ]), ] original_str = 'I play. I play. the dog plays. the dog plays. I play. the dog plays.' self.assertEqual(str(Paragraph(sentences)), original_str) error_maker = ErrorMaker(Paragraph(sentences)) verb_then_is_do = error_maker.verb_errors(1.0).is_do_errors( 1.0).get_paragraph() verb_then_is_do_str = 'I was play. I am play. the dog was play. the dog is play. I am play. the dog is play.' self.assertEqual(str(verb_then_is_do), verb_then_is_do_str) is_do_then_verb = error_maker.is_do_errors(1.0).verb_errors( 1.0).get_paragraph() is_do_then_verb_str = ( 'I am played. I am plays. the dog is plays.' ' the dog is played. I am played. the dog is plays.') self.assertEqual(str(is_do_then_verb), is_do_then_verb_str)
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_error_maker_punctuation_errors_p_error_gte_one(self): sentences = [ Sentence([ CapitalPronoun.I, Verb('go'), Pronoun.HIM, Punctuation.PERIOD ]), Sentence([ CapitalPronoun.HE, Verb('run'), Pronoun.IT, Punctuation.EXCLAMATION ]) ] paragraph = Paragraph(sentences) error_maker = ErrorMaker(paragraph) error_paragraph = error_maker.punctuation_errors(1.0).get_paragraph() expected = [ Sentence( [CapitalPronoun.I, Verb('go'), Pronoun.HIM, Punctuation.COMMA]), Sentence([Pronoun.HE, Verb('run'), Pronoun.IT, Punctuation.COMMA]) ] self.assertEqual(error_paragraph.sentence_list(), expected)
def test_error_maker_punctuation_errors_changes_tags(self): paragraph = Paragraph([], Tags([StatusTag.PRONOUN_ERRORS])) new_error_maker = ErrorMaker(paragraph).punctuation_errors(0.5) self.assertEqual(new_error_maker.get_paragraph().tags, paragraph.tags.add(StatusTag.PUNCTUATION_ERRORS))
def test_error_maker_is_do_errors_changes_tags(self): paragraph = Paragraph([], Tags([StatusTag.PRONOUN_ERRORS])) new_error_maker = ErrorMaker(paragraph).is_do_errors(0.5) self.assertEqual(new_error_maker.get_paragraph().tags, paragraph.tags.add(StatusTag.IS_DO_ERRORS))