upload server files
Browse files- server/alarm_sev.py +114 -0
- server/audiobook_sev.py +100 -0
- server/calendar_sev.py +129 -0
- server/cooking_sev.py +83 -0
- server/datetime_sev.py +123 -0
- server/email_sev.py +162 -0
- server/game_sev.py +76 -0
- server/iot_sev.py +124 -0
- server/lists_sev.py +115 -0
- server/music_sev.py +111 -0
- server/news_sev.py +97 -0
- server/phone_sev.py +87 -0
- server/podcasts_sev.py +85 -0
- server/radio_sev.py +121 -0
- server/recom_sev.py +117 -0
- server/run.sh +22 -0
- server/social_sev.py +109 -0
- server/takeaway_sev.py +121 -0
- server/transport_sev.py +138 -0
server/alarm_sev.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
timep=re.compile(r"\d\d:\d\d[( am)|( pm)|( AM)|(( PM))]*")
|
| 24 |
+
@app.route("/alarm", methods=["GET", "POST"])
|
| 25 |
+
def check():
|
| 26 |
+
intent=""
|
| 27 |
+
slots=dict()
|
| 28 |
+
start_time = time.time()
|
| 29 |
+
if request.method == "POST":
|
| 30 |
+
jsondata = request.get_data(as_text=True)
|
| 31 |
+
if jsondata:
|
| 32 |
+
data = json.loads(jsondata)
|
| 33 |
+
print(data)
|
| 34 |
+
else:
|
| 35 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 36 |
+
return return_dict
|
| 37 |
+
params = ['intent', ]
|
| 38 |
+
for param in params:
|
| 39 |
+
if param not in data:
|
| 40 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 41 |
+
return return_dict
|
| 42 |
+
intent = data.get('intent')
|
| 43 |
+
#iid = str(data.get('iid'))
|
| 44 |
+
if "event_name" in data:
|
| 45 |
+
slots["event_name"] = data.get('event_name')
|
| 46 |
+
if "descriptor" in data:
|
| 47 |
+
slots["descriptor"] = data.get('descriptor')
|
| 48 |
+
if "time" in data:
|
| 49 |
+
slots["time"] = data.get('time')
|
| 50 |
+
if "from_time" in data:
|
| 51 |
+
slots["from_time"] = data.get('from_time')
|
| 52 |
+
if "to_time" in data:
|
| 53 |
+
slots["to_time"] = data.get('to_time')
|
| 54 |
+
if "time2" in data:
|
| 55 |
+
slots["time2"] = data.get('time2')
|
| 56 |
+
#if "timeofday" in data:
|
| 57 |
+
# slots["timeofday"] = data.get('timeofday')
|
| 58 |
+
if request.method == "GET":
|
| 59 |
+
if "intent" in request.args:
|
| 60 |
+
intent = request.args.get("intent")
|
| 61 |
+
if "event_name" in request.args:
|
| 62 |
+
slots["event_name"] = request.args.get('event_name')
|
| 63 |
+
if "descriptor" in request.args:
|
| 64 |
+
slots["descriptor"] = request.args.get('descriptor')
|
| 65 |
+
if "time" in request.args:
|
| 66 |
+
slots["time"] = request.args.get('time')
|
| 67 |
+
if "from_time" in request.args:
|
| 68 |
+
slots["from_time"] = request.args.get('from_time')
|
| 69 |
+
if "to_time" in request.args:
|
| 70 |
+
slots["to_time"] = request.args.get('to_time')
|
| 71 |
+
if "time2" in request.args:
|
| 72 |
+
slots["time2"] = request.args.get('time2')
|
| 73 |
+
|
| 74 |
+
response="operated successfully"
|
| 75 |
+
query = {"intent":intent,"slots":slots}
|
| 76 |
+
if intent =="alarm_set":
|
| 77 |
+
if "time" not in slots:
|
| 78 |
+
response="when do you want to set the alarm"
|
| 79 |
+
elif intent =="alarm_query":
|
| 80 |
+
if len(slots)==0:
|
| 81 |
+
response="all the alarms are listed here. alarm 1: time:...."
|
| 82 |
+
else:
|
| 83 |
+
response="find 1 result. alarm index: 12, alarm time: ...."
|
| 84 |
+
elif intent=="alarm_remove":
|
| 85 |
+
if len(slots)==0:
|
| 86 |
+
response="do you want to delete all the alarms?"
|
| 87 |
+
elif intent=="alarm_change":
|
| 88 |
+
if len(slots)==0:
|
| 89 |
+
response="which alarm do you want to change?"
|
| 90 |
+
else:
|
| 91 |
+
response="not supporting intent"
|
| 92 |
+
for key,value in slots.items() :
|
| 93 |
+
if key.find("time")!=-1:
|
| 94 |
+
if timep.match(value) is None:
|
| 95 |
+
response="time format not right"
|
| 96 |
+
print('耗时:' + str(time.time()-start_time))
|
| 97 |
+
print('----------------------')
|
| 98 |
+
return_dict = {}
|
| 99 |
+
return_dict['code'] = 'SUCCESS'
|
| 100 |
+
return_dict['msg'] = '成功'
|
| 101 |
+
contents = {}
|
| 102 |
+
contents['response'] = response
|
| 103 |
+
contents['query'] = query
|
| 104 |
+
return_dict['data'] = contents
|
| 105 |
+
return return_dict
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
print("模型load完毕")
|
| 109 |
+
|
| 110 |
+
if __name__ == "__main__":
|
| 111 |
+
print("启动开始---------")
|
| 112 |
+
port = sys.argv[1]
|
| 113 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 114 |
+
print("启动完成---------")
|
server/audiobook_sev.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
app=Flask(__name__)
|
| 9 |
+
|
| 10 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 11 |
+
queries = dict()
|
| 12 |
+
with open(file_path ) as f:
|
| 13 |
+
lines=f.readlines()
|
| 14 |
+
count=0
|
| 15 |
+
for line in lines:
|
| 16 |
+
line=line.strip()
|
| 17 |
+
query=json.loads(line)
|
| 18 |
+
if query['domain']==domain:
|
| 19 |
+
queries[query["iid"]]=query
|
| 20 |
+
|
| 21 |
+
return queries
|
| 22 |
+
|
| 23 |
+
@app.route("/audiobook", methods=["GET", "POST"])
|
| 24 |
+
def check():
|
| 25 |
+
intent=""
|
| 26 |
+
slots=dict()
|
| 27 |
+
start_time = time.time()
|
| 28 |
+
if request.method == "POST":
|
| 29 |
+
jsondata = request.get_data(as_text=True)
|
| 30 |
+
if jsondata:
|
| 31 |
+
data = json.loads(jsondata)
|
| 32 |
+
print(data)
|
| 33 |
+
else:
|
| 34 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 35 |
+
return return_dict
|
| 36 |
+
params = ['intent', ]
|
| 37 |
+
for param in params:
|
| 38 |
+
if param not in data:
|
| 39 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 40 |
+
return return_dict
|
| 41 |
+
intent = data.get('intent')
|
| 42 |
+
#iid = str(data.get('iid'))
|
| 43 |
+
if "player_setting" in data:
|
| 44 |
+
slots["player_setting"] = data.get('player_setting')
|
| 45 |
+
if "house_place" in data:
|
| 46 |
+
slots["house_place"] = data.get('house_place')
|
| 47 |
+
if "media_type" in data:
|
| 48 |
+
slots["media_type"] = data.get('media_type')
|
| 49 |
+
if "descriptor" in data:
|
| 50 |
+
slots["descriptor"] = data.get('descriptor')
|
| 51 |
+
if "audiobook_name" in data:
|
| 52 |
+
slots["audiobook_name"] = data.get('audiobook_name')
|
| 53 |
+
if "author_name" in data:
|
| 54 |
+
slots["author_name"] = data.get('author_name')
|
| 55 |
+
if request.method == "GET":
|
| 56 |
+
if "intent" in request.args:
|
| 57 |
+
intent = request.args.get("intent")
|
| 58 |
+
data=request.args
|
| 59 |
+
if "player_setting" in data:
|
| 60 |
+
slots["player_setting"] = data.get('player_setting')
|
| 61 |
+
if "house_place" in data:
|
| 62 |
+
slots["house_place"] = data.get('house_place')
|
| 63 |
+
if "media_type" in data:
|
| 64 |
+
slots["media_type"] = data.get('media_type')
|
| 65 |
+
if "descriptor" in data:
|
| 66 |
+
slots["descriptor"] = data.get('descriptor')
|
| 67 |
+
if "audiobook_name" in data:
|
| 68 |
+
slots["audiobook_name"] = data.get('audiobook_name')
|
| 69 |
+
if "author_name" in data:
|
| 70 |
+
slots["author_name"] = data.get('author_name')
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
response="operated successfully"
|
| 74 |
+
query = {"intent":intent,"slots":slots}
|
| 75 |
+
if intent =="play_audiobook":
|
| 76 |
+
if len(slots)==0:
|
| 77 |
+
response="playing random audiobook"
|
| 78 |
+
else:
|
| 79 |
+
pass
|
| 80 |
+
else:
|
| 81 |
+
response="not supporting intent"
|
| 82 |
+
print('耗时:' + str(time.time()-start_time))
|
| 83 |
+
print('----------------------')
|
| 84 |
+
return_dict = {}
|
| 85 |
+
return_dict['code'] = 'SUCCESS'
|
| 86 |
+
return_dict['msg'] = '成功'
|
| 87 |
+
contents = {}
|
| 88 |
+
contents['response'] = response
|
| 89 |
+
contents['query'] = query
|
| 90 |
+
return_dict['data'] = contents
|
| 91 |
+
return return_dict
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
print("模型load完毕")
|
| 95 |
+
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
print("启动开始---------")
|
| 98 |
+
port = sys.argv[1]
|
| 99 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 100 |
+
print("启动完成---------")
|
server/calendar_sev.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
import time
|
| 7 |
+
import csv
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
|
| 24 |
+
datep=re.compile(r"202\d-\d\d-\d\d")
|
| 25 |
+
timep=re.compile(r"(202\d-\d\d-\d\d )*\d\d:\d\d[( am)|( pm)|( AM)|(( PM))]*")
|
| 26 |
+
@app.route("/calendar", methods=["GET", "POST"])
|
| 27 |
+
def check():
|
| 28 |
+
intent=""
|
| 29 |
+
slots=dict()
|
| 30 |
+
start_time = time.time()
|
| 31 |
+
if request.method == "POST":
|
| 32 |
+
jsondata = request.get_data(as_text=True)
|
| 33 |
+
if jsondata:
|
| 34 |
+
data = json.loads(jsondata)
|
| 35 |
+
print(data)
|
| 36 |
+
else:
|
| 37 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 38 |
+
return return_dict
|
| 39 |
+
params = ['intent', ]
|
| 40 |
+
for param in params:
|
| 41 |
+
if param not in data:
|
| 42 |
+
print("失败,缺少参数:")
|
| 43 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 44 |
+
return return_dict
|
| 45 |
+
intent = data.get('intent')
|
| 46 |
+
#iid = str(data.get('iid'))
|
| 47 |
+
if "event_name" in data:
|
| 48 |
+
slots["event_name"] = data.get('event_name')
|
| 49 |
+
if "descriptor" in data:
|
| 50 |
+
slots["descriptor"] = data.get('descriptor')
|
| 51 |
+
if "person" in data:
|
| 52 |
+
slots["person"] = data.get('person')
|
| 53 |
+
if "relation" in data:
|
| 54 |
+
slots["relation"] = data.get('relation')
|
| 55 |
+
if "date" in data:
|
| 56 |
+
slots["date"] = data.get('date')
|
| 57 |
+
#if "timeofday" in data:
|
| 58 |
+
# slots["timeofday"] = data.get('timeofday')
|
| 59 |
+
if "time" in data:
|
| 60 |
+
slots["time"] = data.get('time')
|
| 61 |
+
if "from_time" in data:
|
| 62 |
+
slots["from_time"] = data.get('from_time')
|
| 63 |
+
if "to_time" in data:
|
| 64 |
+
slots["to_time"] = data.get('to_time')
|
| 65 |
+
if "time2" in data:
|
| 66 |
+
slots["time2"] = data.get('time2')
|
| 67 |
+
if request.method == "GET":
|
| 68 |
+
if "intent" in request.args:
|
| 69 |
+
intent = request.args.get("intent")
|
| 70 |
+
if "event_name" in request.args:
|
| 71 |
+
slots["event_name"] = request.args.get('event_name')
|
| 72 |
+
if "descriptor" in request.args:
|
| 73 |
+
slots["descriptor"] = request.args.get('descriptor')
|
| 74 |
+
if "person" in request.args:
|
| 75 |
+
slots["person"] = request.args.get('person')
|
| 76 |
+
if "relation" in request.args:
|
| 77 |
+
slots["relation"] = request.args.get('relation')
|
| 78 |
+
if "date" in request.args:
|
| 79 |
+
slots["date"] = request.args.get('date')
|
| 80 |
+
if "time" in request.args:
|
| 81 |
+
slots["time"] = request.args.get('time')
|
| 82 |
+
if "from_time" in request.args:
|
| 83 |
+
slots["from_time"] = request.args.get('from_time')
|
| 84 |
+
if "to_time" in request.args:
|
| 85 |
+
slots["to_time"] = request.args.get('to_time')
|
| 86 |
+
if "time2" in request.args:
|
| 87 |
+
slots["time2"] = request.args.get('time2')
|
| 88 |
+
|
| 89 |
+
response="operated successfully"
|
| 90 |
+
query = {"intent":intent,"slots":slots}
|
| 91 |
+
if intent =="calendar_set":
|
| 92 |
+
if "time" not in slots:
|
| 93 |
+
response="what time do you want to set the event?"
|
| 94 |
+
elif intent =="calendar_query":
|
| 95 |
+
if len(slots)==0:
|
| 96 |
+
response="all the events are listed here. event 1: time:...."
|
| 97 |
+
else:
|
| 98 |
+
response="find 1 result. event index: 11, event time: ...."
|
| 99 |
+
elif intent=="calendar_remove":
|
| 100 |
+
if len(slots)==0:
|
| 101 |
+
response="do you want to delete all the events?"
|
| 102 |
+
else:
|
| 103 |
+
response="not supporting intent"
|
| 104 |
+
for key,value in slots.items() :
|
| 105 |
+
if key.find("time")!=-1:
|
| 106 |
+
if timep.match(value) is None:
|
| 107 |
+
response="time format not right"
|
| 108 |
+
if key.find("date")!=-1:
|
| 109 |
+
if datep.match(value) is None:
|
| 110 |
+
response="date format not right"
|
| 111 |
+
print('耗时:' + str(time.time()-start_time))
|
| 112 |
+
print('----------------------')
|
| 113 |
+
return_dict = {}
|
| 114 |
+
return_dict['code'] = 'SUCCESS'
|
| 115 |
+
return_dict['msg'] = '成功'
|
| 116 |
+
contents = {}
|
| 117 |
+
contents['response'] = response
|
| 118 |
+
contents['query'] = query
|
| 119 |
+
return_dict['data'] = contents
|
| 120 |
+
return return_dict
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
print("模型load完毕")
|
| 124 |
+
|
| 125 |
+
if __name__ == "__main__":
|
| 126 |
+
print("启动开始---------")
|
| 127 |
+
port = sys.argv[1]
|
| 128 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 129 |
+
print("启动完成---------")
|
server/cooking_sev.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
app=Flask(__name__)
|
| 9 |
+
|
| 10 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 11 |
+
queries = dict()
|
| 12 |
+
with open(file_path ) as f:
|
| 13 |
+
lines=f.readlines()
|
| 14 |
+
count=0
|
| 15 |
+
for line in lines:
|
| 16 |
+
line=line.strip()
|
| 17 |
+
query=json.loads(line)
|
| 18 |
+
if query['domain']==domain:
|
| 19 |
+
queries[query["iid"]]=query
|
| 20 |
+
|
| 21 |
+
return queries
|
| 22 |
+
|
| 23 |
+
@app.route("/cooking", methods=["GET", "POST"])
|
| 24 |
+
def check():
|
| 25 |
+
intent=""
|
| 26 |
+
slots=dict()
|
| 27 |
+
start_time = time.time()
|
| 28 |
+
if request.method == "POST":
|
| 29 |
+
jsondata = request.get_data(as_text=True)
|
| 30 |
+
if jsondata:
|
| 31 |
+
data = json.loads(jsondata)
|
| 32 |
+
print(data)
|
| 33 |
+
else:
|
| 34 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 35 |
+
return return_dict
|
| 36 |
+
params = ['intent', ]
|
| 37 |
+
for param in params:
|
| 38 |
+
if param not in data:
|
| 39 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 40 |
+
return return_dict
|
| 41 |
+
intent = data.get('intent')
|
| 42 |
+
#iid = str(data.get('iid'))
|
| 43 |
+
if "food_type" in data:
|
| 44 |
+
slots["food_type"] = data.get('food_type')
|
| 45 |
+
if "descriptor" in data:
|
| 46 |
+
slots["descriptor"] = data.get('descriptor')
|
| 47 |
+
if request.method == "GET":
|
| 48 |
+
if "intent" in request.args:
|
| 49 |
+
intent = request.args.get("intent")
|
| 50 |
+
data=request.args
|
| 51 |
+
if "food_type" in data:
|
| 52 |
+
slots["food_type"] = data.get('food_type')
|
| 53 |
+
if "descriptor" in data:
|
| 54 |
+
slots["descriptor"] = data.get('descriptor')
|
| 55 |
+
|
| 56 |
+
response="operated successfully"
|
| 57 |
+
query = {"intent":intent,"slots":slots}
|
| 58 |
+
if intent =="cooking_recipe":
|
| 59 |
+
if len(slots)==0:
|
| 60 |
+
response="which kind of food do you want to cook?"
|
| 61 |
+
else:
|
| 62 |
+
response="find 1 result. The recipe is : ...."
|
| 63 |
+
else:
|
| 64 |
+
response="not support intent"
|
| 65 |
+
print('耗时:' + str(time.time()-start_time))
|
| 66 |
+
print('----------------------')
|
| 67 |
+
return_dict = {}
|
| 68 |
+
return_dict['code'] = 'SUCCESS'
|
| 69 |
+
return_dict['msg'] = '成功'
|
| 70 |
+
contents = {}
|
| 71 |
+
contents['response'] = response
|
| 72 |
+
contents['query'] = query
|
| 73 |
+
return_dict['data'] = contents
|
| 74 |
+
return return_dict
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
print("模型load完毕")
|
| 78 |
+
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
print("启动开始---------")
|
| 81 |
+
port = sys.argv[1]
|
| 82 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 83 |
+
print("启动完成---------")
|
server/datetime_sev.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
|
| 24 |
+
datep=re.compile(r"202\d-\d\d-\d\d")
|
| 25 |
+
timep=re.compile(r"(202\d-\d\d-\d\d )*\d\d:\d\d[( am)|( pm)|( AM)|(( PM))]*")
|
| 26 |
+
@app.route("/datetime", methods=["GET", "POST"])
|
| 27 |
+
def check():
|
| 28 |
+
intent=""
|
| 29 |
+
slots=dict()
|
| 30 |
+
start_time = time.time()
|
| 31 |
+
if request.method == "POST":
|
| 32 |
+
jsondata = request.get_data(as_text=True)
|
| 33 |
+
if jsondata:
|
| 34 |
+
data = json.loads(jsondata)
|
| 35 |
+
print(data)
|
| 36 |
+
else:
|
| 37 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 38 |
+
return return_dict
|
| 39 |
+
params = ['intent', ]
|
| 40 |
+
for param in params:
|
| 41 |
+
if param not in data:
|
| 42 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 43 |
+
return return_dict
|
| 44 |
+
intent = data.get('intent')
|
| 45 |
+
#iid = str(data.get('iid'))
|
| 46 |
+
if "place_name" in data:
|
| 47 |
+
slots["place_name"] = data.get('place_name')
|
| 48 |
+
if "place_name2" in data:
|
| 49 |
+
slots["place_name2"] = data.get('place_name2')
|
| 50 |
+
if "descriptor" in data:
|
| 51 |
+
slots["descriptor"] = data.get('descriptor')
|
| 52 |
+
if "date" in data:
|
| 53 |
+
slots["date"] = data.get('date')
|
| 54 |
+
if "time" in data:
|
| 55 |
+
slots["time"] = data.get('time')
|
| 56 |
+
if "time2" in data:
|
| 57 |
+
slots["time2"] = data.get('time2')
|
| 58 |
+
if "time_zone" in data:
|
| 59 |
+
slots["time_zone"] = data.get('time_zone')
|
| 60 |
+
if "time_zone2" in data:
|
| 61 |
+
slots["time_zone2"] = data.get('time_zone2')
|
| 62 |
+
if request.method == "GET":
|
| 63 |
+
if "intent" in request.args:
|
| 64 |
+
intent = request.args.get("intent")
|
| 65 |
+
data=request.args
|
| 66 |
+
if "place_name" in data:
|
| 67 |
+
slots["place_name"] = data.get('place_name')
|
| 68 |
+
if "place_name2" in data:
|
| 69 |
+
slots["place_name2"] = data.get('place_name2')
|
| 70 |
+
if "descriptor" in data:
|
| 71 |
+
slots["descriptor"] = data.get('descriptor')
|
| 72 |
+
if "date" in data:
|
| 73 |
+
slots["date"] = data.get('date')
|
| 74 |
+
if "time" in data:
|
| 75 |
+
slots["time"] = data.get('time')
|
| 76 |
+
if "time2" in data:
|
| 77 |
+
slots["time2"] = data.get('time2')
|
| 78 |
+
if "time_zone" in data:
|
| 79 |
+
slots["time_zone"] = data.get('time_zone')
|
| 80 |
+
if "time_zone2" in data:
|
| 81 |
+
slots["time_zone2"] = data.get('time_zone2')
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
response="operated successfully"
|
| 85 |
+
query = {"intent":intent,"slots":slots}
|
| 86 |
+
if intent =="datetime_query":
|
| 87 |
+
if len(slots)==0:
|
| 88 |
+
response="Today is ...."
|
| 89 |
+
else:
|
| 90 |
+
response="The date and time is ...."
|
| 91 |
+
elif intent =="datetime_convert":
|
| 92 |
+
if "place_name" not in slots and "place_name2" not in slots and "time_zone" not in slots and "time_zone2" not in slots:
|
| 93 |
+
response="which time zone you want to convert to?"
|
| 94 |
+
else:
|
| 95 |
+
response="the time is ...."
|
| 96 |
+
else:
|
| 97 |
+
response="not supporting intent"
|
| 98 |
+
for key,value in slots.items() :
|
| 99 |
+
if key=="time" or key=="time2":
|
| 100 |
+
if timep.match(value) is None:
|
| 101 |
+
response="time format not right"
|
| 102 |
+
if key.find("date")!=-1:
|
| 103 |
+
if datep.match(value) is None:
|
| 104 |
+
response="date format not right"
|
| 105 |
+
print('耗时:' + str(time.time()-start_time))
|
| 106 |
+
print('----------------------')
|
| 107 |
+
return_dict = {}
|
| 108 |
+
return_dict['code'] = 'SUCCESS'
|
| 109 |
+
return_dict['msg'] = '成功'
|
| 110 |
+
contents = {}
|
| 111 |
+
contents['response'] = response
|
| 112 |
+
contents['query'] = query
|
| 113 |
+
return_dict['data'] = contents
|
| 114 |
+
return return_dict
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
print("模型load完毕")
|
| 118 |
+
|
| 119 |
+
if __name__ == "__main__":
|
| 120 |
+
print("启动开始---------")
|
| 121 |
+
port = sys.argv[1]
|
| 122 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 123 |
+
print("启动完成---------")
|
server/email_sev.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
|
| 24 |
+
datep=re.compile(r"202\d-\d\d-\d\d")
|
| 25 |
+
timep=re.compile(r"(202\d-\d\d-\d\d )*\d\d:\d\d[( am)|( pm)|( AM)|(( PM))]*")
|
| 26 |
+
@app.route("/email", methods=["GET", "POST"])
|
| 27 |
+
def check():
|
| 28 |
+
intent=""
|
| 29 |
+
slots=dict()
|
| 30 |
+
start_time = time.time()
|
| 31 |
+
if request.method == "POST":
|
| 32 |
+
jsondata = request.get_data(as_text=True)
|
| 33 |
+
if jsondata:
|
| 34 |
+
data = json.loads(jsondata)
|
| 35 |
+
print(data)
|
| 36 |
+
else:
|
| 37 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 38 |
+
return return_dict
|
| 39 |
+
params = ['intent', ]
|
| 40 |
+
for param in params:
|
| 41 |
+
if param not in data:
|
| 42 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 43 |
+
return return_dict
|
| 44 |
+
intent = data.get('intent')
|
| 45 |
+
#iid = str(data.get('iid'))
|
| 46 |
+
if "setting" in data:
|
| 47 |
+
slots["setting"] = data.get('setting')
|
| 48 |
+
if "descriptor" in data:
|
| 49 |
+
slots["descriptor"] = data.get('descriptor')
|
| 50 |
+
if "person" in data:
|
| 51 |
+
slots["person"] = data.get('person')
|
| 52 |
+
if "to_person" in data:
|
| 53 |
+
slots["to_person"] = data.get('to_person')
|
| 54 |
+
if "from_person" in data:
|
| 55 |
+
slots["from_person"] = data.get('from_person')
|
| 56 |
+
if "relation" in data:
|
| 57 |
+
slots["relation"] = data.get('relation')
|
| 58 |
+
if "to_relation" in data:
|
| 59 |
+
slots["to_relation"] = data.get('to_relation')
|
| 60 |
+
if "from_relation" in data:
|
| 61 |
+
slots["from_relation"] = data.get('from_relation')
|
| 62 |
+
if "email_folder" in data:
|
| 63 |
+
slots["email_folder"] = data.get('email_folder')
|
| 64 |
+
if "content" in data:
|
| 65 |
+
slots["content"] = data.get('content')
|
| 66 |
+
if "time" in data:
|
| 67 |
+
slots["time"] = data.get('time')
|
| 68 |
+
if "date" in data:
|
| 69 |
+
slots["date"] = data.get('date')
|
| 70 |
+
if "email_address" in data:
|
| 71 |
+
slots["email_address"] = data.get('email_address')
|
| 72 |
+
if "app_name" in data:
|
| 73 |
+
slots["app_name"] = data.get('app_name')
|
| 74 |
+
if "query" in data:
|
| 75 |
+
slots["query"] = data.get('query')
|
| 76 |
+
if "personal_info" in data:
|
| 77 |
+
slots["personal_info"] = data.get('personal_info')
|
| 78 |
+
if request.method == "GET":
|
| 79 |
+
if "intent" in request.args:
|
| 80 |
+
intent = request.args.get("intent")
|
| 81 |
+
data=request.args
|
| 82 |
+
if "setting" in data:
|
| 83 |
+
slots["setting"] = data.get('setting')
|
| 84 |
+
if "descriptor" in data:
|
| 85 |
+
slots["descriptor"] = data.get('descriptor')
|
| 86 |
+
if "person" in data:
|
| 87 |
+
slots["person"] = data.get('person')
|
| 88 |
+
if "to_person" in data:
|
| 89 |
+
slots["to_person"] = data.get('to_person')
|
| 90 |
+
if "from_person" in data:
|
| 91 |
+
slots["from_person"] = data.get('from_person')
|
| 92 |
+
if "relation" in data:
|
| 93 |
+
slots["relation"] = data.get('relation')
|
| 94 |
+
if "to_relation" in data:
|
| 95 |
+
slots["to_relation"] = data.get('to_relation')
|
| 96 |
+
if "from_relation" in data:
|
| 97 |
+
slots["from_relation"] = data.get('from_relation')
|
| 98 |
+
if "email_folder" in data:
|
| 99 |
+
slots["email_folder"] = data.get('email_folder')
|
| 100 |
+
if "content" in data:
|
| 101 |
+
slots["content"] = data.get('content')
|
| 102 |
+
if "time" in data:
|
| 103 |
+
slots["time"] = data.get('time')
|
| 104 |
+
if "date" in data:
|
| 105 |
+
slots["date"] = data.get('date')
|
| 106 |
+
if "email_address" in data:
|
| 107 |
+
slots["email_address"] = data.get('email_address')
|
| 108 |
+
if "app_name" in data:
|
| 109 |
+
slots["app_name"] = data.get('app_name')
|
| 110 |
+
if "query" in data:
|
| 111 |
+
slots["query"] = data.get('query')
|
| 112 |
+
if "personal_info" in data:
|
| 113 |
+
slots["personal_info"] = data.get('personal_info')
|
| 114 |
+
|
| 115 |
+
response="operated successfully"
|
| 116 |
+
query = {"intent":intent,"slots":slots}
|
| 117 |
+
if intent=="email_sendemail":
|
| 118 |
+
if "to_person" not in slots and "person" not in slots and "relation" not in slots and "to_relation" not in slots:
|
| 119 |
+
response="need provide the recipient."
|
| 120 |
+
elif intent=="email_addcontact":
|
| 121 |
+
if "email_address" not in slots:
|
| 122 |
+
response="need provide email address."
|
| 123 |
+
elif intent=="email_query":
|
| 124 |
+
if len(slots)==0:
|
| 125 |
+
response="what kind of email do you want to search for?"
|
| 126 |
+
else:
|
| 127 |
+
response="find 1 result. email index: 12, email content: hi, how's going?...."
|
| 128 |
+
elif intent=="email_querycontact":
|
| 129 |
+
response="find 1 result. the contact index: 8, information is: name...."
|
| 130 |
+
elif intent=="email_subscription":
|
| 131 |
+
if len(slots)==0:
|
| 132 |
+
response="what kind of email do you want me to watch?"
|
| 133 |
+
elif intent=="email_remove":
|
| 134 |
+
if len(slots)==0:
|
| 135 |
+
response="what kind of email do you want to delete?"
|
| 136 |
+
else:
|
| 137 |
+
response="not supporting intent"
|
| 138 |
+
for key,value in slots.items() :
|
| 139 |
+
if key=="time":
|
| 140 |
+
if timep.match(value) is None:
|
| 141 |
+
response="time format not right"
|
| 142 |
+
if key.find("date")!=-1:
|
| 143 |
+
if datep.match(value) is None:
|
| 144 |
+
response="date format not right"
|
| 145 |
+
print('耗时:' + str(time.time()-start_time))
|
| 146 |
+
print('----------------------')
|
| 147 |
+
return_dict = {}
|
| 148 |
+
return_dict['code'] = 'SUCCESS'
|
| 149 |
+
return_dict['msg'] = '成功'
|
| 150 |
+
contents = {}
|
| 151 |
+
contents['response'] = response
|
| 152 |
+
contents['query'] = query
|
| 153 |
+
return_dict['data'] = contents
|
| 154 |
+
return return_dict
|
| 155 |
+
|
| 156 |
+
print("模型load完毕")
|
| 157 |
+
|
| 158 |
+
if __name__ == "__main__":
|
| 159 |
+
print("启动开始---------")
|
| 160 |
+
port = sys.argv[1]
|
| 161 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 162 |
+
print("启动完成---------")
|
server/game_sev.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
app=Flask(__name__)
|
| 9 |
+
|
| 10 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 11 |
+
queries = dict()
|
| 12 |
+
with open(file_path ) as f:
|
| 13 |
+
lines=f.readlines()
|
| 14 |
+
count=0
|
| 15 |
+
for line in lines:
|
| 16 |
+
line=line.strip()
|
| 17 |
+
query=json.loads(line)
|
| 18 |
+
if query['domain']==domain:
|
| 19 |
+
queries[query["iid"]]=query
|
| 20 |
+
|
| 21 |
+
return queries
|
| 22 |
+
|
| 23 |
+
@app.route("/game", methods=["GET", "POST"])
|
| 24 |
+
def check():
|
| 25 |
+
intent=""
|
| 26 |
+
slots=dict()
|
| 27 |
+
start_time = time.time()
|
| 28 |
+
if request.method == "POST":
|
| 29 |
+
jsondata = request.get_data(as_text=True)
|
| 30 |
+
if jsondata:
|
| 31 |
+
data = json.loads(jsondata)
|
| 32 |
+
print(data)
|
| 33 |
+
else:
|
| 34 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 35 |
+
return return_dict
|
| 36 |
+
params = ['intent', ]
|
| 37 |
+
for param in params:
|
| 38 |
+
if param not in data:
|
| 39 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 40 |
+
return return_dict
|
| 41 |
+
intent = data.get('intent')
|
| 42 |
+
#iid = str(data.get('iid'))
|
| 43 |
+
if "game_name" in data:
|
| 44 |
+
slots["game_name"] = data.get('game_name')
|
| 45 |
+
if request.method == "GET":
|
| 46 |
+
if "intent" in request.args:
|
| 47 |
+
intent = request.args.get("intent")
|
| 48 |
+
data=request.args
|
| 49 |
+
if "game_name" in data:
|
| 50 |
+
slots["game_name"] = data.get('game_name')
|
| 51 |
+
|
| 52 |
+
response="operated successfully"
|
| 53 |
+
query = {"intent":intent,"slots":slots}
|
| 54 |
+
if intent=="play_game":
|
| 55 |
+
if len(slots)==0:
|
| 56 |
+
response="which game do you want to play?"
|
| 57 |
+
else:
|
| 58 |
+
response="not supporting intent"
|
| 59 |
+
print('耗时:' + str(time.time()-start_time))
|
| 60 |
+
print('----------------------')
|
| 61 |
+
return_dict = {}
|
| 62 |
+
return_dict['code'] = 'SUCCESS'
|
| 63 |
+
return_dict['msg'] = '成功'
|
| 64 |
+
contents = {}
|
| 65 |
+
contents['response'] = response
|
| 66 |
+
contents['query'] = query
|
| 67 |
+
return_dict['data'] = contents
|
| 68 |
+
return return_dict
|
| 69 |
+
|
| 70 |
+
print("模型load完毕")
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
print("启动开始---------")
|
| 74 |
+
port = sys.argv[1]
|
| 75 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 76 |
+
print("启动完成---------")
|
server/iot_sev.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
import time
|
| 7 |
+
import csv
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
|
| 24 |
+
timep=re.compile(r"\d\d:\d\d[( am)|( pm)|( AM)|(( PM))]*")
|
| 25 |
+
@app.route("/iot", methods=["GET", "POST"])
|
| 26 |
+
def check():
|
| 27 |
+
intent=""
|
| 28 |
+
slots=dict()
|
| 29 |
+
start_time = time.time()
|
| 30 |
+
if request.method == "POST":
|
| 31 |
+
jsondata = request.get_data(as_text=True)
|
| 32 |
+
if jsondata:
|
| 33 |
+
data = json.loads(jsondata)
|
| 34 |
+
print(data)
|
| 35 |
+
else:
|
| 36 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 37 |
+
return return_dict
|
| 38 |
+
params = ['intent', ]
|
| 39 |
+
for param in params:
|
| 40 |
+
if param not in data:
|
| 41 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 42 |
+
return return_dict
|
| 43 |
+
intent = data.get('intent')
|
| 44 |
+
#iid = str(data.get('iid'))
|
| 45 |
+
if "device_type" in data:
|
| 46 |
+
slots["device_type"] = data.get('device_type')
|
| 47 |
+
if "house_place" in data:
|
| 48 |
+
slots["house_place"] = data.get('house_place')
|
| 49 |
+
if "change_amount" in data:
|
| 50 |
+
slots["change_amount"] = data.get('change_amount')
|
| 51 |
+
if "change_to" in data:
|
| 52 |
+
slots["change_to"] = data.get('change_to')
|
| 53 |
+
if "color_type" in data:
|
| 54 |
+
slots["color_type"] = data.get('color_type')
|
| 55 |
+
if "item_name" in data:
|
| 56 |
+
slots["item_name"] = data.get('item_name')
|
| 57 |
+
if "setting" in data:
|
| 58 |
+
slots["setting"] = data.get('setting')
|
| 59 |
+
if "time" in data:
|
| 60 |
+
slots["time"] = data.get('time')
|
| 61 |
+
if request.method == "GET":
|
| 62 |
+
if "intent" in request.args:
|
| 63 |
+
intent = request.args.get("intent")
|
| 64 |
+
data=request.args
|
| 65 |
+
if "device_type" in data:
|
| 66 |
+
slots["device_type"] = data.get('device_type')
|
| 67 |
+
if "house_place" in data:
|
| 68 |
+
slots["house_place"] = data.get('house_place')
|
| 69 |
+
if "change_amount" in data:
|
| 70 |
+
slots["change_amount"] = data.get('change_amount')
|
| 71 |
+
if "change_to" in data:
|
| 72 |
+
slots["change_to"] = data.get('change_to')
|
| 73 |
+
if "color_type" in data:
|
| 74 |
+
slots["color_type"] = data.get('color_type')
|
| 75 |
+
if "item_name" in data:
|
| 76 |
+
slots["item_name"] = data.get('item_name')
|
| 77 |
+
if "setting" in data:
|
| 78 |
+
slots["setting"] = data.get('setting')
|
| 79 |
+
if "time" in data:
|
| 80 |
+
slots["time"] = data.get('time')
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
response="operated successfully"
|
| 84 |
+
query = {"intent":intent,"slots":slots}
|
| 85 |
+
if intent =="iot_hue_lightcolor":
|
| 86 |
+
pass
|
| 87 |
+
elif intent =="iot_coffee" or intent =="audio_volume_mute" or intent =="iot_hue_lightoff" or intent =="iot_wemo_off" or intent =="iot_cleaning" or intent =="iot_wemo_on":
|
| 88 |
+
pass
|
| 89 |
+
elif intent=="iot_hue_lightdim" or intent=="iot_hue_lightup":
|
| 90 |
+
if "change_amount" not in slots:
|
| 91 |
+
response="change the lights with default amount."
|
| 92 |
+
elif intent=="iot_hue_lightchange":
|
| 93 |
+
if "change_to" not in slots:
|
| 94 |
+
response="change the lights to default."
|
| 95 |
+
elif intent=="audio_volume_up" or intent=="audio_volume_down":
|
| 96 |
+
if "change_amount" not in slots:
|
| 97 |
+
response="change the volume with default amount."
|
| 98 |
+
elif intent =="audio_volume_other":
|
| 99 |
+
if "change_to" not in slots:
|
| 100 |
+
response="change the volume to default."
|
| 101 |
+
else:
|
| 102 |
+
response="not supporting intent"
|
| 103 |
+
for key,value in slots.items() :
|
| 104 |
+
if key.find("time")!=-1:
|
| 105 |
+
if timep.match(value) is None:
|
| 106 |
+
response="time format not right"
|
| 107 |
+
print('耗时:' + str(time.time()-start_time))
|
| 108 |
+
print('----------------------')
|
| 109 |
+
return_dict = {}
|
| 110 |
+
return_dict['code'] = 'SUCCESS'
|
| 111 |
+
return_dict['msg'] = '成功'
|
| 112 |
+
contents = {}
|
| 113 |
+
contents['response'] = response
|
| 114 |
+
contents['query'] = query
|
| 115 |
+
return_dict['data'] = contents
|
| 116 |
+
return return_dict
|
| 117 |
+
|
| 118 |
+
print("模型load完毕")
|
| 119 |
+
|
| 120 |
+
if __name__ == "__main__":
|
| 121 |
+
print("启动开始---------")
|
| 122 |
+
port = sys.argv[1]
|
| 123 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 124 |
+
print("启动完成---------")
|
server/lists_sev.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
|
| 24 |
+
datep=re.compile(r"202\d-\d\d-\d\d")
|
| 25 |
+
timep=re.compile(r"(202\d-\d\d-\d\d )*\d\d:\d\d[( am)|( pm)|( AM)|(( PM))]*")
|
| 26 |
+
@app.route("/lists", methods=["GET", "POST"])
|
| 27 |
+
def check():
|
| 28 |
+
intent=""
|
| 29 |
+
slots=dict()
|
| 30 |
+
start_time = time.time()
|
| 31 |
+
if request.method == "POST":
|
| 32 |
+
jsondata = request.get_data(as_text=True)
|
| 33 |
+
if jsondata:
|
| 34 |
+
data = json.loads(jsondata)
|
| 35 |
+
print(data)
|
| 36 |
+
else:
|
| 37 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 38 |
+
return return_dict
|
| 39 |
+
params = ['intent', ]
|
| 40 |
+
for param in params:
|
| 41 |
+
if param not in data:
|
| 42 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 43 |
+
return return_dict
|
| 44 |
+
intent = data.get('intent')
|
| 45 |
+
#iid = str(data.get('iid'))
|
| 46 |
+
if "list_name" in data:
|
| 47 |
+
slots["list_name"] = data.get('list_name')
|
| 48 |
+
if "item_name" in data:
|
| 49 |
+
slots["item_name"] = data.get('item_name')
|
| 50 |
+
if "date" in data:
|
| 51 |
+
slots["date"] = data.get('date')
|
| 52 |
+
if "time" in data:
|
| 53 |
+
slots["time"] = data.get('time')
|
| 54 |
+
if "timeofday" in data:
|
| 55 |
+
slots["timeofday"] = data.get('timeofday')
|
| 56 |
+
if "descriptor" in data:
|
| 57 |
+
slots["descriptor"] = data.get('descriptor')
|
| 58 |
+
if request.method == "GET":
|
| 59 |
+
if "intent" in request.args:
|
| 60 |
+
intent = request.args.get("intent")
|
| 61 |
+
data=request.args
|
| 62 |
+
if "list_name" in data:
|
| 63 |
+
slots["list_name"] = data.get('list_name')
|
| 64 |
+
if "item_name" in data:
|
| 65 |
+
slots["item_name"] = data.get('item_name')
|
| 66 |
+
if "date" in data:
|
| 67 |
+
slots["date"] = data.get('date')
|
| 68 |
+
if "time" in data:
|
| 69 |
+
slots["time"] = data.get('time')
|
| 70 |
+
if "timeofday" in data:
|
| 71 |
+
slots["timeofday"] = data.get('timeofday')
|
| 72 |
+
if "descriptor" in data:
|
| 73 |
+
slots["descriptor"] = data.get('descriptor')
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
response="operated successfully"
|
| 77 |
+
query = {"intent":intent,"slots":slots}
|
| 78 |
+
if intent =="lists_query":
|
| 79 |
+
if len(slots)==0:
|
| 80 |
+
response="all the lists are listed here. list 1: ...."
|
| 81 |
+
else:
|
| 82 |
+
response="find 1 result. list index: 10, content: ...."
|
| 83 |
+
elif intent=="lists_remove":
|
| 84 |
+
if len(slots)==0:
|
| 85 |
+
response="do you want to delete all the lists?"
|
| 86 |
+
elif intent=="lists_createoradd":
|
| 87 |
+
if len(slots)==0:
|
| 88 |
+
response="what's the list name?"
|
| 89 |
+
else:
|
| 90 |
+
response="unsupported intent"
|
| 91 |
+
for key,value in slots.items() :
|
| 92 |
+
if key.find("time")!=-1:
|
| 93 |
+
if timep.match(value) is None:
|
| 94 |
+
response="time format not right"
|
| 95 |
+
if key.find("date")!=-1:
|
| 96 |
+
if datep.match(value) is None:
|
| 97 |
+
response="date format not right"
|
| 98 |
+
print('耗时:' + str(time.time()-start_time))
|
| 99 |
+
print('----------------------')
|
| 100 |
+
return_dict = {}
|
| 101 |
+
return_dict['code'] = 'SUCCESS'
|
| 102 |
+
return_dict['msg'] = '成功'
|
| 103 |
+
contents = {}
|
| 104 |
+
contents['response'] = response
|
| 105 |
+
contents['query'] = query
|
| 106 |
+
return_dict['data'] = contents
|
| 107 |
+
return return_dict
|
| 108 |
+
|
| 109 |
+
print("模型load完毕")
|
| 110 |
+
|
| 111 |
+
if __name__ == "__main__":
|
| 112 |
+
print("启动开始---------")
|
| 113 |
+
port = sys.argv[1]
|
| 114 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 115 |
+
print("启动完成---------")
|
server/music_sev.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
app=Flask(__name__)
|
| 9 |
+
|
| 10 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 11 |
+
queries = dict()
|
| 12 |
+
with open(file_path ) as f:
|
| 13 |
+
lines=f.readlines()
|
| 14 |
+
count=0
|
| 15 |
+
for line in lines:
|
| 16 |
+
line=line.strip()
|
| 17 |
+
query=json.loads(line)
|
| 18 |
+
if query['domain']==domain:
|
| 19 |
+
queries[query["iid"]]=query
|
| 20 |
+
|
| 21 |
+
return queries
|
| 22 |
+
|
| 23 |
+
@app.route("/music", methods=["GET", "POST"])
|
| 24 |
+
def check():
|
| 25 |
+
intent=""
|
| 26 |
+
slots=dict()
|
| 27 |
+
start_time = time.time()
|
| 28 |
+
if request.method == "POST":
|
| 29 |
+
jsondata = request.get_data(as_text=True)
|
| 30 |
+
if jsondata:
|
| 31 |
+
data = json.loads(jsondata)
|
| 32 |
+
print(data)
|
| 33 |
+
else:
|
| 34 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 35 |
+
return return_dict
|
| 36 |
+
params = ['intent', ]
|
| 37 |
+
for param in params:
|
| 38 |
+
if param not in data:
|
| 39 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 40 |
+
return return_dict
|
| 41 |
+
intent = data.get('intent')
|
| 42 |
+
#iid = str(data.get('iid'))
|
| 43 |
+
if "player_setting" in data:
|
| 44 |
+
slots["player_setting"] = data.get('player_setting')
|
| 45 |
+
if "descriptor" in data:
|
| 46 |
+
slots["descriptor"] = data.get('descriptor')
|
| 47 |
+
if "playlist_name" in data:
|
| 48 |
+
slots["playlist_name"] = data.get('playlist_name')
|
| 49 |
+
if "artist_name" in data:
|
| 50 |
+
slots["artist_name"] = data.get('artist_name')
|
| 51 |
+
if "song_name" in data:
|
| 52 |
+
slots["song_name"] = data.get('song_name')
|
| 53 |
+
if "music_genre" in data:
|
| 54 |
+
slots["music_genre"] = data.get('music_genre')
|
| 55 |
+
if "query" in data:
|
| 56 |
+
slots["query"] = data.get('query')
|
| 57 |
+
if request.method == "GET":
|
| 58 |
+
if "intent" in request.args:
|
| 59 |
+
intent = request.args.get("intent")
|
| 60 |
+
data=request.args
|
| 61 |
+
if "player_setting" in data:
|
| 62 |
+
slots["player_setting"] = data.get('player_setting')
|
| 63 |
+
if "descriptor" in data:
|
| 64 |
+
slots["descriptor"] = data.get('descriptor')
|
| 65 |
+
if "playlist_name" in data:
|
| 66 |
+
slots["playlist_name"] = data.get('playlist_name')
|
| 67 |
+
if "artist_name" in data:
|
| 68 |
+
slots["artist_name"] = data.get('artist_name')
|
| 69 |
+
if "song_name" in data:
|
| 70 |
+
slots["song_name"] = data.get('song_name')
|
| 71 |
+
if "music_genre" in data:
|
| 72 |
+
slots["music_genre"] = data.get('music_genre')
|
| 73 |
+
if "query" in data:
|
| 74 |
+
slots["query"] = data.get('query')
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
response="operated successfully"
|
| 78 |
+
query = {"intent":intent,"slots":slots}
|
| 79 |
+
if intent =="play_music":
|
| 80 |
+
if len(slots)==0:
|
| 81 |
+
response="play random music."
|
| 82 |
+
elif intent =="music_likeness" or intent=="music_dislikeness":
|
| 83 |
+
pass
|
| 84 |
+
elif intent=="music_query":
|
| 85 |
+
response="The song name is Imagine, it belongs to album Imagine, and the artist name is John Lennon."
|
| 86 |
+
elif intent=="playlists_createoradd":
|
| 87 |
+
if len(slots)==0:
|
| 88 |
+
response="which song do you want to put in this playlist?"
|
| 89 |
+
elif intent=="music_settings":
|
| 90 |
+
if len(slots)==0:
|
| 91 |
+
response="How do you want to set the music?"
|
| 92 |
+
else:
|
| 93 |
+
response="unsupported intent"
|
| 94 |
+
print('耗时:' + str(time.time()-start_time))
|
| 95 |
+
print('----------------------')
|
| 96 |
+
return_dict = {}
|
| 97 |
+
return_dict['code'] = 'SUCCESS'
|
| 98 |
+
return_dict['msg'] = '成功'
|
| 99 |
+
contents = {}
|
| 100 |
+
contents['response'] = response
|
| 101 |
+
contents['query'] = query
|
| 102 |
+
return_dict['data'] = contents
|
| 103 |
+
return return_dict
|
| 104 |
+
|
| 105 |
+
print("模型load完毕")
|
| 106 |
+
|
| 107 |
+
if __name__ == "__main__":
|
| 108 |
+
print("启动开始---------")
|
| 109 |
+
port = sys.argv[1]
|
| 110 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 111 |
+
print("启动完成---------")
|
server/news_sev.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
app=Flask(__name__)
|
| 9 |
+
|
| 10 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 11 |
+
queries = dict()
|
| 12 |
+
with open(file_path ) as f:
|
| 13 |
+
lines=f.readlines()
|
| 14 |
+
count=0
|
| 15 |
+
for line in lines:
|
| 16 |
+
line=line.strip()
|
| 17 |
+
query=json.loads(line)
|
| 18 |
+
if query['domain']==domain:
|
| 19 |
+
queries[query["iid"]]=query
|
| 20 |
+
|
| 21 |
+
return queries
|
| 22 |
+
|
| 23 |
+
@app.route("/news", methods=["GET", "POST"])
|
| 24 |
+
def check():
|
| 25 |
+
intent=""
|
| 26 |
+
slots=dict()
|
| 27 |
+
start_time = time.time()
|
| 28 |
+
if request.method == "POST":
|
| 29 |
+
jsondata = request.get_data(as_text=True)
|
| 30 |
+
if jsondata:
|
| 31 |
+
data = json.loads(jsondata)
|
| 32 |
+
print(data)
|
| 33 |
+
else:
|
| 34 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 35 |
+
return return_dict
|
| 36 |
+
params = ['intent', ]
|
| 37 |
+
for param in params:
|
| 38 |
+
if param not in data:
|
| 39 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 40 |
+
return return_dict
|
| 41 |
+
intent = data.get('intent')
|
| 42 |
+
#iid = str(data.get('iid'))
|
| 43 |
+
if "news_topic" in data:
|
| 44 |
+
slots["news_topic"] = data.get('news_topic')
|
| 45 |
+
if "media_type" in data:
|
| 46 |
+
slots["media_type"] = data.get('media_type')
|
| 47 |
+
if "descriptor" in data:
|
| 48 |
+
slots["descriptor"] = data.get('descriptor')
|
| 49 |
+
if "date" in data:
|
| 50 |
+
slots["date"] = data.get('date')
|
| 51 |
+
if "timeofday" in data:
|
| 52 |
+
slots["timeofday"] = data.get('timeofday')
|
| 53 |
+
if "place_name" in data:
|
| 54 |
+
slots["place_name"] = data.get('place_name')
|
| 55 |
+
if request.method == "GET":
|
| 56 |
+
if "intent" in request.args:
|
| 57 |
+
intent = request.args.get("intent")
|
| 58 |
+
data=request.args
|
| 59 |
+
if "news_topic" in data:
|
| 60 |
+
slots["news_topic"] = data.get('news_topic')
|
| 61 |
+
if "media_type" in data:
|
| 62 |
+
slots["media_type"] = data.get('media_type')
|
| 63 |
+
if "descriptor" in data:
|
| 64 |
+
slots["descriptor"] = data.get('descriptor')
|
| 65 |
+
if "date" in data:
|
| 66 |
+
slots["date"] = data.get('date')
|
| 67 |
+
if "timeofday" in data:
|
| 68 |
+
slots["timeofday"] = data.get('timeofday')
|
| 69 |
+
if "place_name" in data:
|
| 70 |
+
slots["place_name"] = data.get('place_name')
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
response="operated successfully"
|
| 74 |
+
query = {"intent":intent,"slots":slots}
|
| 75 |
+
if intent == "news_subscription":
|
| 76 |
+
if len(slots)==0:
|
| 77 |
+
response="what kinds of news do you want to subscribe?"
|
| 78 |
+
else:
|
| 79 |
+
response="unsupported intent"
|
| 80 |
+
print('耗时:' + str(time.time()-start_time))
|
| 81 |
+
print('----------------------')
|
| 82 |
+
return_dict = {}
|
| 83 |
+
return_dict['code'] = 'SUCCESS'
|
| 84 |
+
return_dict['msg'] = '成功'
|
| 85 |
+
contents = {}
|
| 86 |
+
contents['response'] = response
|
| 87 |
+
contents['query'] = query
|
| 88 |
+
return_dict['data'] = contents
|
| 89 |
+
return return_dict
|
| 90 |
+
|
| 91 |
+
print("模型load完毕")
|
| 92 |
+
|
| 93 |
+
if __name__ == "__main__":
|
| 94 |
+
print("启动开始---------")
|
| 95 |
+
port = sys.argv[1]
|
| 96 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 97 |
+
print("启动完成---------")
|
server/phone_sev.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
app=Flask(__name__)
|
| 9 |
+
|
| 10 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 11 |
+
queries = dict()
|
| 12 |
+
with open(file_path ) as f:
|
| 13 |
+
lines=f.readlines()
|
| 14 |
+
count=0
|
| 15 |
+
for line in lines:
|
| 16 |
+
line=line.strip()
|
| 17 |
+
query=json.loads(line)
|
| 18 |
+
if query['domain']==domain:
|
| 19 |
+
queries[query["iid"]]=query
|
| 20 |
+
|
| 21 |
+
return queries
|
| 22 |
+
|
| 23 |
+
@app.route("/phone", methods=["GET", "POST"])
|
| 24 |
+
def check():
|
| 25 |
+
intent=""
|
| 26 |
+
slots=dict()
|
| 27 |
+
start_time = time.time()
|
| 28 |
+
if request.method == "POST":
|
| 29 |
+
jsondata = request.get_data(as_text=True)
|
| 30 |
+
if jsondata:
|
| 31 |
+
data = json.loads(jsondata)
|
| 32 |
+
print(data)
|
| 33 |
+
else:
|
| 34 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 35 |
+
return return_dict
|
| 36 |
+
params = ['intent', ]
|
| 37 |
+
for param in params:
|
| 38 |
+
if param not in data:
|
| 39 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 40 |
+
return return_dict
|
| 41 |
+
intent = data.get('intent')
|
| 42 |
+
#iid = str(data.get('iid'))
|
| 43 |
+
if "device_type" in data:
|
| 44 |
+
slots["device_type"] = data.get('device_type')
|
| 45 |
+
if "text" in data:
|
| 46 |
+
slots["text"] = data.get('text')
|
| 47 |
+
if "event_name" in data:
|
| 48 |
+
slots["event_name"] = data.get('event_name')
|
| 49 |
+
if request.method == "GET":
|
| 50 |
+
if "intent" in request.args:
|
| 51 |
+
intent = request.args.get("intent")
|
| 52 |
+
data=request.args
|
| 53 |
+
if "device_type" in data:
|
| 54 |
+
slots["device_type"] = data.get('device_type')
|
| 55 |
+
if "text" in data:
|
| 56 |
+
slots["text"] = data.get('text')
|
| 57 |
+
if "event_name" in data:
|
| 58 |
+
slots["event_name"] = data.get('event_name')
|
| 59 |
+
|
| 60 |
+
response="operated successfully"
|
| 61 |
+
query = {"intent":intent,"slots":slots}
|
| 62 |
+
if intent =="phone_text":
|
| 63 |
+
if "text" not in slots:
|
| 64 |
+
response="what do you want to text?"
|
| 65 |
+
elif intent =="phone_notification":
|
| 66 |
+
if "event_name" not in slots:
|
| 67 |
+
response="what event do you want to watch?"
|
| 68 |
+
else:
|
| 69 |
+
response="unsupported intent."
|
| 70 |
+
print('耗时:' + str(time.time()-start_time))
|
| 71 |
+
print('----------------------')
|
| 72 |
+
return_dict = {}
|
| 73 |
+
return_dict['code'] = 'SUCCESS'
|
| 74 |
+
return_dict['msg'] = '成功'
|
| 75 |
+
contents = {}
|
| 76 |
+
contents['response'] = response
|
| 77 |
+
contents['query'] = query
|
| 78 |
+
return_dict['data'] = contents
|
| 79 |
+
return return_dict
|
| 80 |
+
|
| 81 |
+
print("模型load完毕")
|
| 82 |
+
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
print("启动开始---------")
|
| 85 |
+
port = sys.argv[1]
|
| 86 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 87 |
+
print("启动完成---------")
|
server/podcasts_sev.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
app=Flask(__name__)
|
| 9 |
+
|
| 10 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 11 |
+
queries = dict()
|
| 12 |
+
with open(file_path ) as f:
|
| 13 |
+
lines=f.readlines()
|
| 14 |
+
count=0
|
| 15 |
+
for line in lines:
|
| 16 |
+
line=line.strip()
|
| 17 |
+
query=json.loads(line)
|
| 18 |
+
if query['domain']==domain:
|
| 19 |
+
queries[query["iid"]]=query
|
| 20 |
+
|
| 21 |
+
return queries
|
| 22 |
+
|
| 23 |
+
@app.route("/podcasts", methods=["GET", "POST"])
|
| 24 |
+
def check():
|
| 25 |
+
intent=""
|
| 26 |
+
slots=dict()
|
| 27 |
+
start_time = time.time()
|
| 28 |
+
if request.method == "POST":
|
| 29 |
+
jsondata = request.get_data(as_text=True)
|
| 30 |
+
if jsondata:
|
| 31 |
+
data = json.loads(jsondata)
|
| 32 |
+
print(data)
|
| 33 |
+
else:
|
| 34 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 35 |
+
return return_dict
|
| 36 |
+
params = ['intent', ]
|
| 37 |
+
for param in params:
|
| 38 |
+
if param not in data:
|
| 39 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 40 |
+
return return_dict
|
| 41 |
+
intent = data.get('intent')
|
| 42 |
+
#iid = str(data.get('iid'))
|
| 43 |
+
if "podcast_name" in data:
|
| 44 |
+
slots["podcast_name"] = data.get('podcast_name')
|
| 45 |
+
if "player_setting" in data:
|
| 46 |
+
slots["player_setting"] = data.get('player_setting')
|
| 47 |
+
if "podcast_descriptor" in data:
|
| 48 |
+
slots["podcast_descriptor"] = data.get('podcast_descriptor')
|
| 49 |
+
if request.method == "GET":
|
| 50 |
+
if "intent" in request.args:
|
| 51 |
+
intent = request.args.get("intent")
|
| 52 |
+
data=request.args
|
| 53 |
+
if "podcast_name" in data:
|
| 54 |
+
slots["podcast_name"] = data.get('podcast_name')
|
| 55 |
+
if "player_setting" in data:
|
| 56 |
+
slots["player_setting"] = data.get('player_setting')
|
| 57 |
+
if "podcast_descriptor" in data:
|
| 58 |
+
slots["podcast_descriptor"] = data.get('podcast_descriptor')
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
response="operated successfully"
|
| 62 |
+
query = {"intent":intent,"slots":slots}
|
| 63 |
+
if intent=="play_podcasts":
|
| 64 |
+
if len(slots)==0:
|
| 65 |
+
response="play random podcast."
|
| 66 |
+
else:
|
| 67 |
+
response="unsupported intent."
|
| 68 |
+
print('耗时:' + str(time.time()-start_time))
|
| 69 |
+
print('----------------------')
|
| 70 |
+
return_dict = {}
|
| 71 |
+
return_dict['code'] = 'SUCCESS'
|
| 72 |
+
return_dict['msg'] = '成功'
|
| 73 |
+
contents = {}
|
| 74 |
+
contents['response'] = response
|
| 75 |
+
contents['query'] = query
|
| 76 |
+
return_dict['data'] = contents
|
| 77 |
+
return return_dict
|
| 78 |
+
|
| 79 |
+
print("模型load完毕")
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
print("启动开始---------")
|
| 83 |
+
port = sys.argv[1]
|
| 84 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 85 |
+
print("启动完成---------")
|
server/radio_sev.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
|
| 24 |
+
timep=re.compile(r"(202\d-\d\d-\d\d )*\d\d:\d\d[( am)|( pm)|( AM)|(( PM))]*")
|
| 25 |
+
@app.route("/radio", methods=["GET", "POST"])
|
| 26 |
+
def check():
|
| 27 |
+
intent=""
|
| 28 |
+
slots=dict()
|
| 29 |
+
start_time = time.time()
|
| 30 |
+
if request.method == "POST":
|
| 31 |
+
jsondata = request.get_data(as_text=True)
|
| 32 |
+
if jsondata:
|
| 33 |
+
data = json.loads(jsondata)
|
| 34 |
+
print(data)
|
| 35 |
+
else:
|
| 36 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 37 |
+
return return_dict
|
| 38 |
+
params = ['intent', ]
|
| 39 |
+
for param in params:
|
| 40 |
+
if param not in data:
|
| 41 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 42 |
+
return return_dict
|
| 43 |
+
intent = data.get('intent')
|
| 44 |
+
#iid = str(data.get('iid'))
|
| 45 |
+
if "time" in data:
|
| 46 |
+
slots["time"] = data.get('time')
|
| 47 |
+
if "house_place" in data:
|
| 48 |
+
slots["house_place"] = data.get('house_place')
|
| 49 |
+
if "device_type" in data:
|
| 50 |
+
slots["device_type"] = data.get('device_type')
|
| 51 |
+
if "descriptor" in data:
|
| 52 |
+
slots["descriptor"] = data.get('descriptor')
|
| 53 |
+
if "player_setting" in data:
|
| 54 |
+
slots["player_setting"] = data.get('player_setting')
|
| 55 |
+
if "radio_name" in data:
|
| 56 |
+
slots["radio_name"] = data.get('radio_name')
|
| 57 |
+
if "app_name" in data:
|
| 58 |
+
slots["app_name"] = data.get('app_name')
|
| 59 |
+
if "person_name" in data:
|
| 60 |
+
slots["person_name"] = data.get('person_name')
|
| 61 |
+
if "music_genre" in data:
|
| 62 |
+
slots["music_genre"] = data.get('music_genre')
|
| 63 |
+
if "query" in data:
|
| 64 |
+
slots["query"] = data.get('query')
|
| 65 |
+
if request.method == "GET":
|
| 66 |
+
if "intent" in request.args:
|
| 67 |
+
intent = request.args.get("intent")
|
| 68 |
+
data=request.args
|
| 69 |
+
if "time" in data:
|
| 70 |
+
slots["time"] = data.get('time')
|
| 71 |
+
if "house_place" in data:
|
| 72 |
+
slots["house_place"] = data.get('house_place')
|
| 73 |
+
if "device_type" in data:
|
| 74 |
+
slots["device_type"] = data.get('device_type')
|
| 75 |
+
if "descriptor" in data:
|
| 76 |
+
slots["descriptor"] = data.get('descriptor')
|
| 77 |
+
if "player_setting" in data:
|
| 78 |
+
slots["player_setting"] = data.get('player_setting')
|
| 79 |
+
if "radio_name" in data:
|
| 80 |
+
slots["radio_name"] = data.get('radio_name')
|
| 81 |
+
if "app_name" in data:
|
| 82 |
+
slots["app_name"] = data.get('app_name')
|
| 83 |
+
if "person_name" in data:
|
| 84 |
+
slots["person_name"] = data.get('person_name')
|
| 85 |
+
if "music_genre" in data:
|
| 86 |
+
slots["music_genre"] = data.get('music_genre')
|
| 87 |
+
if "query" in data:
|
| 88 |
+
slots["query"] = data.get('query')
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
response="operated successfully"
|
| 92 |
+
query = {"intent":intent,"slots":slots}
|
| 93 |
+
for key,value in slots.items() :
|
| 94 |
+
if key.find("time")!=-1:
|
| 95 |
+
if timep.match(value) is None:
|
| 96 |
+
response="time format not right"
|
| 97 |
+
if intent =="play_radio":
|
| 98 |
+
if len(slots)==0:
|
| 99 |
+
response="play random radio."
|
| 100 |
+
elif intent =="radio_query":
|
| 101 |
+
pass
|
| 102 |
+
else:
|
| 103 |
+
response="unsupported intent."
|
| 104 |
+
print('耗时:' + str(time.time()-start_time))
|
| 105 |
+
print('----------------------')
|
| 106 |
+
return_dict = {}
|
| 107 |
+
return_dict['code'] = 'SUCCESS'
|
| 108 |
+
return_dict['msg'] = '成功'
|
| 109 |
+
contents = {}
|
| 110 |
+
contents['response'] = response
|
| 111 |
+
contents['query'] = query
|
| 112 |
+
return_dict['data'] = contents
|
| 113 |
+
return return_dict
|
| 114 |
+
|
| 115 |
+
print("模型load完毕")
|
| 116 |
+
|
| 117 |
+
if __name__ == "__main__":
|
| 118 |
+
print("启动开始---------")
|
| 119 |
+
port = sys.argv[1]
|
| 120 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 121 |
+
print("启动完成---------")
|
server/recom_sev.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
|
| 24 |
+
datep=re.compile(r"202\d-\d\d-\d\d")
|
| 25 |
+
@app.route("/recommendation", methods=["GET", "POST"])
|
| 26 |
+
def check():
|
| 27 |
+
intent=""
|
| 28 |
+
slots=dict()
|
| 29 |
+
start_time = time.time()
|
| 30 |
+
if request.method == "POST":
|
| 31 |
+
jsondata = request.get_data(as_text=True)
|
| 32 |
+
if jsondata:
|
| 33 |
+
data = json.loads(jsondata)
|
| 34 |
+
print(data)
|
| 35 |
+
else:
|
| 36 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 37 |
+
return return_dict
|
| 38 |
+
params = ['intent', ]
|
| 39 |
+
for param in params:
|
| 40 |
+
if param not in data:
|
| 41 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 42 |
+
return return_dict
|
| 43 |
+
intent = data.get('intent')
|
| 44 |
+
#iid = str(data.get('iid'))
|
| 45 |
+
if "business_type" in data:
|
| 46 |
+
slots["business_type"] = data.get('business_type')
|
| 47 |
+
if "food_type" in data:
|
| 48 |
+
slots["food_type"] = data.get('food_type')
|
| 49 |
+
if "movie_type" in data:
|
| 50 |
+
slots["movie_type"] = data.get('movie_type')
|
| 51 |
+
if "place_name" in data:
|
| 52 |
+
slots["place_name"] = data.get('place_name')
|
| 53 |
+
if "event_name" in data:
|
| 54 |
+
slots["event_name"] = data.get('event_name')
|
| 55 |
+
if "movie_name" in data:
|
| 56 |
+
slots["movie_name"] = data.get('movie_name')
|
| 57 |
+
if "date" in data:
|
| 58 |
+
slots["date"] = data.get('date')
|
| 59 |
+
if "descriptor" in data:
|
| 60 |
+
slots["descriptor"] = data.get('descriptor')
|
| 61 |
+
if request.method == "GET":
|
| 62 |
+
if "intent" in request.args:
|
| 63 |
+
intent = request.args.get("intent")
|
| 64 |
+
data=request.args
|
| 65 |
+
if "business_type" in data:
|
| 66 |
+
slots["business_type"] = data.get('business_type')
|
| 67 |
+
if "food_type" in data:
|
| 68 |
+
slots["food_type"] = data.get('food_type')
|
| 69 |
+
if "movie_type" in data:
|
| 70 |
+
slots["movie_type"] = data.get('movie_type')
|
| 71 |
+
if "place_name" in data:
|
| 72 |
+
slots["place_name"] = data.get('place_name')
|
| 73 |
+
if "event_name" in data:
|
| 74 |
+
slots["event_name"] = data.get('event_name')
|
| 75 |
+
if "movie_name" in data:
|
| 76 |
+
slots["movie_name"] = data.get('movie_name')
|
| 77 |
+
if "date" in data:
|
| 78 |
+
slots["date"] = data.get('date')
|
| 79 |
+
if "descriptor" in data:
|
| 80 |
+
slots["descriptor"] = data.get('descriptor')
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
response="operated successfully"
|
| 84 |
+
query = {"intent":intent,"slots":slots}
|
| 85 |
+
if intent =="recommendation_events":
|
| 86 |
+
response="find 10 results. event ..., content: ...."
|
| 87 |
+
elif intent =="recommendation_movies":
|
| 88 |
+
response="find 10 results. movie ..., content: ...."
|
| 89 |
+
elif intent=="recommendation_locations":
|
| 90 |
+
if len(slots)==0:
|
| 91 |
+
response="what kind of locations are you looking for?"
|
| 92 |
+
else:
|
| 93 |
+
response="find 10 results. location ..., introduction: ...."
|
| 94 |
+
else:
|
| 95 |
+
response="unsupported intent"
|
| 96 |
+
for key,value in slots.items() :
|
| 97 |
+
if key.find("date")!=-1:
|
| 98 |
+
if datep.match(value) is None:
|
| 99 |
+
response="date format not right"
|
| 100 |
+
print('耗时:' + str(time.time()-start_time))
|
| 101 |
+
print('----------------------')
|
| 102 |
+
return_dict = {}
|
| 103 |
+
return_dict['code'] = 'SUCCESS'
|
| 104 |
+
return_dict['msg'] = '成功'
|
| 105 |
+
contents = {}
|
| 106 |
+
contents['response'] = response
|
| 107 |
+
contents['query'] = query
|
| 108 |
+
return_dict['data'] = contents
|
| 109 |
+
return return_dict
|
| 110 |
+
|
| 111 |
+
print("模型load完毕")
|
| 112 |
+
|
| 113 |
+
if __name__ == "__main__":
|
| 114 |
+
print("启动开始---------")
|
| 115 |
+
port = sys.argv[1]
|
| 116 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 117 |
+
print("启动完成---------")
|
server/run.sh
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nohup python3 alarm_sev.py 3000 > alout.log 2>&1 &
|
| 2 |
+
nohup python3 audiobook_sev.py 3001 > adout.log 2>&1 &
|
| 3 |
+
nohup python3 calendar_sev.py 3002 > clout.log 2>&1 &
|
| 4 |
+
nohup python3 cooking_sev.py 3003 > ckout.log 2>&1 &
|
| 5 |
+
#nohup python3 currency_sev.py 3021 > ckout.log 2>&1 &
|
| 6 |
+
nohup python3 datetime_sev.py 3004 > dtout.log 2>&1 &
|
| 7 |
+
nohup python3 email_sev.py 3005 > emout.log 2>&1 &
|
| 8 |
+
nohup python3 game_sev.py 3006 > gmout.log 2>&1 &
|
| 9 |
+
nohup python3 iot_sev.py 3007 > iotout.log 2>&1 &
|
| 10 |
+
nohup python3 lists_sev.py 3008 > lsout.log 2>&1 &
|
| 11 |
+
nohup python3 music_sev.py 3009 > msout.log 2>&1 &
|
| 12 |
+
nohup python3 news_sev.py 3020 > nsout.log 2>&1 &
|
| 13 |
+
nohup python3 phone_sev.py 3010 > phout.log 2>&1 &
|
| 14 |
+
nohup python3 podcasts_sev.py 3011 > pdout.log 2>&1 &
|
| 15 |
+
#nohup python3 qa_sev.py 3012 > qaout.log 2>&1 &
|
| 16 |
+
nohup python3 radio_sev.py 3013 > rdout.log 2>&1 &
|
| 17 |
+
nohup python3 recom_sev.py 3014 > reout.log 2>&1 &
|
| 18 |
+
nohup python3 social_sev.py 3015 > soout.log 2>&1 &
|
| 19 |
+
#nohup python3 stock_sev.py 3016 > stout.log 2>&1 &
|
| 20 |
+
nohup python3 takeaway_sev.py 3017 > tkout.log 2>&1 &
|
| 21 |
+
nohup python3 transport_sev.py 3018 > trout.log 2>&1 &
|
| 22 |
+
#nohup python3 weather_sev.py 3019 > weout.log 2>&1 &
|
server/social_sev.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
|
| 24 |
+
datep=re.compile(r"202\d-\d\d-\d\d")
|
| 25 |
+
@app.route("/social", methods=["GET", "POST"])
|
| 26 |
+
def check():
|
| 27 |
+
intent=""
|
| 28 |
+
slots=dict()
|
| 29 |
+
start_time = time.time()
|
| 30 |
+
if request.method == "POST":
|
| 31 |
+
jsondata = request.get_data(as_text=True)
|
| 32 |
+
if jsondata:
|
| 33 |
+
data = json.loads(jsondata)
|
| 34 |
+
print(data)
|
| 35 |
+
else:
|
| 36 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 37 |
+
return return_dict
|
| 38 |
+
params = ['intent', ]
|
| 39 |
+
for param in params:
|
| 40 |
+
if param not in data:
|
| 41 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 42 |
+
return return_dict
|
| 43 |
+
intent = data.get('intent')
|
| 44 |
+
#iid = str(data.get('iid'))
|
| 45 |
+
if "media_type" in data:
|
| 46 |
+
slots["media_type"] = data.get('media_type')
|
| 47 |
+
if "person" in data:
|
| 48 |
+
slots["person"] = data.get('person')
|
| 49 |
+
if "business_name" in data:
|
| 50 |
+
slots["business_name"] = data.get('business_name')
|
| 51 |
+
if "content" in data:
|
| 52 |
+
slots["content"] = data.get('content')
|
| 53 |
+
if "date" in data:
|
| 54 |
+
slots["date"] = data.get('date')
|
| 55 |
+
if "descriptor" in data:
|
| 56 |
+
slots["descriptor"] = data.get('descriptor')
|
| 57 |
+
if request.method == "GET":
|
| 58 |
+
if "intent" in request.args:
|
| 59 |
+
intent = request.args.get("intent")
|
| 60 |
+
data=request.args
|
| 61 |
+
if "media_type" in data:
|
| 62 |
+
slots["media_type"] = data.get('media_type')
|
| 63 |
+
if "person" in data:
|
| 64 |
+
slots["person"] = data.get('person')
|
| 65 |
+
if "business_name" in data:
|
| 66 |
+
slots["business_name"] = data.get('business_name')
|
| 67 |
+
if "content" in data:
|
| 68 |
+
slots["content"] = data.get('content')
|
| 69 |
+
if "date" in data:
|
| 70 |
+
slots["date"] = data.get('date')
|
| 71 |
+
if "descriptor" in data:
|
| 72 |
+
slots["descriptor"] = data.get('descriptor')
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
response="operated successfully"
|
| 76 |
+
query = {"intent":intent,"slots":slots}
|
| 77 |
+
|
| 78 |
+
if intent=="social_post":
|
| 79 |
+
if "media_type" not in slots or "person" not in slots or "business_name" not in slots or "content" not in slots:
|
| 80 |
+
response="what do you want to post?"
|
| 81 |
+
elif intent=="social_query":
|
| 82 |
+
if len(slots)==0:
|
| 83 |
+
response="waht social media do you want to query?"
|
| 84 |
+
else:
|
| 85 |
+
response="find 10 results. post 1, content: ...."
|
| 86 |
+
else:
|
| 87 |
+
response="unsupported intent."
|
| 88 |
+
for key,value in slots.items() :
|
| 89 |
+
if key.find("date")!=-1:
|
| 90 |
+
if datep.match(value) is None:
|
| 91 |
+
response="date format not right"
|
| 92 |
+
print('耗时:' + str(time.time()-start_time))
|
| 93 |
+
print('----------------------')
|
| 94 |
+
return_dict = {}
|
| 95 |
+
return_dict['code'] = 'SUCCESS'
|
| 96 |
+
return_dict['msg'] = '成功'
|
| 97 |
+
contents = {}
|
| 98 |
+
contents['response'] = response
|
| 99 |
+
contents['query'] = query
|
| 100 |
+
return_dict['data'] = contents
|
| 101 |
+
return return_dict
|
| 102 |
+
|
| 103 |
+
print("模型load完毕")
|
| 104 |
+
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
print("启动开始---------")
|
| 107 |
+
port = sys.argv[1]
|
| 108 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 109 |
+
print("启动完成---------")
|
server/takeaway_sev.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
|
| 24 |
+
datep=re.compile(r"202\d-\d\d-\d\d")
|
| 25 |
+
timep=re.compile(r"(202\d-\d\d-\d\d )*\d\d:\d\d[( am)|( pm)|( AM)|(( PM))]*")
|
| 26 |
+
@app.route("/takeaway", methods=["GET", "POST"])
|
| 27 |
+
def check():
|
| 28 |
+
intent=""
|
| 29 |
+
slots=dict()
|
| 30 |
+
start_time = time.time()
|
| 31 |
+
if request.method == "POST":
|
| 32 |
+
jsondata = request.get_data(as_text=True)
|
| 33 |
+
if jsondata:
|
| 34 |
+
data = json.loads(jsondata)
|
| 35 |
+
print(data)
|
| 36 |
+
else:
|
| 37 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 38 |
+
return return_dict
|
| 39 |
+
params = ['intent', ]
|
| 40 |
+
for param in params:
|
| 41 |
+
if param not in data:
|
| 42 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 43 |
+
return return_dict
|
| 44 |
+
intent = data.get('intent')
|
| 45 |
+
#iid = str(data.get('iid'))
|
| 46 |
+
if "food_type" in data:
|
| 47 |
+
slots["food_type"] = data.get('meal_type')
|
| 48 |
+
if "meal_type" in data:
|
| 49 |
+
slots["meal_type"] = data.get('meal_type')
|
| 50 |
+
if "order_type" in data:
|
| 51 |
+
slots["order_type"] = data.get('order_type')
|
| 52 |
+
if "business_type" in data:
|
| 53 |
+
slots["business_type"] = data.get('business_type')
|
| 54 |
+
if "business_name" in data:
|
| 55 |
+
slots["business_name"] = data.get('business_name')
|
| 56 |
+
if "place_name" in data:
|
| 57 |
+
slots["place_name"] = data.get('place_name')
|
| 58 |
+
if "date" in data:
|
| 59 |
+
slots["date"] = data.get('date')
|
| 60 |
+
if "time" in data:
|
| 61 |
+
slots["time"] = data.get('time')
|
| 62 |
+
if "descriptor" in data:
|
| 63 |
+
slots["descriptor"] = data.get('descriptor')
|
| 64 |
+
if request.method == "GET":
|
| 65 |
+
if "intent" in request.args:
|
| 66 |
+
intent = request.args.get("intent")
|
| 67 |
+
data=request.args
|
| 68 |
+
if "food_type" in data:
|
| 69 |
+
slots["food_type"] = data.get('meal_type')
|
| 70 |
+
if "meal_type" in data:
|
| 71 |
+
slots["meal_type"] = data.get('meal_type')
|
| 72 |
+
if "order_type" in data:
|
| 73 |
+
slots["order_type"] = data.get('order_type')
|
| 74 |
+
if "business_type" in data:
|
| 75 |
+
slots["business_type"] = data.get('business_type')
|
| 76 |
+
if "business_name" in data:
|
| 77 |
+
slots["business_name"] = data.get('business_name')
|
| 78 |
+
if "place_name" in data:
|
| 79 |
+
slots["place_name"] = data.get('place_name')
|
| 80 |
+
if "date" in data:
|
| 81 |
+
slots["date"] = data.get('date')
|
| 82 |
+
if "time" in data:
|
| 83 |
+
slots["time"] = data.get('time')
|
| 84 |
+
if "descriptor" in data:
|
| 85 |
+
slots["descriptor"] = data.get('descriptor')
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
response="operated successfully"
|
| 89 |
+
query = {"intent":intent,"slots":slots}
|
| 90 |
+
if intent =="takeaway_query":
|
| 91 |
+
response="find 10 results. restaurant ..., food: ...."
|
| 92 |
+
elif intent =="takeaway_order":
|
| 93 |
+
if len(slots)==0:
|
| 94 |
+
response="what do you want to order?"
|
| 95 |
+
else:
|
| 96 |
+
response="unsupported intent"
|
| 97 |
+
for key,value in slots.items() :
|
| 98 |
+
if key.find("time")!=-1:
|
| 99 |
+
if timep.match(value) is None:
|
| 100 |
+
response="time format not right"
|
| 101 |
+
if key.find("date")!=-1:
|
| 102 |
+
if datep.match(value) is None:
|
| 103 |
+
response="date format not right"
|
| 104 |
+
print('耗时:' + str(time.time()-start_time))
|
| 105 |
+
print('----------------------')
|
| 106 |
+
return_dict = {}
|
| 107 |
+
return_dict['code'] = 'SUCCESS'
|
| 108 |
+
return_dict['msg'] = '成功'
|
| 109 |
+
contents = {}
|
| 110 |
+
contents['response'] = response
|
| 111 |
+
contents['query'] = query
|
| 112 |
+
return_dict['data'] = contents
|
| 113 |
+
return return_dict
|
| 114 |
+
|
| 115 |
+
print("模型load完毕")
|
| 116 |
+
|
| 117 |
+
if __name__ == "__main__":
|
| 118 |
+
print("启动开始---------")
|
| 119 |
+
port = sys.argv[1]
|
| 120 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 121 |
+
print("启动完成---------")
|
server/transport_sev.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import time
|
| 6 |
+
import csv
|
| 7 |
+
import sys
|
| 8 |
+
import re
|
| 9 |
+
app=Flask(__name__)
|
| 10 |
+
|
| 11 |
+
def read_chat_intents_from_file(file_path,domain):
|
| 12 |
+
queries = dict()
|
| 13 |
+
with open(file_path ) as f:
|
| 14 |
+
lines=f.readlines()
|
| 15 |
+
count=0
|
| 16 |
+
for line in lines:
|
| 17 |
+
line=line.strip()
|
| 18 |
+
query=json.loads(line)
|
| 19 |
+
if query['domain']==domain:
|
| 20 |
+
queries[query["iid"]]=query
|
| 21 |
+
|
| 22 |
+
return queries
|
| 23 |
+
|
| 24 |
+
datep=re.compile(r"202\d-\d\d-\d\d")
|
| 25 |
+
timep=re.compile(r"(202\d-\d\d-\d\d )*\d\d:\d\d[( am)|( pm)|( AM)|(( PM))]*")
|
| 26 |
+
@app.route("/transport", methods=["GET", "POST"])
|
| 27 |
+
def check():
|
| 28 |
+
intent=""
|
| 29 |
+
slots=dict()
|
| 30 |
+
start_time = time.time()
|
| 31 |
+
if request.method == "POST":
|
| 32 |
+
jsondata = request.get_data(as_text=True)
|
| 33 |
+
if jsondata:
|
| 34 |
+
data = json.loads(jsondata)
|
| 35 |
+
print(data)
|
| 36 |
+
else:
|
| 37 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数'}
|
| 38 |
+
return return_dict
|
| 39 |
+
params = ['intent', ]
|
| 40 |
+
for param in params:
|
| 41 |
+
if param not in data:
|
| 42 |
+
return_dict = {'code': 'FAIL', 'msg': '失败,缺少参数:' + param}
|
| 43 |
+
return return_dict
|
| 44 |
+
intent = data.get('intent')
|
| 45 |
+
#iid = str(data.get('iid'))
|
| 46 |
+
if "transport_type" in data:
|
| 47 |
+
slots["transport_type"] = data.get('transport_type')
|
| 48 |
+
if "transport_agency" in data:
|
| 49 |
+
slots["transport_agency"] = data.get('transport_agency')
|
| 50 |
+
if "business_type" in data:
|
| 51 |
+
slots["business_type"] = data.get('business_type')
|
| 52 |
+
if "business_name" in data:
|
| 53 |
+
slots["business_name"] = data.get('business_name')
|
| 54 |
+
if "place_name" in data:
|
| 55 |
+
slots["place_name"] = data.get('place_name')
|
| 56 |
+
if "to_place_name" in data:
|
| 57 |
+
slots["to_place_name"] = data.get('to_place_name')
|
| 58 |
+
if "from_place_name" in data:
|
| 59 |
+
slots["from_place_name"] = data.get('from_place_name')
|
| 60 |
+
if "query" in data:
|
| 61 |
+
slots["query"] = data.get('query')
|
| 62 |
+
if "date" in data:
|
| 63 |
+
slots["date"] = data.get('date')
|
| 64 |
+
if "time" in data:
|
| 65 |
+
slots["time"] = data.get('time')
|
| 66 |
+
#if "timeofday" in data:
|
| 67 |
+
# slots["timeofday"] = data.get('timeofday')
|
| 68 |
+
if "descriptor" in data:
|
| 69 |
+
slots["descriptor"] = data.get('descriptor')
|
| 70 |
+
if request.method == "GET":
|
| 71 |
+
if "intent" in request.args:
|
| 72 |
+
intent = request.args.get("intent")
|
| 73 |
+
data=request.args
|
| 74 |
+
if "transport_type" in data:
|
| 75 |
+
slots["transport_type"] = data.get('transport_type')
|
| 76 |
+
if "transport_agency" in data:
|
| 77 |
+
slots["transport_agency"] = data.get('transport_agency')
|
| 78 |
+
if "business_type" in data:
|
| 79 |
+
slots["business_type"] = data.get('business_type')
|
| 80 |
+
if "business_name" in data:
|
| 81 |
+
slots["business_name"] = data.get('business_name')
|
| 82 |
+
if "place_name" in data:
|
| 83 |
+
slots["place_name"] = data.get('place_name')
|
| 84 |
+
if "to_place_name" in data:
|
| 85 |
+
slots["to_place_name"] = data.get('to_place_name')
|
| 86 |
+
if "from_place_name" in data:
|
| 87 |
+
slots["from_place_name"] = data.get('from_place_name')
|
| 88 |
+
if "query" in data:
|
| 89 |
+
slots["query"] = data.get('query')
|
| 90 |
+
if "date" in data:
|
| 91 |
+
slots["date"] = data.get('date')
|
| 92 |
+
if "time" in data:
|
| 93 |
+
slots["time"] = data.get('time')
|
| 94 |
+
#if "timeofday" in data:
|
| 95 |
+
# slots["timeofday"] = data.get('timeofday')
|
| 96 |
+
if "descriptor" in data:
|
| 97 |
+
slots["descriptor"] = data.get('descriptor')
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
response="operated successfully"
|
| 101 |
+
query = {"intent":intent,"slots":slots}
|
| 102 |
+
if intent =="transport_taxi" or intent =="transport_ticket":
|
| 103 |
+
if "to_place_name" not in slots and "from_place_name" not in slots:
|
| 104 |
+
response="what is your destination?"
|
| 105 |
+
elif intent =="transport_traffic":
|
| 106 |
+
response="find the following results. from ... road to ...."
|
| 107 |
+
elif intent=="transport_query":
|
| 108 |
+
if len(slots)==0:
|
| 109 |
+
response="what do you want to query?"
|
| 110 |
+
else:
|
| 111 |
+
response="find the following results. from ... to ...."
|
| 112 |
+
else:
|
| 113 |
+
response="unsupported intent"
|
| 114 |
+
for key,value in slots.items() :
|
| 115 |
+
if key.find("time")!=-1:
|
| 116 |
+
if timep.match(value) is None:
|
| 117 |
+
response="time format not right"
|
| 118 |
+
if key.find("date")!=-1:
|
| 119 |
+
if datep.match(value) is None:
|
| 120 |
+
response="date format not right"
|
| 121 |
+
print('耗时:' + str(time.time()-start_time))
|
| 122 |
+
print('----------------------')
|
| 123 |
+
return_dict = {}
|
| 124 |
+
return_dict['code'] = 'SUCCESS'
|
| 125 |
+
return_dict['msg'] = '成功'
|
| 126 |
+
contents = {}
|
| 127 |
+
contents['response'] = response
|
| 128 |
+
contents['query'] = query
|
| 129 |
+
return_dict['data'] = contents
|
| 130 |
+
return return_dict
|
| 131 |
+
|
| 132 |
+
print("模型load完毕")
|
| 133 |
+
|
| 134 |
+
if __name__ == "__main__":
|
| 135 |
+
print("启动开始---------")
|
| 136 |
+
port = sys.argv[1]
|
| 137 |
+
app.run(debug=False, host='0.0.0.0',port=port)
|
| 138 |
+
print("启动完成---------")
|