Esempio n. 1
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)
Esempio n. 2
0
 def test_paragraph_with_empty_sentence(self):
     answer = Serializer.to_dict(Paragraph([Sentence([])]))
     expected = {
         'class': 'Paragraph',
         'sentence_list': [{
             'class': 'Sentence',
             'word_list': []
         }],
         'tags': [],
     }
     self.assertEqual(answer, expected)
Esempio n. 3
0
    def test_paragraph_with_tags(self):
        tag_list = [tag for tag in StatusTag]
        paragraph = Paragraph([], Tags(tag_list))

        answer = Serializer.to_dict(paragraph)
        tag_names = [tag.name for tag in StatusTag]
        expected = {
            'class': 'Paragraph',
            'sentence_list': [],
            'tags': tag_names
        }
        self.assertEqual(answer, expected)
Esempio n. 4
0
 def test_to_json(self):
     paragraph = Paragraph([
         Sentence([
             Verb('go').past_tense().capitalize().bold(),
             Noun.uncountable_noun('water'), Punctuation.PERIOD
         ]),
         Sentence([
             BasicWord.preposition('a'), Pronoun.I, CapitalPronoun.ME,
             BeVerb.AM,
             Punctuation.COMMA.bold()
         ])
     ], Tags([StatusTag.PUNCTUATION_ERRORS]))
     as_dict = Serializer.to_dict(paragraph)
     self.assertEqual(json.dumps(as_dict), Serializer.to_json(paragraph))
Esempio n. 5
0
 def test_to_dict_and_back_with_all_word_types_in_multiple_sentences(self):
     paragraph = Paragraph([
         Sentence([
             Verb('go').past_tense().capitalize().bold(),
             Noun.uncountable_noun('water'), Punctuation.PERIOD
         ]),
         Sentence([
             BasicWord.preposition('a'), Pronoun.I, CapitalPronoun.ME,
             BeVerb.AM,
             Punctuation.COMMA.bold()
         ])
     ])
     as_dict = Serializer.to_dict(paragraph)
     as_obj = Serializer.to_obj(as_dict)
     self.assertEqual(as_obj, paragraph)
Esempio n. 6
0
 def test_to_dict_with_BeVerb_in_sentence(self):
     paragraph = Paragraph([Sentence([pronoun for pronoun in BeVerb])])
     word_list = [{
         'class': 'BeVerb',
         'name': pronoun.name
     } for pronoun in BeVerb]
     expected = {
         'class': 'Paragraph',
         'sentence_list': [{
             'class': 'Sentence',
             'word_list': word_list
         }],
         'tags': [],
     }
     self.assertEqual(Serializer.to_dict(paragraph), expected)
Esempio n. 7
0
 def test_to_dict_with_tagged_BasicWord_in_sentence(self):
     paragraph = Paragraph(
         [Sentence([BasicWord('x', Tags([tag for tag in WordTag]))])])
     tag_list = [tag.name for tag in WordTag]
     word_list = [
         {
             'class': 'BasicWord',
             'value': 'x',
             'tags': tag_list
         },
     ]
     expected = {
         'class': 'Paragraph',
         'sentence_list': [{
             'class': 'Sentence',
             'word_list': word_list
         }],
         'tags': [],
     }
     self.assertEqual(Serializer.to_dict(paragraph), expected)
Esempio n. 8
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)
Esempio n. 9
0
 def test_to_dict_with_tagged_Verb_in_sentence(self):
     paragraph = Paragraph(
         [Sentence([Verb('x', tags=Tags([tag for tag in WordTag]))])])
     tag_list = [tag.name for tag in WordTag]
     word_list = [
         {
             'class': 'Verb',
             'value': 'x',
             'irregular_past': '',
             'infinitive': 'x',
             'tags': tag_list
         },
     ]
     expected = {
         'class': 'Paragraph',
         'sentence_list': [{
             'class': 'Sentence',
             'word_list': word_list
         }],
         'tags': [],
     }
     self.assertEqual(Serializer.to_dict(paragraph), expected)
Esempio n. 10
0
 def test_to_dict_with_tagless_Verb_in_sentence(self):
     paragraph = Paragraph([Sentence([Verb('x'), Verb('y', 'z', 'q')])])
     word_list = [{
         'class': 'Verb',
         'value': 'x',
         'irregular_past': '',
         'infinitive': 'x',
         'tags': []
     }, {
         'class': 'Verb',
         'value': 'y',
         'irregular_past': 'z',
         'infinitive': 'q',
         'tags': []
     }]
     expected = {
         'class': 'Paragraph',
         'sentence_list': [{
             'class': 'Sentence',
             'word_list': word_list
         }],
         'tags': [],
     }
     self.assertEqual(Serializer.to_dict(paragraph), expected)
Esempio n. 11
0
 def test_to_dict_with_tagless_Noun_in_sentence(self):
     paragraph = Paragraph([Sentence([Noun('x'), Noun('y', 'z', 'q')])])
     word_list = [{
         'class': 'Noun',
         'value': 'x',
         'irregular_plural': '',
         'base_noun': 'x',
         'tags': []
     }, {
         'class': 'Noun',
         'value': 'y',
         'irregular_plural': 'z',
         'base_noun': 'q',
         'tags': []
     }]
     expected = {
         'class': 'Paragraph',
         'sentence_list': [{
             'class': 'Sentence',
             'word_list': word_list
         }],
         'tags': [],
     }
     self.assertEqual(Serializer.to_dict(paragraph), expected)
Esempio n. 12
0
 def test_to_obj_with_tags(self):
     tag_list = [tag for tag in StatusTag]
     paragraph = Paragraph([], Tags(tag_list))
     as_dict = Serializer.to_dict(paragraph)
     self.assertEqual(Serializer.to_obj(as_dict), paragraph)
Esempio n. 13
0
 def test_to_obj_with_empty_sentence(self):
     paragraph = Paragraph([Sentence()])
     as_dict = Serializer.to_dict(paragraph)
     self.assertEqual(Serializer.to_obj(as_dict), paragraph)
Esempio n. 14
0
 def test_to_obj_with_BeVerb_in_sentence(self):
     paragraph = Paragraph([Sentence([pronoun for pronoun in BeVerb])])
     as_dict = Serializer.to_dict(paragraph)
     self.assertEqual(Serializer.to_obj(as_dict), paragraph)
Esempio n. 15
0
 def test_to_obj_with_tagless_Verb_in_sentence(self):
     paragraph = Paragraph([Sentence([Verb('x'), Verb('y')])])
     as_dict = Serializer.to_dict(paragraph)
     self.assertEqual(Serializer.to_obj(as_dict), paragraph)
Esempio n. 16
0
 def test_empty_paragraph_to_dict(self):
     answer = Serializer.to_dict(Paragraph([]))
     expected = {'class': 'Paragraph', 'sentence_list': [], 'tags': []}
     self.assertEqual(expected, answer)