Commit 91bd21e6 by lichenggang

单个关键词预测单独抽离

parent 34016db7
Showing with 24 additions and 14 deletions
......@@ -13,6 +13,29 @@ from predict.kw_predict import KwPredict
from utils.status import code2msg
import re
def predict_gn_param(predict: KwPredict, kw) -> int:
'''
传入预测类实例和关键字,返回是否是型号名或参数
:param predict: 预测类实例
:param kw: 关键字
:return: 1|0
'''
pat = re.compile(r'(?:.*\-.*|\d+)')
if len(kw) <= 2:
return 0
elif pat.findall(kw):
return 1
else:
res1 = predict.predict(kw, 'gn')
res2 = predict.predict(kw, 'param')
if res1['result'] == 1 or res2['result'] == 1:
return 1
else:
return 0
class KwHandler(tornado.web.RequestHandler):
pat = re.compile(r'(?:.*\-.*|\d+)')
......@@ -56,24 +79,11 @@ class KwHandler(tornado.web.RequestHandler):
list_data = json.loads(self.request.body)
dic_res = {}
for kw in list_data:
dic_res[kw] = self.judge(kw)
dic_res[kw] = predict_gn_param(self.predic, kw)
self.write({'status': 1,'result':dic_res})
def judge(self, kw):
if len(kw) <= 2:
return 0
elif self.pat.findall(kw):
return 1
else:
res1 = self.predic.predict(kw, 'gn')
res2 = self.predic.predict(kw, 'param')
if res1['result'] == 1 or res2['result'] == 1:
return 1
else:
return 0
def gen_app():
return tornado.web.Application(handlers=[(k, v) for k, v in register_tornado_handlers.items()])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment