Exemple #1
0
    def test_related_concepts(self):
        related_concepts = fac.concept(num=2)
        c = Concept('Argos')

        concept_associations = [ConceptConceptAssociation(concept, 1.0) for concept in related_concepts]
        c.concept_associations = concept_associations

        for concept in c.concepts:
            self.assertTrue(c in concept.from_concepts)
            self.assertTrue(concept in c.concepts)
Exemple #2
0
    def test_conceptize_doesnt_set_new_alias_for_existing_concept_with_same_name(self):
        concept = fac.concept()
        uri = concept.uri

        concepts_count = Concept.query.count()
        self.assertEqual(len(concept.aliases), 1)

        # Mock things so we extract one concept with the same URI
        # as the one we just created.
        self.create_patch('argos.core.knowledge.uri_for_name', return_value=uri)
        self.create_patch('galaxy.concepts', return_value=[concept.aliases[0].name])

        # Create the article, which calls conceptize.
        article = Article(title='A title', text='Some text', score=100)

        self.assertEqual(Concept.query.count(), concepts_count)
        self.assertEqual(len(concept.aliases), 1)

        # There should be a mention for each concept on the article.
        self.assertEqual(len(article.concepts), len(article.mentions))
Exemple #3
0
    def test_conceptize_adds_new_mention_for_existing_concept_when_mentioned_name_is_different(self):
        concept = fac.concept()
        uri = concept.uri

        # Mock things so two concepts are returned, but since they share the same uri, they point to the same concept.
        self.create_patch('argos.core.knowledge.uri_for_name', return_value=uri)
        self.create_patch('galaxy.concepts', return_value=['Concept alias one', 'Concept alias two'])

        # Create the article, which calls conceptize.
        article = Article(title='A title', text='Some text', score=100)

        # There should still only be one concept on the article.
        self.assertEqual(len(article.concepts), 1)

        # But there should be two mentions.
        self.assertEqual(len(article.mentions), 2)

        # There should only be one concept.
        self.assertEqual(Concept.query.count(), 1)
        # But three aliases (the original one the
        # concept had, plus the two new ones here).
        self.assertEqual(len(concept.aliases), 3)