浏览代码

change the model uri and exported updated database

Mohidul Islam 5 年之前
父节点
当前提交
9d900e3c49

+ 3 - 1
name_extractor/admin.py

@@ -1,3 +1,5 @@
 from django.contrib import admin
+from .models import Staff
 
-# Register your models here.
+
+admin.site.register(Staff)

+ 26 - 0
name_extractor/migrations/0001_initial.py

@@ -0,0 +1,26 @@
+# Generated by Django 3.0 on 2020-02-09 12:34
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+        ('gauth', '0008_location_total_review_db'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Staff',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(max_length=255)),
+                ('total_units', models.FloatField()),
+                ('nick_names', models.TextField()),
+                ('location', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='gauth.Location')),
+            ],
+        ),
+    ]

+ 16 - 1
name_extractor/models.py

@@ -1,3 +1,18 @@
 from django.db import models
 
-# Create your models here.
+from gauth.models import Location
+
+
+class Staff(models.Model):
+    name = models.CharField(max_length=255)
+    total_units = models.FloatField()
+    location = models.ForeignKey(Location, on_delete=models.CASCADE)
+    nick_names = models.TextField()
+
+    def __str__(self):
+        return f'{self.name} - {self.location}'
+
+    @property
+    def get_nick_names(self):
+        return self.nick_names.split(',')
+

+ 23 - 3
name_extractor/utils.py

@@ -1,21 +1,41 @@
 import re
 from django.conf import settings
-
+from .models import Staff
 
 nlp = settings.MODEL
+STOP_WORDS = ['signature', 'care', 'emergency', 'er', 'center', 'nurse', 'dr', 'dr.', 'signaturecare', 'tech',
+              'doc', 'urgent', 'the', 'nures', 'nurses', 'registration']
 
 
 def clean_text(text):
     # replace some letter in text for getting better performance
     text = re.sub(r':\s*', ' ', text)
-    text = re.sub(r'&', ',', text)
+    text = re.sub(r'&', ', ', text)
+    text = re.sub(r'/', ', ', text)
     text = re.sub(r'\.*\n\.*', '.', text)
     text = re.sub(r'[dD][rR](\.|\s*)*', 'Dr. ', text)
     return text
 
 
+def cleaning_name(names):
+    cleaned_names = []
+    for name in names:
+        for n in name.split():
+            cleaned_names.append(n) if len(n) > 2 and n.lower() not in STOP_WORDS else None
+    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']}
-    return list(names)
+    names = list(names)
+    cleaned_names = cleaning_name(names)
+    return cleaned_names
+
+
+def add_point_to_staff_profile(review):
+    staffs = Staff.objects.all()
+    names = extract_names(review.comment)
+    point_unit = 1/len(names)
+    # TODO: store points to the staff profile

+ 9 - 4
nlu_job/nlu_utils.py

@@ -37,11 +37,16 @@ def model_inference(text):
 def is_a_name(name):
     '''
     function that decide whether it is a person name or not
-    :param : name -> a string usually reviewer name
-    :return: Boolean ->  true or false
+    :param -> a string usually reviewer name:
+    :return -> a boolean True/False:
     '''
-    doc = ner_model(name)
-    if doc.ents and doc.ents[0].label_ == 'PERSON':
+
+    response = model_inference(name.title())
+    entities = response.get('entities')
+    if not entities:
+        return False
+    entity = entities[0]
+    if entity.get('entity') == 'PERSON':
         return True
     else:
         return False

文件差异内容过多而无法显示
+ 971 - 4
review_automation.sql


+ 4 - 5
review_automation/settings.py

@@ -81,7 +81,6 @@ DATABASES = {
 }
 
 
-
 # Password validation
 
 AUTH_PASSWORD_VALIDATORS = [
@@ -128,15 +127,15 @@ CLIENT_ID = "174657415928-0bt50gt42pslq47gf21ao67n15rom96r.apps.googleuserconten
 CLIENT_SECRET = "ZXYpt07Su0pW3y3jPGOXY_C_"
 TOKEN_URI = "https://oauth2.googleapis.com/token"
 HOST_URI = "http://127.0.0.1:8000"
-NLU_SERVER_URI = 'http://localhost:5005'
+NLU_SERVER_URI = 'http://10.0.0.33:5005'
 
 
 # Cron-Jobs of the project
 CRONJOBS = [
-    ('0 * * * *', 'review.background_job.background_task'),
+    ('0 6 * * *', 'review.background_job.background_task'),
 ]
 
 # spaCy model
 
-MODEL = spacy.load('en_core_web_md')
-# MODEL = 'NLP NER MODEL'
+# MODEL = spacy.load('en_core_web_md')
+MODEL = 'NLP NER MODEL'

部分文件因为文件数量过多而无法显示