def test_query_lemmas_multiple(fragment_repository, lemma_repository): lemmatized_fragment = LemmatizedFragmentFactory.build() fragment_repository.create(lemmatized_fragment) fragment_repository.create(ANOTHER_LEMMATIZED_FRAGMENT) assert lemma_repository.query_lemmas("ana", False) == [["ana II"], ["ana I"]]
def test_number_deserialization(): number = MuseumNumber.of("Z.1.b") fragment = FragmentSchema().load({ **FragmentSchema().dump(LemmatizedFragmentFactory.build()), "museumNumber": MuseumNumberSchema().dump(number), }) assert fragment.number == number
def test_query_by_museum_number_references( database, fragment_repository, bibliography_repository ): reference = ReferenceFactory.build(with_document=True) fragment = LemmatizedFragmentFactory.build(references=(reference,)) database[COLLECTION].insert_one(FragmentSchema(exclude=["joins"]).dump(fragment)) bibliography_repository.create(reference.document) assert fragment_repository.query_by_museum_number(fragment.number) == fragment
def test_create(database, fragment_repository): fragment = LemmatizedFragmentFactory.build() fragment_id = fragment_repository.create(fragment) assert fragment_id == str(fragment.number) assert database[COLLECTION].find_one( {"_id": fragment_id}, projection={"_id": False} ) == FragmentSchema(exclude=["joins"]).dump(fragment)
def test_search_fragment(query_word, lemma, is_normalized, client, fragmentarium, dictionary, word): expected_word = {**word, "_id": lemma} lemmatized_fragment = LemmatizedFragmentFactory.build() fragmentarium.create(lemmatized_fragment) dictionary.create(expected_word) result = client.simulate_get("/lemmas", params={ "word": query_word, "isNormalized": is_normalized }) assert result.status == falcon.HTTP_OK assert result.json == [[expected_word]]
def test_update_transliteration_merge_lemmatization( new_transliteration, client, fragmentarium, signs, sign_repository, transliteration_factory, parallel_line_injector, user, ): for sign in signs: sign_repository.create(sign) lemmatized_fragment = LemmatizedFragmentFactory.build() fragmentarium.create(lemmatized_fragment) lines = lemmatized_fragment.text.atf.split("\n") lines[1] = new_transliteration updates = { "transliteration": "\n".join(lines), "notes": lemmatized_fragment.notes } updated_transliteration = transliteration_factory.create( updates["transliteration"], updates["notes"]) updated_fragment = lemmatized_fragment.update_transliteration( updated_transliteration, user) expected_fragment = attr.evolve( updated_fragment, text=attr.evolve( updated_fragment.text, lines=parallel_line_injector.inject(updated_fragment.text.lines), ), ) expected_json = create_response_dto( expected_fragment, user, lemmatized_fragment.number == MuseumNumber("K", "1"), ) post_result = client.simulate_post( f"/fragments/{lemmatized_fragment.number}/transliteration", body=json.dumps(updates), ) assert post_result.status == falcon.HTTP_OK assert post_result.json == expected_json updated_fragment = client.simulate_get( f"/fragments/{lemmatized_fragment.number}").json assert updated_fragment == expected_json
def test_create_fragment_info_dto(): lemmatized_fragment = LemmatizedFragmentFactory.build() line = "1. kur" info = FragmentInfo.of(lemmatized_fragment, ((line, ), )) record_entry = lemmatized_fragment.record.entries[0] is_transliteration = record_entry.type == RecordType.TRANSLITERATION assert ApiFragmentInfoSchema().dump(info) == { "number": str(info.number), "accession": info.accession, "script": info.script, "description": info.description, "matchingLines": [[line]], "editor": record_entry.user if is_transliteration else "", "editionDate": record_entry.date if is_transliteration else "", "references": [], }
def test_update_transliteration(user): lemmatized_fragment = LemmatizedFragmentFactory.build() lines = lemmatized_fragment.text.atf.split("\n") lines[1] = "2'. [...] GI₆ mu u₄-š[u ...]" atf = Atf("\n".join(lines)) text = parse_atf_lark(atf) transliteration = TransliterationUpdate(text, "updated notes", "X X\nX") updated_fragment = lemmatized_fragment.update_transliteration( transliteration, user) expected_fragment = attr.evolve( lemmatized_fragment, text=lemmatized_fragment.text.merge(text), notes=transliteration.notes, signs=transliteration.signs, record=lemmatized_fragment.record.add_entry( lemmatized_fragment.text.atf, transliteration.text.atf, user), ) assert updated_fragment == expected_fragment
def test_query_by_museum_number_joins(database, fragment_repository): museum_number = MuseumNumber("X", "1") first_join = Join(museum_number, is_in_fragmentarium=True) second_join = Join(MuseumNumber("X", "2"), is_in_fragmentarium=False) fragment = LemmatizedFragmentFactory.build( number=museum_number, joins=Joins(((first_join,), (second_join,))) ) database[COLLECTION].insert_one(FragmentSchema(exclude=["joins"]).dump(fragment)) database[JOINS_COLLECTION].insert_one( { "fragments": [ { **JoinSchema(exclude=["is_in_fragmentarium"]).dump(first_join), "group": 0, }, { **JoinSchema(exclude=["is_in_fragmentarium"]).dump(second_join), "group": 1, }, ] } ) assert fragment_repository.query_by_museum_number(fragment.number) == fragment
def test_query_by_museum_number(database, fragment_repository): fragment = LemmatizedFragmentFactory.build() database[COLLECTION].insert_one(FragmentSchema(exclude=["joins"]).dump(fragment)) assert fragment_repository.query_by_museum_number(fragment.number) == fragment
def test_query_lemmas_not_found(is_normalized, fragment_repository, lemma_repository): lemmatized_fragment = LemmatizedFragmentFactory.build() fragment_repository.create(lemmatized_fragment) assert lemma_repository.query_lemmas("aklu", is_normalized) == []
def test_serialization_and_deserialization(): fragment = LemmatizedFragmentFactory.build( joins=Joins(((Join(MuseumNumber("X", "1")), ), ))) schema = FragmentSchema() data = schema.dump(fragment) assert schema.load(data) == fragment
def test_number_serialization(): fragment = LemmatizedFragmentFactory.build() data = FragmentSchema().dump(fragment) assert data["museumNumber"] == MuseumNumberSchema().dump(fragment.number)
def test_default_joins(): fragment = LemmatizedFragmentFactory.build(joins=Joins()) data = FragmentSchema(exclude=["joins"]).dump(fragment) assert FragmentSchema().load(data) == fragment
def test_create_response_dto(user): lemmatized_fragment = LemmatizedFragmentFactory.build( joins=Joins(((JoinFactory.build(), ), ))) has_photo = True assert create_response_dto( lemmatized_fragment, user, has_photo) == pydash.omit_by( { "museumNumber": attr.asdict(lemmatized_fragment.number), "accession": lemmatized_fragment.accession, "cdliNumber": lemmatized_fragment.cdli_number, "bmIdNumber": lemmatized_fragment.bm_id_number, "publication": lemmatized_fragment.publication, "description": lemmatized_fragment.description, "joins": JoinsSchema().dump(lemmatized_fragment.joins)["fragments"], "length": attr.asdict(lemmatized_fragment.length, filter=lambda _, value: value is not None), "width": attr.asdict(lemmatized_fragment.width, filter=lambda _, value: value is not None), "thickness": attr.asdict(lemmatized_fragment.thickness, filter=lambda _, value: value is not None), "collection": lemmatized_fragment.collection, "script": lemmatized_fragment.script, "notes": lemmatized_fragment.notes, "museum": lemmatized_fragment.museum, "signs": lemmatized_fragment.signs, "record": [{ "user": entry.user, "type": entry.type.value, "date": entry.date } for entry in lemmatized_fragment.record.entries], "folios": [ attr.asdict(folio) for folio in lemmatized_fragment.folios.filter(user).entries ], "text": TextSchema().dump(lemmatized_fragment.text), "references": [{ "id": reference.id, "type": reference.type.name, "pages": reference.pages, "notes": reference.notes, "linesCited": list(reference.lines_cited), } for reference in lemmatized_fragment.references], "uncuratedReferences": ([ attr.asdict(reference) for reference in lemmatized_fragment.uncurated_references ] if lemmatized_fragment.uncurated_references is not None else None), "atf": lemmatized_fragment.text.atf, "hasPhoto": has_photo, "genres": [{ "category": genre.category, "uncertain": genre.uncertain } for genre in lemmatized_fragment.genres], "lineToVec": [[ line_to_vec_encoding.value for line_to_vec_encoding in line_to_vec_encodings ] for line_to_vec_encodings in lemmatized_fragment.line_to_vec ], }, pydash.is_none, )
def test_query_lemmas(fragment_repository, lemma_repository): lemmatized_fragment = LemmatizedFragmentFactory.build() fragment_repository.create(lemmatized_fragment) fragment_repository.create(ANOTHER_LEMMATIZED_FRAGMENT) assert lemma_repository.query_lemmas("GI₆", False) == [["ginâ I"]]
def test_query_lemmas_normalized(fragment_repository, lemma_repository): lemmatized_fragment = LemmatizedFragmentFactory.build() fragment_repository.create(lemmatized_fragment) fragment_repository.create(ANOTHER_LEMMATIZED_FRAGMENT) assert lemma_repository.query_lemmas("ana", True) == [["normalized I"]]