Пример #1
0
    def test_article_time_bias(self):
        # Identical
        a = fac.article()
        b = fac.article()
        sim = a.similarity(b)

        # Set time difference
        b.created_at = datetime.utcnow() - timedelta(days=10)
        sim_ = a.similarity(b)

        self.assertTrue(sim > sim_)
Пример #2
0
    def test_article_time_bias(self):
        # Identical
        a = fac.article()
        b = fac.article()
        sim = a.similarity(b)

        # Set time difference
        b.created_at = datetime.utcnow() - timedelta(days=10)
        sim_ = a.similarity(b)

        self.assertTrue(sim > sim_)
Пример #3
0
    def test_article_small_time_bias(self):
        # Identical
        a = fac.article()
        b = fac.article()
        sim = a.similarity(b)

        # Set time difference to be small,
        # small enough that it doesn't affect the score.
        b.created_at = datetime.utcnow() - timedelta(days=1)
        sim_ = a.similarity(b)

        self.assertEqual(sim, sim_)
Пример #4
0
    def test_article_small_time_bias(self):
        # Identical
        a = fac.article()
        b = fac.article()
        sim = a.similarity(b)

        # Set time difference to be small,
        # small enough that it doesn't affect the score.
        b.created_at = datetime.utcnow() - timedelta(days=1)
        sim_ = a.similarity(b)

        self.assertEqual(sim, sim_)
Пример #5
0
    def test_conceptize_creates_new_concepts_if_no_existing_concept_is_found(self):
        self.assertEqual(Concept.query.count(), 0)

        article = fac.article()

        self.assertTrue(Concept.query.count() > 0)
        self.assertEqual(Concept.query.count(), len(article.concepts))

        # There should be a mention for each concept on the article.
        self.assertEqual(len(article.concepts), len(article.mentions))
Пример #6
0
    def test_story_clustering_without_matching_entities(self):
        story = fac.story()

        # Create an event with completely different entities
        # from the story.
        article = fac.article(title='The Illiad', text='The Illiad has Argos in it.')
        event = Event([article])

        Story.cluster([event])
        self.assertEqual(len(story.members), 2)
        self.assertEqual(Story.query.count(), 2)
Пример #7
0
    def test_story_clustering_without_matching_entities(self):
        story = fac.story()

        # Create an event with completely different entities
        # from the story.
        article = fac.article(title='The Illiad',
                              text='The Illiad has Argos in it.')
        event = Event([article])

        Story.cluster([event])
        self.assertEqual(len(story.members), 2)
        self.assertEqual(Story.query.count(), 2)
Пример #8
0
    def _create_dated_story(self):
        datetime_A = datetime.utcnow() - timedelta(days=1)
        datetime_B = datetime.utcnow() - timedelta(days=5)

        article_a = fac.article(title='The Illiad', text='The Illiad has Argos in it.')
        event_a = Event([article_a])
        event_a.created_at = datetime_A

        article_b = fac.article(title='The Illiad', text='The Illiad has Argos in it.')
        event_b = Event([article_b])
        event_b.created_at = datetime_B

        article_c = fac.article(title='The Illiad', text='The Illiad has Argos in it.')
        event_c = Event([article_c])
        event_c.created_at = datetime_A

        story = Story([event_a, event_b, event_c])

        self.db.session.add(story)
        self.db.session.commit()

        return story, datetime_A, datetime_B
Пример #9
0
    def test_GET_article(self):
        article = fac.article()
        source = fac.source()
        article.source = source
        save()

        r = self.client.get("/articles/{0}".format(article.id))
        expected = {
            "id": article.id,
            "url": "/articles/{0}".format(article.id),
            "title": article.title,
            "ext_url": article.ext_url,
            "image": article.image,
            "created_at": article.created_at.isoformat(),
            "updated_at": article.updated_at.isoformat(),
            "authors": [],
            "events": [],
            "source": {"url": "/sources/{0}".format(source.id), "name": source.name},
        }
        self.assertEqual(self.json(r), expected)
Пример #10
0
    def test_GET_article(self):
        article = fac.article()
        source = fac.source()
        article.source = source
        save()

        r = self.client.get('/articles/{0}'.format(article.id))
        expected = {
            'id': article.id,
            'url': '/articles/{0}'.format(article.id),
            'title': article.title,
            'ext_url': article.ext_url,
            'image': article.image,
            'created_at': article.created_at.isoformat(),
            'updated_at': article.updated_at.isoformat(),
            'authors': [],
            'events': [],
            'source': {
                'url': '/sources/{0}'.format(source.id),
                'name': source.name
            }
        }
        self.assertEqual(self.json(r), expected)
Пример #11
0
    def test_GET_article(self):
        article = fac.article()
        source = fac.source()
        article.source = source
        save()

        r = self.client.get('/articles/{0}'.format(article.id))
        expected = {
                'id': article.id,
                'url': '/articles/{0}'.format(article.id),
                'title': article.title,
                'ext_url': article.ext_url,
                'image': article.image,
                'created_at': article.created_at.isoformat(),
                'updated_at': article.updated_at.isoformat(),
                'authors': [],
                'events': [],
                'source': {
                    'id': source.id,
                    'url': '/sources/{0}'.format(source.id),
                    'name': source.name
                }
        }
        self.assertEqual(self.json(r), expected)
Пример #12
0
 def test_article_identical_similarity(self):
     # Identical
     a = fac.article()
     b = fac.article()
     sim = a.similarity(b)
     self.assertEqual(sim, 1.0)
Пример #13
0
 def test_article_identical_similarity(self):
     # Identical
     a = fac.article()
     b = fac.article()
     sim = a.similarity(b)
     self.assertEqual(sim, 1.0)