Ejemplo n.º 1
0
def review_summarization(movie_id):
    try:
        positive_reviews = Reviews.objects(
            Movie_id=movie_id, Sense='positive').order_by('-Polarity')
        negative_reviews = Reviews.objects(
            Movie_id=movie_id, Sense='negative').order_by('Polarity')
        neutral_reviews = Reviews.objects(Movie_id=movie_id, Sense='neutral')
        positive_string = ""
        negative_string = ""
        neutral_string = ""
        for review in positive_reviews:
            positive_string += (review.Body + " ")
        for review in negative_reviews:
            negative_string += (review.Body + " ")
        for review in neutral_reviews:
            neutral_string += (review.Body + " ")

        positive_summ = text_summarization.summarize(text=positive_string)
        negative_summ = text_summarization.summarize(text=negative_string)
        neutral_summ = text_summarization.summarize(text=neutral_string)
        return {
            "positive_key_reviews": positive_summ,
            "negative_key_reviews": negative_summ,
            "neutral_key_reviews": neutral_summ
        }
    except:
        raise InvalidQueryError("Summary cannot be generated")
def reviews(request, template='review/reviews.html', extra_context=None):
    review_positiv = Reviews.objects(
        review_eval='positiv').order_by('+hotel_name')
    review_neutral = Reviews.objects(
        review_eval='neutral').order_by('+hotel_name')
    review_negativ = Reviews.objects(
        review_eval='negativ').order_by('+hotel_name')
    best_hotels = Reviews.objects.aggregate(
        {"$match": {
            "review_eval": "positiv"
        }}, {"$group": {
            "_id": "$hotel_name",
            "sum": {
                "$sum": 1
            }
        }}, {"$sort": {
            "sum": -1
        }}, {"$limit": 10})

    context = {
        # 'reviews':review_list,
        #Future work
        'reviews_positiv': review_positiv,
        'reviews_neutral': review_neutral,
        'reviews_negativ': review_negativ,
        'best_hotels': best_hotels
    }
    if extra_context is not None:
        context.update(extra_context)

    return render(request, 'review/reviews.html', context)
Ejemplo n.º 3
0
def review_summarization(movie_id):
    try:
        positive_reviews = Reviews.objects(Movie_id=movie_id, Sense='positive').order_by('-Polarity')
        negative_reviews = Reviews.objects(Movie_id=movie_id, Sense='negative').order_by('Polarity')
        neutral_reviews = Reviews.objects(Movie_id=movie_id, Sense='neutral')
        positive_string=""
        negative_string=""
        neutral_string=""
        for review in positive_reviews:
            positive_string+=(review.Body+" ")
        for review in negative_reviews:
            negative_string+=(review.Body+" ")
        for review in neutral_reviews:
            neutral_string+=(review.Body+" ")

        positive_summ = text_summarization.summarize(text=positive_string)
        negative_summ = text_summarization.summarize(text=negative_string)
        neutral_summ = text_summarization.summarize(text=neutral_string)
        return {
                "positive_key_reviews":positive_summ,
                "negative_key_reviews":negative_summ,
                "neutral_key_reviews":neutral_summ
        }
    except:
        raise InvalidQueryError("Summary cannot be generated")
Ejemplo n.º 4
0
def update_movie_review(review_id,
                        movie_id=None,
                        body=None,
                        timestamp=None,
                        deleted=None,
                        review_author=None):
    try:
        review = Reviews.objects(id=review_id)
        if movie_id:
            review.update(Movie_id=movie_id)

        if body:
            review.update(Body=body)
            analysis = comments_analysis.sentiment(sentence=body)
            review.update(Polarity=analysis['polarity'])
            review.update(Sense=analysis['sense'])

        if timestamp:
            review.update(Timestamp=timestamp)

        if deleted:
            review.update(Deleted=deleted)

        if review_author:
            review.update(Review_author=review_author)

        return {'Success': True}

    except:
        raise InvalidQueryError("Check for details")
Ejemplo n.º 5
0
def update_movie_review(review_id, movie_id=None, body=None, timestamp=None, deleted=None, review_author=None):
    try:
        review = Reviews.objects(id=review_id)
        if movie_id:
            review.update(Movie_id=movie_id)

        if body:
            review.update(Body=body)
            analysis = comments_analysis.sentiment(sentence=body)
            review.update(Polarity=analysis['polarity'])
            review.update(Sense=analysis['sense'])

        if timestamp:
            review.update(Timestamp=timestamp)

        if deleted:
            review.update(Deleted=deleted)

        if review_author:
            review.update(Review_author=review_author)

        return {'Success':True}

    except:
        raise InvalidQueryError("Check for details")
Ejemplo n.º 6
0
def get_movie_reviews(movie_id,offset=0,limit=10):
    positive_reviews=[]
    negative_reviews=[]
    neutral_reviews=[]
    reviews = Reviews.objects(Movie_id=movie_id)
    #print reviews
    for review in reviews:
        d={}
        d['sentence']=review.Body
        d['polarity']=review.Polarity
        if review.Sense == 'positive':
            positive_reviews.append(d)
        elif review.Sense == 'neutral':
            neutral_reviews.append(d)
        else:
            negative_reviews.append(d)

    positive_reviews = sorted(positive_reviews, key=lambda k: k['polarity'], reverse=True)
    negative_reviews = sorted(negative_reviews, key=lambda k: k['polarity'], reverse=True)
    #rating = calculate_rating(positive_reviews,negative_reviews)
    #print  rating
    return positive_reviews,neutral_reviews,negative_reviews