Bläddra i källkod

added an endpoint for displacy module

Mohidul Islam 4 år sedan
förälder
incheckning
34f97a3b94
3 ändrade filer med 19 tillägg och 2 borttagningar
  1. 0 1
      src/clean_text.py
  2. 16 1
      src/main.py
  3. 3 0
      test.json

+ 0 - 1
src/clean_text.py

@@ -41,4 +41,3 @@ def text_formatter(text):
     text = re.sub(r'^[dD][rR](\.|\s*)*', 'Dr. ', text)
     text = re.sub(r'\s[dD][rR](\.|\s*)*', ' Dr. ', text)
     return text
-

+ 16 - 1
src/main.py

@@ -1,5 +1,6 @@
 from fastapi import FastAPI, Body
 
+from spacy import displacy
 from .models import get_model
 from .clean_text import text_cleaner, text_formatter
 
@@ -47,4 +48,18 @@ def get_all_names(data: dict = Body(...)):
     response =  {
         'names': names
     }
-    return response
+    return response
+
+
+
+@app.post('/displacy/google')
+def get_html_entity(data: dict = Body(...)):
+
+    reviews = data.get('reviews')
+
+    for rev in reviews:
+        doc = model(text_formatter(rev['comment']))
+        options = {"ents": ["ORG", "PERSON", "GPE", "PRODUCT", "DATE", "TIME", "MONEY"]}
+        html = displacy.render(doc, options=options, style='ent')
+        rev['comment'] = html
+    return reviews

+ 3 - 0
test.json

@@ -0,0 +1,3 @@
+{
+    "text": "I wasnt feeling well I decided to drive to a near by urgent care. I came across Signature Care, first thing I noticed was the cleanliness! The front desk receptionist Briseida was very kind and helped me get checked in. I was seen by Dr. Henderson he was awesome and very caring of his patients. Nurse Sheila was very sweet and very genuine on how I was feeling. My experience was Great!! Thank you!!!"
+}