|
@@ -0,0 +1,38 @@
|
|
|
+import json
|
|
|
+import requests
|
|
|
+import csv
|
|
|
+from difflib import SequenceMatcher
|
|
|
+from django.utils import timezone
|
|
|
+
|
|
|
+from .models import Review, CustomReply
|
|
|
+
|
|
|
+
|
|
|
+# constants
|
|
|
+nlu_server_url = 'http://localhost:5005'
|
|
|
+replies = CustomReply.objects.all()
|
|
|
+
|
|
|
+
|
|
|
+def model_inference(text):
|
|
|
+ url = nlu_server_url + '/model/parse'
|
|
|
+ payload = {'text': text}
|
|
|
+ headers = {'content-type': 'application/json'}
|
|
|
+ response = requests.post(url, data=json.dumps(payload), headers=headers)
|
|
|
+ if response.status_code == 200:
|
|
|
+ res = response.json()
|
|
|
+ intents_rankings = res.get('intent_ranking')
|
|
|
+ intents = []
|
|
|
+ for intent in intents_rankings:
|
|
|
+ if intent.get('confidence') > 0.2:
|
|
|
+ intents.append(intent['name'])
|
|
|
+
|
|
|
+ return intents
|
|
|
+
|
|
|
+
|
|
|
+def get_review_actual_intent(review):
|
|
|
+ actual_reply = review.reply.replied_text
|
|
|
+ for c_r in replies:
|
|
|
+ replied_text = c_r.reply
|
|
|
+ similarity = SequenceMatcher(None, actual_reply, replied_text).ratio()
|
|
|
+ if similarity > 0.7:
|
|
|
+ return c_r.reply_category
|
|
|
+ return None
|