|
@@ -1,10 +1,27 @@
|
|
import re
|
|
import re
|
|
|
|
+from decimal import Decimal
|
|
from django.conf import settings
|
|
from django.conf import settings
|
|
from .models import Staff
|
|
from .models import Staff
|
|
|
|
+from nlu_job.nlu_utils import model_inference
|
|
|
|
|
|
nlp = settings.MODEL
|
|
nlp = settings.MODEL
|
|
-STOP_WORDS = ['signature', 'care', 'emergency', 'er', 'center', 'nurse', 'dr', 'dr.', 'signaturecare', 'tech',
|
|
|
|
- 'doc', 'urgent', 'the', 'nures', 'nurses', 'registration']
|
|
|
|
|
|
+
|
|
|
|
+nlu_url = settings.NLU_SERVER_URI
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def get_all_names(text):
|
|
|
|
+ res = model_inference(text)
|
|
|
|
+ entities = res.get('entities')
|
|
|
|
+ names = {ent.get('value') for ent in entities if ent.get('entity') in ['PERSON', 'ORG']}
|
|
|
|
+ return names
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def all_staffs(location):
|
|
|
|
+ names = []
|
|
|
|
+ staffs = Staff.objects.filter(location=location)
|
|
|
|
+ for s in staffs:
|
|
|
|
+ names.extend(s.get_nick_names)
|
|
|
|
+ return set(names)
|
|
|
|
|
|
|
|
|
|
def clean_text(text):
|
|
def clean_text(text):
|
|
@@ -17,25 +34,40 @@ def clean_text(text):
|
|
return text
|
|
return text
|
|
|
|
|
|
|
|
|
|
-def cleaning_name(names):
|
|
|
|
|
|
+def extract_names(review):
|
|
|
|
+ text = clean_text(review.comment)
|
|
|
|
+ # doc = nlp(text)
|
|
|
|
+ # names = {ent.text for ent in doc.ents if ent.label_ in ['PERSON', 'ORG']}
|
|
|
|
+
|
|
|
|
+ names = get_all_names(text)
|
|
cleaned_names = []
|
|
cleaned_names = []
|
|
for name in names:
|
|
for name in names:
|
|
for n in name.split():
|
|
for n in name.split():
|
|
- cleaned_names.append(n) if len(n) > 2 and n.lower() not in STOP_WORDS else None
|
|
|
|
|
|
+ cleaned_names.append(n) if n.lower() in all_staffs(review.location) else None
|
|
return cleaned_names
|
|
return cleaned_names
|
|
|
|
|
|
|
|
|
|
-def extract_names(text):
|
|
|
|
- text = clean_text(text)
|
|
|
|
- doc = nlp(text)
|
|
|
|
- names = {ent.text for ent in doc.ents if ent.label_ in ['PERSON', 'ORG']}
|
|
|
|
- names = list(names)
|
|
|
|
- cleaned_names = cleaning_name(names)
|
|
|
|
- return cleaned_names
|
|
|
|
|
|
+def add_point_to_staff_profile(review):
|
|
|
|
+ staffs = Staff.objects.filter(location=review.location)
|
|
|
|
+ names = extract_names(review)
|
|
|
|
+ point_unit = Decimal(1/len(names)) if not names == [] else 0
|
|
|
|
|
|
|
|
+ for name in names:
|
|
|
|
+ for staff in staffs:
|
|
|
|
+ if name.lower() in staff.get_nick_names:
|
|
|
|
+ staff.name_mentioned += 1
|
|
|
|
+ staff.total_units += point_unit
|
|
|
|
+ staff.save()
|
|
|
|
|
|
-def add_point_to_staff_profile(review):
|
|
|
|
|
|
+
|
|
|
|
+def make_all_staffs_point_zero():
|
|
staffs = Staff.objects.all()
|
|
staffs = Staff.objects.all()
|
|
- names = extract_names(review.comment)
|
|
|
|
- point_unit = 1/len(names)
|
|
|
|
- # TODO: store points to the staff profile
|
|
|
|
|
|
+ for s in staffs:
|
|
|
|
+ s.total_units = 0
|
|
|
|
+ s.name_mentioned = 0
|
|
|
|
+ s.save()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def extract_names_from_reviews(reviews):
|
|
|
|
+ for review in reviews:
|
|
|
|
+ add_point_to_staff_profile(review)
|