Esempio n. 1
0
    def test_readPersons_ndSpecific_unexpectedRoot_raises(self):
        ingested_supervision_sentence = \
            StateSupervisionSentence.new_with_defaults(
                external_id=_EXTERNAL_ID)
        ingested_sentence_group = StateSentenceGroup.new_with_defaults(
            supervision_sentences=[ingested_supervision_sentence])
        ingested_person = StatePerson.new_with_defaults(
            sentence_groups=[ingested_sentence_group])

        with pytest.raises(EntityMatchingError):
            session = SessionFactory.for_schema_base(StateBase)
            read_persons(session, 'us_nd', [ingested_person])
Esempio n. 2
0
    def test_readPersons_ndSpecific(self):
        schema_person = schema.StatePerson(person_id=1)
        schema_sentence_group = schema.StateSentenceGroup(
            sentence_group_id=1,
            external_id=_EXTERNAL_ID,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value,
            state_code='US_ND')
        schema_sentence_group_2 = schema.StateSentenceGroup(
            sentence_group_id=2,
            external_id=_EXTERNAL_ID_2,
            status=StateSentenceStatus.PRESENT_WITHOUT_INFO.value,
            state_code='US_ND')
        schema_person.sentence_groups = [
            schema_sentence_group, schema_sentence_group_2
        ]
        schema_person_2 = schema.StatePerson(person_id=2)

        session = SessionFactory.for_schema_base(StateBase)
        session.add(schema_person)
        session.add(schema_person_2)
        session.commit()

        ingested_sentence_group = StateSentenceGroup.new_with_defaults(
            state_code='us_nd', external_id=_EXTERNAL_ID)
        ingested_person = StatePerson.new_with_defaults(
            sentence_groups=[ingested_sentence_group])

        expected_people = StateSchemaToEntityConverter().convert_all(
            [schema_person], populate_back_edges=False)

        people = read_persons(session, 'us_nd', [ingested_person])
        self.assertCountEqual(expected_people, people)
 def read_potential_match_db_persons(
         self,
         session: Session,
         ingested_persons: List[schema.StatePerson]
 ) -> List[schema.StatePerson]:
     """Reads and returns all persons from the DB that are needed for
     entity matching in this state, given the |ingested_persons|.
     """
     return state_matching_utils.read_persons(
         session, self.region_code, ingested_persons)
    def test_readPersons_default(self):
        schema_person = schema.StatePerson(person_id=1)
        schema_person_2 = schema.StatePerson(person_id=2)
        session = SessionFactory.for_schema_base(StateBase)
        session.add(schema_person)
        session.add(schema_person_2)
        session.commit()

        expected_people = [schema_person, schema_person_2]
        people = read_persons(session, _STATE_CODE, [])
        self.assert_schema_object_lists_equal(expected_people, people)
Esempio n. 5
0
    def test_readPersons_default(self):
        schema_person = schema.StatePerson(person_id=1)
        schema_person_2 = schema.StatePerson(person_id=2)
        session = SessionFactory.for_schema_base(StateBase)
        session.add(schema_person)
        session.add(schema_person_2)
        session.commit()

        expected_people = StateSchemaToEntityConverter().convert_all(
            [schema_person, schema_person_2])
        people = read_persons(session, _STATE_CODE, [])
        self.assertCountEqual(expected_people, people)
    def test_readPersons_default(self) -> None:
        schema_person = schema.StatePerson(person_id=1, state_code=_STATE_CODE)
        schema_person_2 = schema.StatePerson(person_id=2,
                                             state_code=_STATE_CODE)
        with SessionFactory.using_database(self.database_key,
                                           autocommit=False) as session:
            session.add(schema_person)
            session.add(schema_person_2)
            session.commit()

            expected_people = [schema_person, schema_person_2]
            people = read_persons(session, _STATE_CODE, [])
            self.assert_schema_object_lists_equal(expected_people, people)
Esempio n. 7
0
 def run_match(self, session: Session, region: str,
               ingested_people: List[StatePerson]) \
         -> MatchedEntities:
     """Attempts to match all persons from |ingested_persons| with
     corresponding persons in our database for the given |region|. Returns a
     MatchedEntities object that contains the results of matching.
     """
     logging.info(
         "[Entity matching] Starting reading and converting people "
         "at time [%s].",
         datetime.datetime.now().isoformat())
     db_persons = read_persons(session=session,
                               region=region,
                               ingested_people=ingested_people)
     logging.info("[Entity matching] Completed DB read at time [%s].",
                  datetime.datetime.now().isoformat())
     matched_entities = _run_match(ingested_people, db_persons)
     return matched_entities