Exemple #1
0
 def test_iter_topic(self, _s3_mock):
     weights = classifier.SimpleWeights.load(classifier.s3_key_xreadlines())
     self.assertItemsEqual(
         weights.iter_topics("About 75% of New York City School students qualify "
                             "for free or reduced-price lunch.", 'Healthcare'),
         [('Healthcare', 0)]
     )
Exemple #2
0
 def test_classify(self, _s3_mock):
     weights = classifier.SimpleWeights.load(classifier.s3_key_xreadlines())
     self.assertEqual(
         weights.classify("About 75% of New York City School students qualify "
                          "for free or reduced-price lunch."),
         {'Healthcare': 0,
          'Education': atan_norm(0.6 + 0.9)} # students, school
     )
Exemple #3
0
 def test_iter_topic_phrase_linking(self, _s3_mock):
     weights = classifier.SimpleWeights.load(classifier.s3_key_xreadlines())
     self.assertItemsEqual(
         weights.iter_topics(
             "Home-schooling parents and teachers can include our fun and free "
             "preschool activities and worksheets in their lesson plans",
             'Education'
         ),
         [('Education', 0.9 + 0.9 + 0.9 + 0.9)] # home schooling, teachers, pre school, lesson plans
     )
Exemple #4
0
    def test_load(self, _s3_mock):
        weights = classifier.SimpleWeights.load(classifier.s3_key_xreadlines())
        self.assertEqual(len(weights), 2)

        topic_data = [line.split(',') for line in DATA.splitlines()]
        for (topic, info) in weights.iteritems():
            topic_lines = [
                (phrase, float(weight), bool(int(skip)))
                for (topic1, phrase, weight, skip) in topic_data
                if topic1 == topic
            ]
            topic_info = [topic_info[:3] for topic_info in info]
            self.assertEqual(topic_info, topic_lines)
Exemple #5
0
 def test_chunked_content_no_trailer(self):
     chunks = CHUNKED_DATA[:-1]
     stripped = CHUNKED_DATA[-1].strip()
     with s3_data_patch(chunks + [stripped]):
         self.assertEqual(''.join(classifier.s3_key_xreadlines()), DATA.strip())
Exemple #6
0
 def test_chunked_content(self, _s3_mock):
     self.assertEqual(list(classifier.s3_key_xreadlines()), StringIO(DATA).readlines())
Exemple #7
0
 def test_short_content(self, _s3_mock):
     self.assertEqual(list(classifier.s3_key_xreadlines()), StringIO(SHORT_DATA).readlines())
Exemple #8
0
 def test_no_creds(self, _s3_mock):
     with self.assertRaises(StopIteration):
         next(classifier.s3_key_xreadlines())