|
@@ -16,13 +16,36 @@ from .nlu_utils import (
|
|
|
|
|
|
@login_required
|
|
|
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)
|
|
|
+ review = Review.objects.get(review_id=review_id)
|
|
|
+ location_id = review.location_id
|
|
|
+ replies = {}
|
|
|
+ if review.star_rating == 5:
|
|
|
+ text = review.comment.lower()
|
|
|
+ res = model_inference(text=text)
|
|
|
+ intents = analyze_inference(res)
|
|
|
+ for intent in intents.keys():
|
|
|
+ r = CustomReply.objects.filter(reply_category=intent)
|
|
|
+ filtered_replies = filter_with_last_ten_reviews(location_id, r)
|
|
|
+ replies[intent] = filtered_replies
|
|
|
+
|
|
|
+ elif review.star_rating == 4:
|
|
|
+ intents = {'four_star': 100}
|
|
|
+ cr = CustomReply.objects.filter(reply_star=4)
|
|
|
+ filtered_replies = filter_with_last_ten_reviews(location_id, cr)
|
|
|
+ replies = {'four_star': filtered_replies}
|
|
|
+
|
|
|
+ elif review.star_rating == 3:
|
|
|
+ intents = {'three_star': 100}
|
|
|
+ cr = CustomReply.objects.filter(reply_star=3)
|
|
|
+ filtered_replies = filter_with_last_ten_reviews(location_id, cr)
|
|
|
+ replies = {'three_star': filtered_replies}
|
|
|
+
|
|
|
+ else:
|
|
|
+ intents = {'negative': 100}
|
|
|
+ cr = CustomReply.objects.filter(reply_star__lte=2)
|
|
|
+ filtered_replies = filter_with_last_ten_reviews(location_id, cr)
|
|
|
+ replies = {'negative': filtered_replies}
|
|
|
+
|
|
|
now = timezone.now()
|
|
|
form = ReplyForm()
|
|
|
date = now - timezone.timedelta(days=30)
|
|
@@ -39,40 +62,11 @@ def predict_report(request, review_id):
|
|
|
reviews = paginator.page(1)
|
|
|
except EmptyPage:
|
|
|
reviews = paginator.page(paginator.num_pages)
|
|
|
- if review.star_rating == 5:
|
|
|
- replies = {}
|
|
|
- for intent in intents.keys():
|
|
|
- r = CustomReply.objects.filter(reply_category=intent)
|
|
|
- filtered_replies = filter_with_last_ten_reviews(location_id, r)
|
|
|
- replies[intent] = filtered_replies
|
|
|
|
|
|
- # ================================================================================================================================
|
|
|
- # This is for temporary use, It will be remove in future release.
|
|
|
- # This part of code block is used for show all reviews as intent classifier make mistake sometime.
|
|
|
- replies2 = {}
|
|
|
- rep_cls = {'staff', 'facility', 'kids', 'quick', 'general_review', 'open_24', 'continuous_visit'}.difference(set(intents.keys()))
|
|
|
- for c in rep_cls:
|
|
|
- r = CustomReply.objects.filter(reply_category=c)
|
|
|
- filtered_replies = filter_with_last_ten_reviews(location_id, r)
|
|
|
- replies2[c] = filtered_replies
|
|
|
-
|
|
|
- # End of the temporary code block
|
|
|
- # ================================================================================================================================
|
|
|
- else:
|
|
|
- cr = CustomReply.objects.values('reply_category').distinct()
|
|
|
- cr_li = {c_r['reply_category'] for c_r in cr}
|
|
|
- rep_cls = cr_li.difference({'staff', 'facility', 'kids', 'quick', 'general_review', 'open_24', 'continuous_visit', 'no_comment'})
|
|
|
- replies = {}
|
|
|
- replies2 = None
|
|
|
- for c in rep_cls:
|
|
|
- r = CustomReply.objects.filter(reply_category=c)
|
|
|
- filtered_replies = filter_with_last_ten_reviews(location_id, r)
|
|
|
- replies[c] = filtered_replies
|
|
|
context = {
|
|
|
'reviews': reviews,
|
|
|
'form': form,
|
|
|
'intents': intents,
|
|
|
'replies': replies,
|
|
|
- 'replies2': replies2 # This context is associate with the temporary code that mentioned above.
|
|
|
}
|
|
|
return render(request, 'dashboard.html', context)
|