You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
613 B

9 months ago
from flask import Flask, request
from cppy.cp_util import *
'''
使用Flask构建一个简单的服务端
该服务端能够接收POST请求并返回词频统计结果
先运行该代码搭建起服务端然后运行request文件进行词频统计
'''
app = Flask(__name__)
@app.route('/word_frequency', methods=['POST'])
def word_frequency():
# 获取POST请求中的JSON数据
data = request.get_json()
data = data['file']
# 统计词频
word_freq = get_frequencies(data)
word_freq = sort_dict(word_freq)
return word_freq
if __name__ == '__main__':
app.run(debug=True)