From f1b5fff3b359520718855472d651e01d90dd238f Mon Sep 17 00:00:00 2001 From: Alexander-D-Karpov Date: Sat, 9 Sep 2023 19:59:39 +0300 Subject: [PATCH] updated doc process --- press_release_nl/processor/api/views.py | 17 ++++++-- press_release_nl/processor/services.py | 53 +++++++++++++++---------- press_release_nl/processor/tasks.py | 31 +++++++++++++++ 3 files changed, 78 insertions(+), 23 deletions(-) diff --git a/press_release_nl/processor/api/views.py b/press_release_nl/processor/api/views.py index bbd99d0..60c5f8d 100644 --- a/press_release_nl/processor/api/views.py +++ b/press_release_nl/processor/api/views.py @@ -52,7 +52,7 @@ class UpdateTextDescriptionApiView(generics.GenericAPIView): def get(self, request, *args, **kwargs): type = self.request.query_params.get("type") text = get_object_or_404(Text, id=self.kwargs["id"]) - run_mth = ["f", "bert"] + run_mth = ["f", "bert", "nearest"] if type in run_mth: run_mth = [type] @@ -71,8 +71,14 @@ def get(self, request, *args, **kwargs): re = requests.post(ML_HOST + "tfidf/describe", json={"data": text.text}) if re.status_code == 200: text.description["f"]["text"] = re.json()["text"] + + if "nearest" not in text.description and "nearest" in run_mth: + e = True + text.description["nearest"] = {} + text.description["nearest"]["text"] = text.score["nearest"]["detailed"] + text.score["nearest"]["detailed"] = "" if e: - text.save(update_fields=["description"]) + text.save(update_fields=["description", "score"]) else: text.description = {} @@ -87,5 +93,10 @@ def get(self, request, *args, **kwargs): re = requests.post(ML_HOST + "tfidf/describe", json={"data": text.text}) if re.status_code == 200: text.description["f"]["text"] = re.json()["text"] - text.save(update_fields=["description"]) + + if "nearest" in run_mth: + text.description["nearest"] = {} + text.description["nearest"]["text"] = text.score["nearest"]["detailed"] + text.score["nearest"]["detailed"] = "" + text.save(update_fields=["description", "score"]) return Response(data=ProcessedTextSerializer().to_representation(instance=text)) diff --git a/press_release_nl/processor/services.py b/press_release_nl/processor/services.py index 3464ad5..da291b1 100644 --- a/press_release_nl/processor/services.py +++ b/press_release_nl/processor/services.py @@ -20,26 +20,39 @@ def create_highlighted_document(pk: int, var: str) -> str: text = Text.objects.get(pk=pk).description[var]["text"] document = Document() p = document.add_paragraph() - for e in [[y.split(">") for y in x.split("<")] for x in text.split("") for y in x.split("<")] for x in text.split("