|
@@ -3,14 +3,33 @@ from django.utils import timezone
|
|
|
from django.shortcuts import redirect
|
|
|
from review.forms import ReplyForm
|
|
|
from review.models import Review, CustomReply
|
|
|
+from gauth.models import Location
|
|
|
+from difflib import SequenceMatcher
|
|
|
|
|
|
from .nlu_utils import model_inference, analyze_inference
|
|
|
|
|
|
|
|
|
+def filter_with_last_ten_reviews(location_id, replies):
|
|
|
+ replies = list(replies)
|
|
|
+ revs = Review.objects.filter(location_id=location_id).exclude(reply=None).order_by('-update_time')[:12]
|
|
|
+ for r in revs:
|
|
|
+ s1 = r.reply.replied_text
|
|
|
+ for rep in replies:
|
|
|
+ s2 = rep.reply
|
|
|
+ similarity = SequenceMatcher(None, s1, s2).ratio()
|
|
|
+ if similarity > 0.7:
|
|
|
+ replies.remove(rep)
|
|
|
+ print(similarity, '--------------', rep.reply_category)
|
|
|
+ # if similarity < 0.7 and rep not in reps:
|
|
|
+ # reps.append(rep)
|
|
|
+ return replies
|
|
|
+
|
|
|
+
|
|
|
def predict_report(request, review_id):
|
|
|
review = Review.objects.filter(review_id=review_id).first()
|
|
|
if review is None:
|
|
|
return redirect('un-replied-review')
|
|
|
+ location_id = review.location.location_id
|
|
|
text = review.comment.lower()
|
|
|
res = model_inference(text=text)
|
|
|
intents = analyze_inference(res)
|
|
@@ -21,7 +40,8 @@ def predict_report(request, review_id):
|
|
|
replies = {}
|
|
|
for intent in intents.keys():
|
|
|
r = CustomReply.objects.filter(reply_category=intent)
|
|
|
- replies[intent] = r
|
|
|
+ filtered_replies = filter_with_last_ten_reviews(location_id, r)
|
|
|
+ replies[intent] = filtered_replies
|
|
|
context = {
|
|
|
'reviews': reviews,
|
|
|
'form': form,
|