大家好!我是程序猿老A,感谢您阅读本文,欢迎一键三连哦。
🎀当前专栏: Python毕业设计
精彩专栏推荐👇🏻👇🏻👇🏻
开发环境
- 开发语言:Python
- 数据库:mysql 5.7
- 数据库工具:Navicat12
- 开发软件:pycharm
- 浏览器:谷歌浏览器
源码下载地址:
https://download.csdn.net/download/m0_46388260/87890657
论文目录
【如需全文请按文末获取联系】
一、项目简介
鉴于电影评论的重要性,电影评论的情感数据分析也成为了当下发展非常迅速的一项内容。本次就是利用了flask框架以及深度学习中的word2vac向量模型来进行一款深度学习的电影评论软件开发,通过该软件的开发来更加有效的对众多的影评文本进行情感分析来判断出一部电影评论好与评论不好的比例等内容,从而为电影的评论提供一个综合的汇总评判分析。
二、系统设计
2.1软件功能模块设计
在系统的功能模块的设计上,本次首先是在部分电影的数据筛选上来确认数据的真实性,从而能够更好推动情感值的模型训练,让整个深度学习的效果达到最好。
2.2数据库设计
本次的数据库设计中,数据库的表格设计如下所示:
三、系统项目部分截图
3.1系统的登录模块设计
本次的基于深度学习的电影评论情感分析系统是需要完成用户的登录才能够进入到系统中进行评论分析的,此次设计的分析系统的登录页面如下所示:
3.2系统的首页实现
当完成登录后,系统的首页以搜索界面为主要展示的内容,在首页中能够在文本框内进行想要获取的电影详情的搜索来快速的查询到与电影相关的信息内容。如下所示:
3.3电影简介的实现
当输入相关信息后,会有电影的名称、图片、主演、上映时间以及简介等多种内容在该页面进行呈现,并且能够通过点击“立即播放”实现在线的电影播放功能,如下图所示:
3.4电影评价分析的实现
在电影简介界面中点击“下一页”能够看到当前用户对于该电影的评价信息,有积极、消极、一般等内容,能够通过环形图来进行相应评分占比的展示。当在点击下一页时,会有具体的热门点评的显示,通过“积极”、“消极”、“一般”三个选项来进行评价的划分,有用户对于电影的评分、点赞数、留言时间等内容的显示。如下图所示:
3.5电影评价情感类别的实现
在电影评价的菜单中,管理员能够看到现有的用户对于电影的全部评价信息,系统会根据输入的评价内容来进行情感类别的判断,并且存储如数据库中,如下图所示:
四、部分核心代码
import csv
import os
import sys
import time
from flask import Blueprint, request, jsonify, render_template, session, redirect
workdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, workdir)
from logger import Logger
from exts import db
from .models import *
from ai_detection.word2vec_svm import test2
from ai_detection import serve
PAGE_SIZE = 5
bp = Blueprint('inference', '__name__', url_prefix='')
logger = Logger(logname='inference_views.log', loglevel=5, logger='inference').getlog()
@bp.route('/get_movies',methods=['get'])
def get_movies():
"""
查询所有用户信息
:return:
"""
keyword = request.args.get('name')
page = int(request.args.get("page"))
limit = int(request.args.get("limit"))
response_data = {}
response_data['code'] = 0
response_data['msg'] = ''
data = []
if keyword is None:
user_objs = Movie.query.order_by(Movie.id.desc())
else:
user_objs = Movie.query.filter(Movie.name.like('%{keyword}%'.format(keyword=keyword)))
results = user_objs.paginate(page=page, per_page=limit, error_out=False)
users_page = results.items
if users_page:
for result in users_page:
record = {
"id": result.id,
"name": result.name,
"performer": result.performer,
'create_time': str(result.create_time),
"country": result.country,
"type": result.type,
'desc':result.desc,
'path':result.path
}
data.append(record)
response_data['count'] = len(user_objs.all())
response_data['data'] = data
return response_data
@bp.route('/edit_movie',methods=['post'])
def edit_movie():
response_data = {}
movie_id = request.form.get('id')
result = Movie.query.filter(Movie.id==movie_id).first()
result.name=request.form.get('name')
result.type=request.form.get('type')
result.path = request.form.get('path')
result.performer = request.form.get('performer')
result.country = request.form.get('country')
db.session.commit()
response_data['msg'] = '修改信息成功!'
return jsonify(response_data), 201
@bp.route('/index', methods=['GET'])
def index1():
"""
:return:
"""
# with open(os.path.join(workdir,'inference','info.csv'),'r',encoding='gbk') as f:
# csv_reader = csv.reader(f)
# for l_list in csv_reader:
# name= l_list[0]
# pj = l_list[4].strip()
# performer= l_list[5]
#
# #movie = Movie(name=name,performer=performer,country=country,type=lb,desc=jj,create_time=sy,image=image)
# r = Movie.query.filter(Movie.name==name).first()
# text = Text(name=pj,owner=performer,status='',movie=r.id,star=random.choice([1,2,3,4,5]),count=l_list[7],create_time=l_list[6].strip())
# print(r)
#
# db.session.add(text)
# db.session.commit()
return render_template('index.html')
@bp.route('/', methods=['GET'])
def login():
"""
:return:
"""
return render_template('login.html')
@bp.route('/movies', methods=['get'])
def movies():
return render_template('movies.html')
@bp.route('/user', methods=['get'])
def user():
return render_template('user.html')
@bp.route('texts',methods=['get'])
def texts():
return render_template('text.html')
@bp.route('/get_text', methods=['get', 'post'])
def get_text():
"""
查询所有用户信息
:return:
"""
keyword = request.args.get('name')
page = int(request.args.get("page"))
limit = int(request.args.get("limit"))
print(page)
response_data = {}
response_data['code'] = 0
response_data['msg'] = ''
data = []
if keyword is None:
user_objs = Text.query.order_by(Text.id.desc())
else:
user_objs = Text.query.filter(Text.name.like('%{keyword}%'.format(keyword=keyword)))
results = user_objs.paginate(page=page, per_page=limit, error_out=False)
users_page = results.items
if users_page:
for result in users_page:
record = {
"id": result.id,
"name": result.name,
"count": result.count,
'create_time': str(result.create_time),
"star": result.star,
"status": result.status,
'owner':result.owner
}
data.append(record)
response_data['count'] = len(user_objs.all())
response_data['data'] = data
return response_data
@bp.route('/get_users', methods=['get', 'post'])
def get_users():
"""
查询所有用户信息
:return:
"""
keyword = request.args.get('name')
page = int(request.args.get("page"))
limit = int(request.args.get("limit"))
print(page)
response_data = {}
response_data['code'] = 0
response_data['msg'] = ''
data = []
if keyword is None:
user_objs = User.query.order_by(User.id.desc())
else:
user_objs = User.query.filter(User.name.like('%{keyword}%'.format(keyword=keyword)))
results = user_objs.paginate(page=page, per_page=limit, error_out=False)
users_page = results.items
if users_page:
for user_obj in users_page:
if user_obj.role == '3':
role = '管理员'
else:
role = '普通用户'
record = {
"id": user_obj.id,
"name": user_obj.name,
"password": user_obj.password,
'create_time': str(user_obj.create_time),
"phone": user_obj.phone,
"role": role
}
data.append(record)
response_data['count'] = len(user_objs.all())
response_data['data'] = data
return response_data
@bp.route('/personal', methods=['get', 'post'])
def personal():
"""
个人信息
:return:
"""
username = session.get('username', 'admin')
user_obj = User.query.filter(User.name == username).first()
return render_template('personal.html', user_obj=user_obj)
@bp.route('/search', methods=['get', 'post'])
def search():
"""
首页搜索
:return:
"""
text = request.args.get('text')
# 根据名字模糊查询
movie_obj = Movie.query.filter(Movie.name.like('%{keyword}%'.format(keyword=text))).first()
return render_template('movie.html', movie_obj=movie_obj)
@bp.route('/add_user', methods=['post'])
def add_user():
"""
新增用户
:return:
"""
# 判断用户是否存在
others = User.query.filter_by(name=request.form.get('username')).all()
if len(others) > 0:
return jsonify({"code": 'error!', 'msg': '用户名重复!'})
others = User.query.filter_by(phone=request.form.get('phone')).all()
if len(others) > 0:
return jsonify({"code": 'error!', 'msg': '手机号重复!'})
password = request.form.get('password')
user = User(name=request.form.get('username'), password=password,
phone=request.form.get('phone'),
role=2)
try:
db.session.add(user)
db.session.commit()
return jsonify({"code": 'success!'})
except Exception as e:
logger.error(str(e))
return jsonify({'code': 'error!'})
@bp.route('/login_out', methods=['get'])
def login_out():
"""
注销登录
:return:
"""
# 删除session
if session.get("username"):
del session["username"]
return redirect('/')
@bp.route('/register', methods=['get'])
def register():
"""
注册页面
:return:
"""
return render_template('signup.html')
@bp.route('/check_login', methods=['POST'])
def check_login():
"""
登录验证
:return:
"""
username = request.form.get('username')
password = request.form.get('password')
print(username, password)
user = db.session.query(User).filter(User.name == username).first()
# 判断用户密码是否正确
if user:
if user.password == password:
session['username'] = username
session['role'] = user.role
session['user_id'] = user.id
session.permanent = True
return {"msg": "验证通过", 'role': user.role}
else:
return jsonify({"msg": "密码错误,请重新输入"}), 401
return jsonify({"msg": "帐号不存在,请重新输入"}), 401
@bp.route('edit_user', methods=['post'])
def edit_user():
"""
编辑用户
:return:
"""
print(1111111)
response_data = {}
user_id = request.form.get('id')
username = request.form.get('username')
phone = request.form.get('phone')
others = db.session.query(User).filter(User.id != user_id).all()
if others:
for other in others:
if other.username == username:
response_data['msg'] = '用户名重复,请重新填写!'
return jsonify(response_data), 402
if other.phone == phone:
response_data['msg'] = '手机号重复,请重新填写!'
return jsonify(response_data), 402
user = db.session.query(User).filter(User.id == user_id).first()
user.username = username
user.password = request.form.get('password')
user.phone = phone
db.session.commit()
response_data['msg'] = '修改用户信息成功!'
return jsonify(response_data), 201
else:
response_data['msg'] = '修改用户信息失败!'
return jsonify(response_data), 402
@bp.route('/del_user', methods=['post'])
def del_user():
"""
删除用户
:return:
"""
user_id = request.form.get('id')
result = db.session.query(User).filter(User.id == user_id).first()
if not result:
response_data = {'msg': '删除失败!该用户不存在'}
return jsonify(response_data), 402
db.session.delete(result)
db.session.commit()
response_data = {'msg': '删除成功!'}
return jsonify(response_data), 201
@bp.route('/get_info', methods=['get'])
def get_info():
"""
获取登录用户信息
:return:
"""
username = session.get('username', '0')
return jsonify({'username': username})
@bp.route("/predict", methods=['post'])
def predict():
"""
预测文本
:return:
"""
print(222)
text = request.form.get('text')
movie_id = request.form.get('movie_id')
print(text,movie_id)
# 调word2vac预测
result = test2.svm_predict(text)
t_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
if not result:
result = serve.predict_main(text)
t = Text(owner=session['username'],name=text,status=result,movie=movie_id,star=3,count=1,create_time=str(t_time))
db.session.add(t)
db.session.commit()
return redirect('/next_page1/'+str(movie_id))
@bp.route("/next_page/<movie_id>", methods=['get'])
def next_page(movie_id):
"""
下一页
:param movie_id:
:return:
"""
movie_obj = Movie.query.filter(Movie.id == movie_id).first()
result1 = Text.query.filter(Text.movie == movie_id, Text.status == '积极').all()
result2 = Text.query.filter(Text.movie == movie_id, Text.status == '消极').all()
result3 = Text.query.filter(Text.movie == movie_id, Text.status == '一般').all()
values = [{'name': '积极', 'value': len(result1)}, {'name': '消极', 'value': len(result2)},
{'name': '一般', 'value': len(result3)}]
return render_template('analysis.html', movie_obj=movie_obj, values=values)
@bp.route('/update_password',methods=['post'])
def update_password():
old_pwd = request.form.get('oldPwd')
username = session.get('username')
user_obj = User.query.filter(User.name==username).first()
if user_obj.password == old_pwd:
user_obj.password = request.form.get('newPwd')
db.session.commit()
return jsonify({'msg': '修改成功!', 'error': 0})
else:
return jsonify({'msg':'旧密码不正确,请重新输入','error':403})
@bp.route("/next_page1/<movie_id>", methods=['get'])
def next_page1(movie_id):
movie_obj = Movie.query.filter(Movie.id == movie_id).first()
result1 = Text.query.filter(Text.movie == movie_id, Text.status == '积极').all()
result2 = Text.query.filter(Text.movie == movie_id, Text.status == '消极').all()
result3 = Text.query.filter(Text.movie == movie_id, Text.status == '一般').all()
values = [{'name': '积极', 'value': len(result1)}, {'name': '消极', 'value': len(result2)},
{'name': '一般', 'value': len(result3)}]
return render_template('pj.html', movie_obj=movie_obj, values=values, result1=result1, result2=result2,
result3=result3, length1=len(result1), length2=len(result2), length3=len(result3))
获取源码或论文
如需对应的论文或源码,以及其他定制需求,也可以下方微❤联系。