def reviews_analysis(url): """ This module will obtain the dataframe containing the reviews: 1. Calculate the sentiments using the reviews 2. Calculate the count of positive and negative reviews 3. Calculate the average rating Returns total_ratings, avg_rating, negative_reviews """ import numpy as np product_name, dataframe = get_reviews(url) # Just get the title as reviews reviews = dataframe["title"] dataframe["rating"] = dataframe["rating"].astype('float') ratings = dataframe["rating"] avg_rating = np.mean(ratings) sentiments = get_sentiment(reviews) # sentiments = pd.Series([1 if sentiment == "POS" else 0 for sentiment in sentiments]) print(sentiments) print(ratings) dataframe["rating"] = dataframe["rating"].astype('int') # negative_reviews = dataframe[dataframe["rating"] < 3] negative_reviews = dataframe[sentiments == "NEG"] # print(negative_reviews) return product_name, ratings, avg_rating, negative_reviews, sentiments
def movie_page(id): if request.method == "GET": if not movies.get_movie_info(id): return render_template( "issue.html", message="Valitettavasti elokuvaa ei löytynyt.") info = movies.get_movie_info(id) review_list = reviews.get_reviews(id) amount_of_reviews = reviews.get_amount(id) average = reviews.get_average(id) return render_template("movie_page.html", information=info, reviews=review_list, amount_of_reviews=amount_of_reviews, average=average, id=id) if request.method == "POST": users.check_csrf() movie_id = request.form["movie_id"] grade = int(request.form["grade"]) review = request.form["review"] if grade == 0 or grade == 1 or grade == 2 or grade == 3 or grade == 4 or grade == 5 or grade == 6 or grade == 7 or grade == 8 or grade == 9 or grade == 10: if not reviews.create_review(movie_id, grade, review): return render_template( "review_issue.html", message="Arvostelun lisäys ei onnistunut", id=id) else: return redirect("/movie_page/" + str(movie_id)) return render_template( "review_issue.html", message="Arvostelussa pitää olla ainakin arvosana.", id=id)
def reviewsit(id): book = books.get_book(id) name = book[0] reviewsit = reviews.get_reviews(id) count = reviews.get_count(id) if count == None: count = 0 else: count = count[0] return render_template("reviews.html", reviews=reviewsit, id=id, count=count, name=name)
def get(self): housing_id = self.request.get("id") housing_query = housing.housing_option_list() current_housing = HousingOption( name = "placeholder", ) for option in housing_query: if housing.get_id(option) == int(housing_id): current_housing = option housing_reviews = reviews.get_reviews(housing_id) template_vars = { "current_housing" : current_housing, "housing_id" : housing_id, "reviews" : housing_reviews } template = jinja_env.get_template("templates/housing.html") self.response.write(template.render(template_vars))
import search import training_module import reviews import sys info = input("\nEnter info : ") review_tab = search.get_first_from_search(info) if (review_tab == ""): print( "\nError\nPossible errors : Incorrect input/Connectivity problem/Product irrelevant\n" ) sys.exit(0) review_list = reviews.get_reviews(review_tab) training_module.sentiment_analysis(review_list)
def get_reviews(id): list = reviews.get_reviews(id) return render_template("reviews2.html", id=id, review=list)
def books_reviews(id): list = reviews.get_reviews(id) return render_template("reviews.html", review=list)
def run(self): self.reviews = get_reviews(self.index) for review in self.reviews: emoji = get_emoji(review.text) self._emojis_counter[emoji] += 1