基于深度学习的酒店评论文本情感分析研究-hadoop+django+spider
- 开发语言:Python
- 框架:django
- Python版本:python3.8
- 数据库:mysql 5.7
- 数据库工具:Navicat12
- 开发软件:PyCharm
系统展示
系统首页

酒店信息

个人中心

管理员功能界面

用户管理

酒店信息管理

情感分析

酒店信息预测

留言反馈

看板展示

摘要
随着互联网的快速发展,酒店评论成为消费者决策的重要参考,也为酒店管理者提供了宝贵的反馈渠道。海量的评论数据中蕴含着复杂的情感信息,传统的文本分析方法难以高效处理。本研究开发了一套基于深度学习的酒店评论文本情感分析系统,旨在通过先进的技术手段实现对酒店评论情感倾向的精准分析和预测。系统采用 Python 语言开发,结合 Django 框架构建高效稳定的后端服务,并利用 MySQL 数据库进行数据存储与管理。引入 Scrapy 爬虫技术用于采集评论数据,借助 Hadoop 大数据平台实现数据的高效处理与存储。系统功能丰富,包括主页展示、用户管理、酒店信息查询、情感分析、酒店信息预测、留言反馈、系统管理和个人中心等模块。情感分析模块通过深度学习算法对评论文本进行情感分类,能够准确识别正面、负面和中性情感。酒店信息预测模块则基于历史评论数据和情感分析结果,预测酒店的未来发展趋势。留言反馈功能为用户提供了一个表达意见和建议的平台,系统管理模块则保障了数据的安全性和系统的稳定性。
研究背景
在当今数字化时代,互联网的普及和电子商务的迅猛发展极大地改变了人们的生活方式和消费习惯。酒店行业作为旅游产业链中的重要环节,其竞争日益激烈。随着在线旅游平台的兴起,消费者在预订酒店时不再仅仅依赖传统的广告宣传或旅行社推荐,而是越来越多地参考其他用户的在线评论。这些评论不仅涵盖了酒店的设施、服务、环境等多方面信息,还反映了消费者的真实感受和体验。海量的评论数据中蕴含着复杂的情感倾向,对于酒店管理者来说,如何从中快速、准确地提取有价值的信息,以便优化服务和提升竞争力,成为了一个亟待解决的问题。传统的文本分析方法在处理大规模、复杂的评论数据时存在效率低下、主观性强等局限性,而深度学习技术的出现为解决这一问题提供了新的思路和方法。深度学习能够自动提取文本中的特征,并通过对大量标注数据的学习,实现对情感倾向的精准分类和分析。研究基于深度学习的酒店评论文本情感分析系统,具有重要的现实意义和广阔的应用前景。
关键技术
Python是解释型的脚本语言,在运行过程中,把程序转换为字节码和机器语言,说明性语言的程序在运行之前不必进行编译,而是一个专用的解释器,当被执行时,它都会被翻译,与之对应的还有编译性语言。
同时,这也是一种用于电脑编程的跨平台语言,这是一门将编译、交互和面向对象相结合的脚本语言(script language)。
Django用Python编写,属于开源Web应用程序框架。采用(模型M、视图V和模板t)的框架模式。该框架以比利时吉普赛爵士吉他手詹戈·莱因哈特命名。该架构的主要组件如下:
1.用于创建模型的对象关系映射。
2.最终目标是为用户设计一个完美的管理界面。
3.是目前最流行的URL设计解决方案。
4.模板语言对设计师来说是最友好的。
5.缓存系统。
Vue是一款流行的开源JavaScript框架,用于构建用户界面和单页面应用程序。Vue的核心库只关注视图层,易于上手并且可以与其他库或现有项目轻松整合。
MYSQL数据库运行速度快,安全性能也很高,而且对使用的平台没有任何的限制,所以被广泛应运到系统的开发中。MySQL是一个开源和多线程的关系管理数据库系统,MySQL是开放源代码的数据库,具有跨平台性。
B/S(浏览器/服务器)结构是目前主流的网络化的结构模式,它能够把系统核心功能集中在服务器上面,可以帮助系统开发人员简化操作,便于维护和使用。
系统分析
对系统的可行性分析以及对所有功能需求进行详细的分析,来查看该系统是否具有开发的可能。

