From 606fd691b3b1c4e5aea8d5b89e98a9224d7a0889 Mon Sep 17 00:00:00 2001 From: Kartik Paliwal Date: Mon, 29 Jan 2024 12:17:59 +0000 Subject: [PATCH 1/2] refactor TextSearchResource --- ebl/corpus/web/bootstrap.py | 17 +++++----- ebl/corpus/web/texts.py | 50 +++++++++++++++------------- ebl/tests/corpus/test_texts_route.py | 31 +---------------- 3 files changed, 36 insertions(+), 62 deletions(-) diff --git a/ebl/corpus/web/bootstrap.py b/ebl/corpus/web/bootstrap.py index 362461011..031eb79c1 100644 --- a/ebl/corpus/web/bootstrap.py +++ b/ebl/corpus/web/bootstrap.py @@ -17,14 +17,15 @@ from ebl.corpus.web.manuscripts import ManuscriptsResource from ebl.corpus.web.texts import ( TextResource, - TextSearchResource, + # TextSearchResource, TextsResource, TextsAllResource, ) from ebl.corpus.web.unplaced_lines import UnplacedLinesResource -from ebl.transliteration.application.transliteration_query_factory import ( - TransliterationQueryFactory, -) + +# from ebl.transliteration.application.transliteration_query_factory import ( +# TransliterationQueryFactory, +# ) def create_corpus_routes(api: falcon.App, context: Context): @@ -39,9 +40,9 @@ def create_corpus_routes(api: falcon.App, context: Context): texts = TextsResource(corpus) text = TextResource(corpus) - text_search = TextSearchResource( - corpus, TransliterationQueryFactory(context.sign_repository) - ) + # text_search = TextSearchResource( + # corpus, TransliterationQueryFactory(context.sign_repository) + # ) chapters = ChaptersResource(corpus) chapters_display = ChaptersDisplayResource(corpus, context.custom_cache) chapters_line = LineResource(corpus, context.custom_cache) @@ -64,7 +65,7 @@ def create_corpus_routes(api: falcon.App, context: Context): chapter_url = text_url + "/chapters/{stage}/{name}" api.add_route("/texts", texts) - api.add_route("/textsearch", text_search) + # api.add_route("/textsearch", text_search) api.add_route(text_url, text) api.add_route(chapter_url, chapters) diff --git a/ebl/corpus/web/texts.py b/ebl/corpus/web/texts.py index 8f15e8d84..7188cccaa 100644 --- a/ebl/corpus/web/texts.py +++ b/ebl/corpus/web/texts.py @@ -1,15 +1,17 @@ import falcon from ebl.corpus.application.corpus import Corpus -from ebl.corpus.web.chapter_info_schema import ( - ChapterInfosPaginationSchema, -) + +# from ebl.corpus.web.chapter_info_schema import ( +# ChapterInfosPaginationSchema, +# ) from ebl.corpus.web.text_schema import ApiTextSchema from ebl.corpus.web.text_utils import create_text_id -from ebl.errors import DataError -from ebl.transliteration.application.transliteration_query_factory import ( - TransliterationQueryFactory, -) + +# from ebl.errors import DataError +# from ebl.transliteration.application.transliteration_query_factory import ( +# TransliterationQueryFactory, +# ) class TextsResource: @@ -31,23 +33,23 @@ def on_get( resp.media = ApiTextSchema().dump(text) -class TextSearchResource: - def __init__( - self, corpus: Corpus, transliteration_query_factory: TransliterationQueryFactory - ): - self._corpus = corpus - self._transliteration_query_factory = transliteration_query_factory - - def on_get(self, req: falcon.Request, resp: falcon.Response) -> None: - query = self._transliteration_query_factory.create( - req.params["transliteration"] - ) - try: - pagination_index = int(req.params["paginationIndex"]) - except ValueError as error: - raise DataError("Pagination Index has to be a number") from error - chapters = self._corpus.search_transliteration(query, pagination_index) - resp.media = ChapterInfosPaginationSchema().dump(chapters) +# class TextSearchResource: +# def __init__( +# self, corpus: Corpus, transliteration_query_factory: TransliterationQueryFactory +# ): +# self._corpus = corpus +# self._transliteration_query_factory = transliteration_query_factory + +# def on_get(self, req: falcon.Request, resp: falcon.Response) -> None: +# query = self._transliteration_query_factory.create( +# req.params["transliteration"] +# ) +# try: +# pagination_index = int(req.params["paginationIndex"]) +# except ValueError as error: +# raise DataError("Pagination Index has to be a number") from error +# chapters = self._corpus.search_transliteration(query, pagination_index) +# resp.media = ChapterInfosPaginationSchema().dump(chapters) class TextsAllResource: diff --git a/ebl/tests/corpus/test_texts_route.py b/ebl/tests/corpus/test_texts_route.py index 883a93952..f1ce36a04 100644 --- a/ebl/tests/corpus/test_texts_route.py +++ b/ebl/tests/corpus/test_texts_route.py @@ -1,12 +1,7 @@ import falcon from ebl.corpus.application.schemas import TextSchema -from ebl.corpus.domain.chapter_info import ChapterInfo -from ebl.corpus.web.chapter_info_schema import ChapterInfoSchema -from ebl.tests.corpus.support import allow_references, allow_signs -from ebl.tests.factories.corpus import ChapterFactory, TextFactory -from ebl.transliteration.domain.transliteration_query import TransliterationQuery -from ebl.transliteration.application.signs_visitor import SignsVisitor +from ebl.tests.factories.corpus import TextFactory def create_dto(text): @@ -53,27 +48,3 @@ def test_listing_texts(client, bibliography, text_repository): assert get_result.status == falcon.HTTP_OK assert get_result.json == [create_dto(first_text), create_dto(second_text)] - - -def test_searching_texts(client, bibliography, sign_repository, signs, text_repository): - allow_signs(signs, sign_repository) - chapter = ChapterFactory.build() - allow_references(chapter, bibliography) - text_repository.create_chapter(chapter) - - get_result = client.simulate_get("/textsearch?transliteration=ku&paginationIndex=0") - - assert get_result.status == falcon.HTTP_OK - assert get_result.json == { - "chapterInfos": [ - ChapterInfoSchema().dump( - ChapterInfo.of( - chapter, - TransliterationQuery( - string="KU", visitor=SignsVisitor(sign_repository) - ), - ) - ) - ], - "totalCount": 1, - } From 0ee656b94507f05f7e8af411f3d8aebdd55cb19a Mon Sep 17 00:00:00 2001 From: Kartik Paliwal Date: Mon, 29 Jan 2024 12:34:49 +0000 Subject: [PATCH 2/2] Refactor TextSearchResource and delete comments --- ebl/corpus/web/bootstrap.py | 9 --------- ebl/corpus/web/texts.py | 27 --------------------------- 2 files changed, 36 deletions(-) diff --git a/ebl/corpus/web/bootstrap.py b/ebl/corpus/web/bootstrap.py index 031eb79c1..02ebfdffa 100644 --- a/ebl/corpus/web/bootstrap.py +++ b/ebl/corpus/web/bootstrap.py @@ -17,16 +17,11 @@ from ebl.corpus.web.manuscripts import ManuscriptsResource from ebl.corpus.web.texts import ( TextResource, - # TextSearchResource, TextsResource, TextsAllResource, ) from ebl.corpus.web.unplaced_lines import UnplacedLinesResource -# from ebl.transliteration.application.transliteration_query_factory import ( -# TransliterationQueryFactory, -# ) - def create_corpus_routes(api: falcon.App, context: Context): corpus = Corpus( @@ -40,9 +35,6 @@ def create_corpus_routes(api: falcon.App, context: Context): texts = TextsResource(corpus) text = TextResource(corpus) - # text_search = TextSearchResource( - # corpus, TransliterationQueryFactory(context.sign_repository) - # ) chapters = ChaptersResource(corpus) chapters_display = ChaptersDisplayResource(corpus, context.custom_cache) chapters_line = LineResource(corpus, context.custom_cache) @@ -65,7 +57,6 @@ def create_corpus_routes(api: falcon.App, context: Context): chapter_url = text_url + "/chapters/{stage}/{name}" api.add_route("/texts", texts) - # api.add_route("/textsearch", text_search) api.add_route(text_url, text) api.add_route(chapter_url, chapters) diff --git a/ebl/corpus/web/texts.py b/ebl/corpus/web/texts.py index 7188cccaa..b108f05db 100644 --- a/ebl/corpus/web/texts.py +++ b/ebl/corpus/web/texts.py @@ -2,17 +2,9 @@ from ebl.corpus.application.corpus import Corpus -# from ebl.corpus.web.chapter_info_schema import ( -# ChapterInfosPaginationSchema, -# ) from ebl.corpus.web.text_schema import ApiTextSchema from ebl.corpus.web.text_utils import create_text_id -# from ebl.errors import DataError -# from ebl.transliteration.application.transliteration_query_factory import ( -# TransliterationQueryFactory, -# ) - class TextsResource: def __init__(self, corpus: Corpus): @@ -33,25 +25,6 @@ def on_get( resp.media = ApiTextSchema().dump(text) -# class TextSearchResource: -# def __init__( -# self, corpus: Corpus, transliteration_query_factory: TransliterationQueryFactory -# ): -# self._corpus = corpus -# self._transliteration_query_factory = transliteration_query_factory - -# def on_get(self, req: falcon.Request, resp: falcon.Response) -> None: -# query = self._transliteration_query_factory.create( -# req.params["transliteration"] -# ) -# try: -# pagination_index = int(req.params["paginationIndex"]) -# except ValueError as error: -# raise DataError("Pagination Index has to be a number") from error -# chapters = self._corpus.search_transliteration(query, pagination_index) -# resp.media = ChapterInfosPaginationSchema().dump(chapters) - - class TextsAllResource: def __init__( self,