接口简单实现
1.简单实现接口的功能
下面展示一些 代码片
。
## -*- coding: utf-8 -*-
from flask import Flask,request,jsonify
app = Flask(__name__)
@app.route('/')
def hello_world():
return '基于关键词的语义泛化系统'
@app.route('/kwpu',methods=['POST'])
def keyword_pickup():
my_json = request.get_json()
# print(my_json)
my_string = my_json.get("String")
'''
这边写业务
'''
# 示例函数,截取返回代替关键字提取
keyword = my_string[:4]
keyword = keyword + ',' + my_string[9:15]
keyword = keyword + ',' + my_string[25:28]
keyword = keyword + ',' + my_string[42:46]
keyword = keyword + ',' + my_string[-6:]
print(keyword)
return jsonify({'keyword':keyword})
# return 'nothing'
@app.route('/gen',methods=['POST'])
def generalization():
my_json = request.get_json()
my_string = my_json.get("String")
'''
这边写业务
'''
# 示例函数,取前两个字代表泛化
# print(my_string,":要跑gen了哦")
gen = my_string[:1]
return jsonify({'gen':gen})
if __name__ == '__main__':
app.run()
这def keyword_pickup() 实现关键词的提取
这def generalization()实现关键词的泛化