系统设计
功能模块设计和数据库设计这两部分内容都有专门的表格和图片表示。

系统实现
本系统前台功能丰富,首页提供系统概览与核心功能导航;酒店信息模块支持通过名称、城市或地址查询酒店,用户可查看酒店详情、进行收藏或评论,系统基于深度学习分析情感倾向,为用户决策提供参考。公告信息模块展示最新动态与通知;留言反馈模块供用户提交意见与建议,增强互动性。管理员主页面作为系统控制中心,提供全面的管理功能。页面通常详细列出所有管理模块,包括主页、用户、酒店信息、情感分析、酒店信息预测、留言反馈、系统管理、个人中心等,确保管理员能够高效地进行日常管理工作。整个页面布局清晰,功能模块化,便于管理员快速定位和操作。
代码实现
#coding:utf-8
pd.options.mode.chained_assignment = None # default='warn'
#获取当前文件路径的根目录
parent_directory = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
dbtype, host, port, user, passwd, dbName, charset,hasHadoop = config_read(os.path.join(parent_directory,"config.ini"))
#MySQL连接配置
mysql_config = {
'host': host,
'user':user,
'password': passwd,
'database': dbName,
'port':port
}
#获取预测可视化图表接口
def hotelinfoforecast_forecastimgs(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, 'message': 'success'}
# 指定目录
directory = os.path.join(parent_directory, "templates", "front", "hotelinfoforecast")
# 获取目录下的所有文件和文件夹名称
all_items = os.listdir(directory)
# 过滤出文件(排除文件夹)
files = [f'upload/hotelinfoforecast/{item}' for item in all_items if os.path.isfile(os.path.join(directory, item))]
msg["data"] = files
fontlist=[]
for font in fm.fontManager.ttflist:
fontlist.append(font.name)
msg["message"]=fontlist
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_forecast(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
#1.获取数据集
req_dict = request.session.get("req_dict")
connection = pymysql.connect(**mysql_config)
query = "SELECT hotelname,nowprice,preprice,score, scoredesc FROM hotelinfo"
#2.处理缺失值
data = pd.read_sql(query, connection).dropna()
id = req_dict.pop('id',None)
df = to_forecast(data,req_dict,None)
#9.创建数据库连接,将DataFrame 插入数据库
connection_string = f"mysql+pymysql://{mysql_config['user']}:{mysql_config['password']}@{mysql_config['host']}:{mysql_config['port']}/{mysql_config['database']}"
engine = create_engine(connection_string)
try:
if req_dict :
#遍历 DataFrame,并逐行更新数据库
with engine.connect() as connection:
for index, row in df.iterrows():
sql = """
INSERT INTO hotelinfoforecast (id
,scoredesc
)
VALUES (%(id)s
,%(scoredesc)s
)
ON DUPLICATE KEY UPDATE
scoredesc = VALUES(scoredesc)
"""
connection.execute(sql, {'id': id
, 'scoredesc': row['scoredesc']
})
else:
df.to_sql('hotelinfoforecast', con=engine, if_exists='append', index=False)
print("数据更新成功!")
except Exception as e:
print(f"发生错误: {e}")
finally:
engine.dispose() # 关闭数据库连接
return JsonResponse(msg, encoder=CustomJsonEncoder)
def to_forecast(data,req_dict,value):
if len(data) < 5:
print(f"的样本数量不足: {len(data)}")
return pd.DataFrame()
#3.处理特征值和目标值
labels={}
for key in data.keys():
if pd.api.types.is_string_dtype(data[key]):
label_encoder = LabelEncoder()
labels[key] = label_encoder
data[key] = label_encoder.fit_transform(data[key])
#4.数据集划分
X = data[[
'hotelname',
'nowprice',
'preprice',
'score',
]]
y = data[[
'scoredesc',
]]
x_train, x_test, y_train, y_test = train_test_split(X, y,test_size=0.2, random_state=22)
#5.构建预测特征值
#根据输入的特征值去预测
if req_dict:
req_dict.pop('addtime',None)
future_df = pd.DataFrame([req_dict])
for key in future_df.keys():
if key in labels:
encoder = labels[key]
values = future_df[key][0]
try:
values = encoder.transform([values])[0]
except ValueError as e: #处理未见过的标签
values = np.array([encoder.transform([v])[0] if v in encoder.classes_ else -1 for v in values]).sum()
future_df[key][0] = values
else:
future_df = x_test
#特征工程-标准化
transfer = DictVectorizer(sparse=False)
x_train = transfer.fit_transform(x_train.to_dict(orient="records"))
x_test = transfer.fit_transform(x_test.to_dict(orient="records"))
future_df = transfer.fit_transform(future_df.to_dict(orient="records"))
estimator_file = os.path.join(parent_directory, "hotelinfoforecast.pkl")
#6.决策树模型训练和模型评估
estimator = DecisionTreeClassifier(criterion="entropy", max_depth=5)
estimator.fit(x_train, y_train)
#生成决策树,重复tree.dot文件内的内容到网址:http://webgraphviz.com/ 可查看图示结构
export_graphviz(estimator, out_file="./tree.dot",feature_names=[
'hotelname',
'nowprice',
'preprice',
'score',
])
#保存模型
joblib.dump(estimator, estimator_file)
y_pred = estimator.predict(x_test)
comparison_df = pd.DataFrame({'实际值': y_test.values.flatten(), '预测值': y_pred.flatten()})
comparison_df = comparison_df.sort_values(by='实际值') # 按实际销量排序,方便可视化
# 绘制实际值 vs 预测值散点图
plt.figure(figsize=(10, 6))
plt.rcParams['font.sans-serif'] = ['SimHei'] # 使用黑体 SimHei
plt.rcParams['axes.unicode_minus'] = False # 解决负号 '-' 显示为方块的问题
sns.scatterplot(x=comparison_df['实际值'], y=comparison_df['预测值'], color='blue', label='预测值')
plt.plot([comparison_df['实际值'].min(), comparison_df['实际值'].max()],
[comparison_df['实际值'].min(), comparison_df['实际值'].max()],
color='red', linestyle='--', label='完美预测线')
plt.xlabel('实际值')
plt.ylabel('预测值')
plt.title('实际值 vs 预测值')
plt.legend()
directory =os.path.join(parent_directory, "templates","front","hotelinfoforecast","figure.png")
os.makedirs(os.path.dirname(directory), exist_ok=True)
plt.savefig(directory)
plt.clf()
plt.close()
#7.进行预测
y_predict = estimator.predict(future_df)
if isinstance(y_predict[0], numbers.Number) or len(y_predict[0])<2:
y_predict = np.mean(y_predict, axis=0)
if not isinstance(y_predict, np.ndarray):
y_predict = np.expand_dims(y_predict, axis=0)
df = pd.DataFrame(y_predict, columns=[
'scoredesc',
])
df['scoredesc']=df['scoredesc'].astype(int)
df['scoredesc'] = labels['scoredesc'].inverse_transform(df['scoredesc'])
return df
def hotelinfoforecast_register(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
error = hotelinfoforecast.createbyreq(hotelinfoforecast, hotelinfoforecast, req_dict)
if error is Exception:
msg['code'] = crud_error_code
msg['msg'] = "用户已存在,请勿重复注册!"
else:
msg['data'] = error
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_login(request):
if request.method in ["POST", "GET"]:
msg = {'code': normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
datas = hotelinfoforecast.getbyparams(hotelinfoforecast, hotelinfoforecast, req_dict)
if not datas:
msg['code'] = password_error_code
msg['msg'] = mes.password_error_code
return JsonResponse(msg, encoder=CustomJsonEncoder)
try:
__sfsh__= hotelinfoforecast.__sfsh__
except:
__sfsh__=None
if __sfsh__=='是':
if datas[0].get('sfsh')!='是':
msg['code']=other_code
msg['msg'] = "账号已锁定,请联系管理员审核!"
return JsonResponse(msg, encoder=CustomJsonEncoder)
req_dict['id'] = datas[0].get('id')
return Auth.authenticate(Auth, hotelinfoforecast, req_dict)
def hotelinfoforecast_logout(request):
if request.method in ["POST", "GET"]:
msg = {
"msg": "登出成功",
"code": 0
}
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_resetPass(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
req_dict = request.session.get("req_dict")
columns= hotelinfoforecast.getallcolumn( hotelinfoforecast, hotelinfoforecast)
try:
__loginUserColumn__= hotelinfoforecast.__loginUserColumn__
except:
__loginUserColumn__=None
username=req_dict.get(list(req_dict.keys())[0])
if __loginUserColumn__:
username_str=__loginUserColumn__
else:
username_str=username
if 'mima' in columns:
password_str='mima'
else:
password_str='password'
init_pwd = '123456'
recordsParam = {}
recordsParam[username_str] = req_dict.get("username")
records=hotelinfoforecast.getbyparams(hotelinfoforecast, hotelinfoforecast, recordsParam)
if len(records)<1:
msg['code'] = 400
msg['msg'] = '用户不存在'
return JsonResponse(msg, encoder=CustomJsonEncoder)
eval('''hotelinfoforecast.objects.filter({}='{}').update({}='{}')'''.format(username_str,username,password_str,init_pwd))
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_session(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict={"id":request.session.get('params').get("id")}
msg['data'] = hotelinfoforecast.getbyparams(hotelinfoforecast, hotelinfoforecast, req_dict)[0]
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_default(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code,"msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
req_dict.update({"isdefault":"是"})
data=hotelinfoforecast.getbyparams(hotelinfoforecast, hotelinfoforecast, req_dict)
if len(data)>0:
msg['data'] = data[0]
else:
msg['data'] = {}
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_page(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
global hotelinfoforecast
#获取全部列名
columns= hotelinfoforecast.getallcolumn( hotelinfoforecast, hotelinfoforecast)
if "vipread" in req_dict and "vipread" not in columns:
del req_dict["vipread"]
#当前登录用户所在表
tablename = request.session.get("tablename")
'''__authSeparate__此属性为真,params添加userid,后台只查询个人数据'''
try:
__authSeparate__=hotelinfoforecast.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="是":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns and 'userid' not in req_dict:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
#当项目属性hasMessage为”是”,生成系统自动生成留言板的表messages,同时该表的表属性hasMessage也被设置为”是”,字段包括userid(用户id),username(用户名),content(留言内容),reply(回复)
#接口page需要区分权限,普通用户查看自己的留言和回复记录,管理员查看所有的留言和回复记录
try:
__hasMessage__=hotelinfoforecast.__hasMessage__
except:
__hasMessage__=None
if __hasMessage__=="是":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict["userid"]=request.session.get("params").get("id")
# 判断当前表的表属性isAdmin,为真则是管理员表
# 当表属性isAdmin=”是”,刷出来的用户表也是管理员,即page和list可以查看所有人的考试记录(同时应用于其他表)
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
# 当前表也是有管理员权限的表
if __isAdmin__ == "是" and 'hotelinfoforecast' != 'forum' :
if req_dict.get("userid") and 'hotelinfoforecast' != 'chat' and 'hotelinfoforecast' != 'examrecord':
del req_dict["userid"]
else:
if tablename!="users" and tablename!="jdfnl" and 'hotelinfoforecast'[:7]!='discuss' and "userid" in hotelinfoforecast.getallcolumn(hotelinfoforecast,hotelinfoforecast):
req_dict["userid"] = request.session.get("params").get("id")
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致],则对应的表有个隐藏属性authTable为”是”,那么该用户查看该表信息时,只能查看自己的
try:
__authTables__=hotelinfoforecast.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __isAdmin__ == "是":
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
username=params.get(authColumn)
break
q = Q()
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] =hotelinfoforecast.page(hotelinfoforecast, hotelinfoforecast, req_dict, request, q)
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_autoSort(request):
'''
.智能推荐功能(表属性:[intelRecom(是/否)],新增clicktime[前端不显示该字段]字段(调用info/detail接口的时候更新),按clicktime排序查询)
主要信息列表(如商品列表,新闻列表)中使用,显示最近点击的或最新添加的5条记录就行
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
if "clicknum" in hotelinfoforecast.getallcolumn(hotelinfoforecast,hotelinfoforecast):
req_dict['sort']='clicknum'
elif "browseduration" in hotelinfoforecast.getallcolumn(hotelinfoforecast,hotelinfoforecast):
req_dict['sort']='browseduration'
else:
req_dict['sort']='clicktime'
req_dict['order']='desc'
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = hotelinfoforecast.page(hotelinfoforecast,hotelinfoforecast, req_dict)
return JsonResponse(msg, encoder=CustomJsonEncoder)
#分类列表
def hotelinfoforecast_lists(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":[]}
msg['data'],_,_,_,_ = hotelinfoforecast.page(hotelinfoforecast, hotelinfoforecast, {})
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_query(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
try:
query_result = hotelinfoforecast.objects.filter(**request.session.get("req_dict")).values()
msg['data'] = query_result[0]
except Exception as e:
msg['code'] = crud_error_code
msg['msg'] = f"发生错误:{e}"
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_list(request):
'''
前台分页
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data":{"currPage":1,"totalPage":1,"total":1,"pageSize":10,"list":[]}}
req_dict = request.session.get("req_dict")
#获取全部列名
columns= hotelinfoforecast.getallcolumn( hotelinfoforecast, hotelinfoforecast)
if "vipread" in req_dict and "vipread" not in columns:
del req_dict["vipread"]
#表属性[foreEndList]前台list:和后台默认的list列表页相似,只是摆在前台,否:指没有此页,是:表示有此页(不需要登陆即可查看),前要登:表示有此页且需要登陆后才能查看
try:
__foreEndList__=hotelinfoforecast.__foreEndList__
except:
__foreEndList__=None
try:
__foreEndListAuth__=hotelinfoforecast.__foreEndListAuth__
except:
__foreEndListAuth__=None
#authSeparate
try:
__authSeparate__=hotelinfoforecast.__authSeparate__
except:
__authSeparate__=None
if __foreEndListAuth__ =="是" and __authSeparate__=="是":
tablename=request.session.get("tablename")
if tablename!="users" and request.session.get("params") is not None:
req_dict['userid']=request.session.get("params").get("id")
tablename = request.session.get("tablename")
if tablename == "users" and req_dict.get("userid") != None:#判断是否存在userid列名
del req_dict["userid"]
else:
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
if __isAdmin__ == "是":
if req_dict.get("userid"):
# del req_dict["userid"]
pass
else:
#非管理员权限的表,判断当前表字段名是否有userid
if "userid" in columns:
try:
pass
except:
pass
#当列属性authTable有值(某个用户表)[该列的列名必须和该用户表的登陆字段名一致],则对应的表有个隐藏属性authTable为”是”,那么该用户查看该表信息时,只能查看自己的
try:
__authTables__=hotelinfoforecast.__authTables__
except:
__authTables__=None
if __authTables__!=None and __authTables__!={} and __foreEndListAuth__=="是":
for authColumn,authTable in __authTables__.items():
if authTable==tablename:
try:
del req_dict['userid']
except:
pass
params = request.session.get("params")
req_dict[authColumn]=params.get(authColumn)
username=params.get(authColumn)
break
if hotelinfoforecast.__tablename__[:7]=="discuss":
try:
del req_dict['userid']
except:
pass
q = Q()
msg['data']['list'], msg['data']['currPage'], msg['data']['totalPage'], msg['data']['total'], \
msg['data']['pageSize'] = hotelinfoforecast.page(hotelinfoforecast, hotelinfoforecast, req_dict, request, q)
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_save(request):
'''
后台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if 'clicktime' in req_dict.keys():
del req_dict['clicktime']
tablename=request.session.get("tablename")
__isAdmin__ = None
allModels = apps.get_app_config('main').get_models()
for m in allModels:
if m.__tablename__==tablename:
try:
__isAdmin__ = m.__isAdmin__
except:
__isAdmin__ = None
break
#获取全部列名
columns= hotelinfoforecast.getallcolumn( hotelinfoforecast, hotelinfoforecast)
if tablename!='users' and req_dict.get("userid")!=None and 'userid' in columns and __isAdmin__!='是':
params=request.session.get("params")
req_dict['userid']=params.get('id')
if 'addtime' in req_dict.keys():
del req_dict['addtime']
idOrErr= hotelinfoforecast.createbyreq(hotelinfoforecast,hotelinfoforecast, req_dict)
if idOrErr is Exception:
msg['code'] = crud_error_code
msg['msg'] = idOrErr
else:
msg['data'] = idOrErr
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_add(request):
'''
前台新增
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
tablename=request.session.get("tablename")
#获取全部列名
columns= hotelinfoforecast.getallcolumn( hotelinfoforecast, hotelinfoforecast)
try:
__authSeparate__=hotelinfoforecast.__authSeparate__
except:
__authSeparate__=None
if __authSeparate__=="是":
tablename=request.session.get("tablename")
if tablename!="users" and 'userid' in columns:
try:
req_dict['userid']=request.session.get("params").get("id")
except:
pass
try:
__foreEndListAuth__=hotelinfoforecast.__foreEndListAuth__
except:
__foreEndListAuth__=None
if __foreEndListAuth__ and __foreEndListAuth__!="否":
tablename=request.session.get("tablename")
if tablename!="users":
req_dict['userid']=request.session.get("params").get("id")
if 'addtime' in req_dict.keys():
del req_dict['addtime']
error= hotelinfoforecast.createbyreq(hotelinfoforecast,hotelinfoforecast, req_dict)
if error is Exception:
msg['code'] = crud_error_code
msg['msg'] = error
else:
msg['data'] = error
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_thumbsup(request,id_):
'''
点赞:表属性thumbsUp[是/否],刷表新增thumbsupnum赞和crazilynum踩字段,
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
id_=int(id_)
type_=int(req_dict.get("type",0))
rets=hotelinfoforecast.getbyid(hotelinfoforecast,hotelinfoforecast,id_)
update_dict={
"id":id_,
}
if type_==1:#赞
update_dict["thumbsupnum"]=int(rets[0].get('thumbsupnum'))+1
elif type_==2:#踩
update_dict["crazilynum"]=int(rets[0].get('crazilynum'))+1
error = hotelinfoforecast.updatebyparams(hotelinfoforecast,hotelinfoforecast, update_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_info(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data = hotelinfoforecast.getbyid(hotelinfoforecast,hotelinfoforecast, int(id_))
if len(data)>0:
msg['data']=data[0]
if msg['data'].__contains__("reversetime"):
if isinstance(msg['data']['reversetime'], datetime.datetime):
msg['data']['reversetime'] = msg['data']['reversetime'].strftime("%Y-%m-%d %H:%M:%S")
else:
if msg['data']['reversetime'] != None:
reversetime = datetime.datetime.strptime(msg['data']['reversetime'], '%Y-%m-%d %H:%M:%S')
msg['data']['reversetime'] = reversetime.strftime("%Y-%m-%d %H:%M:%S")
#浏览点击次数
try:
__browseClick__= hotelinfoforecast.__browseClick__
except:
__browseClick__=None
if __browseClick__=="是" and "clicknum" in hotelinfoforecast.getallcolumn(hotelinfoforecast,hotelinfoforecast):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum,"clicktime":datetime.datetime.now()}
ret=hotelinfoforecast.updatebyparams(hotelinfoforecast,hotelinfoforecast,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_detail(request,id_):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
data =hotelinfoforecast.getbyid(hotelinfoforecast,hotelinfoforecast, int(id_))
if len(data)>0:
msg['data']=data[0]
if msg['data'].__contains__("reversetime"):
if isinstance(msg['data']['reversetime'], datetime.datetime):
msg['data']['reversetime'] = msg['data']['reversetime'].strftime("%Y-%m-%d %H:%M:%S")
else:
if msg['data']['reversetime'] != None:
reversetime = datetime.datetime.strptime(msg['data']['reversetime'], '%Y-%m-%d %H:%M:%S')
msg['data']['reversetime'] = reversetime.strftime("%Y-%m-%d %H:%M:%S")
#浏览点击次数
try:
__browseClick__= hotelinfoforecast.__browseClick__
except:
__browseClick__=None
if __browseClick__=="是" and "clicknum" in hotelinfoforecast.getallcolumn(hotelinfoforecast,hotelinfoforecast):
try:
clicknum=int(data[0].get("clicknum",0))+1
except:
clicknum=0+1
click_dict={"id":int(id_),"clicknum":clicknum,"clicktime":datetime.datetime.now()}
ret=hotelinfoforecast.updatebyparams(hotelinfoforecast,hotelinfoforecast,click_dict)
if ret!=None:
msg['code'] = crud_error_code
msg['msg'] = ret
return JsonResponse(msg, encoder=CustomJsonEncoder)
def hotelinfoforecast_update(request):
'''
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
if 'clicktime' in req_dict.keys() and req_dict['clicktime']=="None":
del req_dict['clicktime']
if req_dict.get("mima") and "mima" not in hotelinfoforecast.getallcolumn(hotelinfoforecast,hotelinfoforecast) :
del req_dict["mima"]
if req_dict.get("password") and "password" not in hotelinfoforecast.getallcolumn(hotelinfoforecast,hotelinfoforecast) :
del req_dict["password"]
try:
del req_dict["clicknum"]
except:
pass
error = hotelinfoforecast.updatebyparams(hotelinfoforecast, hotelinfoforecast, req_dict)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def hotelinfoforecast_delete(request):
'''
批量删除
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code, "data": {}}
req_dict = request.session.get("req_dict")
error=hotelinfoforecast.deletes(hotelinfoforecast,
hotelinfoforecast,
req_dict.get("ids")
)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def hotelinfoforecast_vote(request,id_):
'''
浏览点击次数(表属性[browseClick:是/否],点击字段(clicknum),调用info/detail接口的时候后端自动+1)、投票功能(表属性[vote:是/否],投票字段(votenum),调用vote接口后端votenum+1)
统计商品或新闻的点击次数;提供新闻的投票功能
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": mes.normal_code}
data= hotelinfoforecast.getbyid(hotelinfoforecast, hotelinfoforecast, int(id_))
for i in data:
votenum=i.get('votenum')
if votenum!=None:
params={"id":int(id_),"votenum":votenum+1}
error=hotelinfoforecast.updatebyparams(hotelinfoforecast,hotelinfoforecast,params)
if error!=None:
msg['code'] = crud_error_code
msg['msg'] = error
return JsonResponse(msg)
def hotelinfoforecast_importExcel(request):
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
excel_file = request.FILES.get("file", "")
file_type = excel_file.name.split('.')[1]
if file_type in ['xlsx', 'xls']:
data = xlrd.open_workbook(filename=None, file_contents=excel_file.read())
table = data.sheets()[0]
rows = table.nrows
try:
for row in range(1, rows):
row_values = table.row_values(row)
req_dict = {}
hotelinfoforecast.createbyreq(hotelinfoforecast, hotelinfoforecast, req_dict)
except:
pass
else:
msg = {
"msg": "文件类型错误",
"code": 500
}
return JsonResponse(msg)
def hotelinfoforecast_autoSort2(request):
return JsonResponse({"code": 0, "msg": '', "data":{}})
def hotelinfoforecast_count(request):
'''
总数接口
'''
if request.method in ["POST", "GET"]:
msg = {"code": normal_code, "msg": "成功", "data": {}}
req_dict = request.session.get("req_dict")
where = ' where 1 = 1 '
for key in req_dict:
if req_dict[key] != None:
where = where + " and key like '{0}'".format(req_dict[key])
sql = "SELECT count(*) AS count FROM hotelinfoforecast {0}".format(where)
count = 0
cursor = connection.cursor()
cursor.execute(sql)
desc = cursor.description
data_dict = [dict(zip([col[0] for col in desc], row)) for row in cursor.fetchall()]
for online_dict in data_dict:
count = online_dict['count']
msg['data'] = count
return JsonResponse(msg, encoder=CustomJsonEncoder)
系统测试
系统测试的终极目标在于确保软件产品能够满足所有预定的需求和功能标准。系统测试通过模拟用户在真实环境中的操作和使用场景,对软件进行全面的验证。这包括对软件的功能性、性能、安全性、兼容性、稳定性和可用性等多个维度的细致检验。系统测试的目的是发现并记录软件中存在的缺陷,评估软件的可靠性和效率,并确保软件能够在各种预期的使用条件下正常运行。系统测试还旨在验证软件是否符合相关的法规和标准要求。通过这一过程,开发团队可以在产品发布前对发现的问题进行修复和优化,从而提高软件的整体质量,减少未来的维护成本,并最终提升用户的满意度。
结论
在本次设计中,我深入研究并分析了基于深度学习的酒店评论文本情感分析研究系统的相关问题。这一过程不仅加深了我对理论知识的理解,也积累了宝贵的实践经验。在项目实施的过程中,我遇到了诸多挑战,如数据收集的难度、模型构建的复杂性以及结果分析的准确性等问题。面对这些困难,我通过不断的实验和调整,最终成功克服了它们,实现了预期的研究目标。
更多推荐
所有评论(0)