def _create_tag_instance(
        self,
        tag: Tag,
        summary_guid: str,
        start_char: int,
        stop_char: int,
        session: Session,
    ):
        """Second: step of handle updates: creates a tag instance, and
        associates it with citation and tag"""
        # resolve citation
        log.debug("Creating a TagInstance")
        summary_id = self.get_summary_id(summary_guid=summary_guid,
                                         session=session)

        # create Tag Instance
        tag_instance = TagInstance(summary_id=summary_id,
                                   tag=tag,
                                   start_char=start_char,
                                   stop_char=stop_char)

        session.add_all([tag, tag_instance])
        session.commit()
        print("just committed the session: ", tag)
        log.debug("☀️ ☀️ ☀️ Created tag instance and tag. " +
                  f"TagInstance id is {tag_instance.id}, " +
                  f"TagInstance Summary ID is {tag_instance.summary_id}, " +
                  f"TagInstance Tag ID is {tag_instance.tag_id}")
Example #2
0
def test_tag_inheritance(engine, summary_data_1, summary_data_2):
    time = Time(guid=str(uuid4()), name="November 1963")
    person = Person(guid=str(uuid4()),
                    names="Bach,Johann Sebastian Bach,J.S.Bach")
    place = Place(guid=str(uuid4()), names="Milan,Milano")
    guid1, text1 = summary_data_1
    sum_1 = Summary(guid=guid1, text=text1)
    guid2, text2 = summary_data_2
    sum_2 = Summary(guid=guid2, text=text2)
    tags = [
        TagInstance(start_char=1, stop_char=5, summary=c, tag=t)
        for t in [time, person, place] for c in [sum_1, sum_2]
    ]

    data = [time, person, place, sum_1, sum_2, *tags]
    with Session(engine, future=True) as sess, sess.begin():
        sess.add_all(data)
def db_tuple(_db):
    """
    This fixture manually creates DB_COUNT citations, and DB_COUNT // 2
    of people, places, and times (each). It then associates each citation
    with a person, place, and time, going through the list twice, so that
    each person, place, time is tagged by two different citations.

    NOTE: Because all the db additions are done manually (in order to isolate
    the tests from errors originating in the MUTATION section of the db) the
    addition of names to the Name table is a bit wonky. It's assumed that
    each entity name appears with exactly the same spelling in both citations
    in which it appears.
    """
    summaries = list()
    citations = list()
    people = list()
    places = list()
    times = list()
    cit_guids = list()
    sum_guids = list()
    person_guids = list()
    place_guids = list()
    time_guids = list()
    names = list()
    for _ in range(DB_COUNT // 2):
        person_guid = str(uuid4())
        person_guids.append(person_guid)
        person_name = f"A Person Name {_}"
        people.append(Person(guid=person_guid, names=person_name))
        place_guid = str(uuid4())
        place_guids.append(place_guid)
        place_name = f"A Place Name {_}"
        places.append(
            Place(
                guid=place_guid,
                names=place_name,
                latitude=random.random(),
                longitude=random.random(),
                geoshape="A geoshape string {_}"
                if random.random() > 0.7 else None,
            ))
        time_guid = str(uuid4())
        time_guids.append(time_guid)
        time_name = f"2{_}5{random.randint(0, 9)}|{random.randint(1, 4)}"
        times.append(Time(guid=time_guid, name=time_name))
        # add names to list
        names.extend([person_name, place_name, time_name])
    entities = [(person, place, time)
                for person, place, time in zip(people, places, times)]
    for n in range(DB_COUNT):
        # create a citation
        cit_guid = f"fake-citation-guid-{n}"
        cit_guids.append(cit_guid)
        citation = Citation(
            guid=cit_guid,
            text=f"some citation text {n}",
            meta=json.dumps({"some": "meta data"}),
        )
        citations.append(citation)
        # create a summary
        sum_guid = f"fake-summary-guid-{n}"
        sum_guids.append(sum_guid)
        person, place, time = entities[n % len(entities)]
        summaries.append(
            Summary(
                guid=sum_guid,
                text=f"test text {n}",
                time_tag=time.name,
                tags=[
                    TagInstance(
                        start_char=random.randint(0, 100),
                        stop_char=random.randint(100, 200),
                        tag=entity,
                    ) for entity in (person, place, time)
                ],
                citations=[citation],
            ))

    with Session(_db._engine, future=True) as session:
        session.add_all([*summaries, *citations, *people, *places, *times])
        # manually update names
        for person in people:
            _db._handle_name(person.names, person.guid, session)
        for place in places:
            _db._handle_name(place.names, place.guid, session)
        for time in times:
            _db._handle_name(time.name, time.guid, session)
        session.commit()
    db_dict = {
        "summary_guids": sum_guids,
        "citation_guids": cit_guids,
        "person_guids": person_guids,
        "place_guids": place_guids,
        "time_guids": time_guids,
        "names": names,
    }
    return _db, db_dict
Example #4
0
def tag4():
    return TagInstance(start_char=27, stop_char=32)
Example #5
0
def tag3():
    return TagInstance(start_char=9, stop_char=15)
Example #6
0
def tag2():
    return TagInstance(start_char=8, stop_char=12)
Example #7
0
def tag1():
    return TagInstance(start_char=5, stop_char=10)