Пример #1
0
    def test_add_entities_no_dups(self):
        doc = self.doc

        e = Entity()
        e.group = 'group'
        e.name = u'name'

        de = DocumentEntity()
        de.entity = e
        de.relevance = 1.0
        de.count = 2

        doc.add_entity(de)
        self.assertEqual([de], list(doc.entities))

        e2 = Entity()
        e2.group = 'group'
        e2.name = u'name'

        de2 = DocumentEntity()
        de2.entity = e
        de2.relevance = 0.5
        de2.count = 3

        doc.add_entity(de2)
        # shouldn't add dup
        self.assertEqual([de], list(doc.entities))
    def test_guess_genders(self):
        d = Document.query.get(self.fx.DocumentData.simple.id)
        d.text = 'Fred Astair did something. He also did something else.'

        de = DocumentEntity()
        de.document = d
        de.relevance = 1.0
        de.entity = Entity.query.get(self.fx.EntityData.sue_no_gender.id)
        de.offset_list = '27:2'

        self.db.session.add(d)

        self.ex.guess_genders(d)
        self.assertEqual('Male', d.entities[0].entity.person.gender.name)
Пример #3
0
    def test_delete_document(self):
        doc = self.doc
        doc.text = u'And Fred said "Hello" to everyone.'
        doc.published_at = datetime.datetime.utcnow()

        u = Utterance()
        u.entity = Entity()
        u.entity.group = 'person'
        u.entity.name = u'Fred'
        u.quote = u'Hello'
        self.assertTrue(doc.add_utterance(u))

        de = DocumentEntity()
        de.document = doc
        de.relevance = 0.5
        de.entity = Entity.query.first()

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

        self.db.session.delete(doc)
        self.db.session.commit()