Commit b033bed1 by lichenggang

增加单次预测服务

parent b63dcce9
No preview for this file type
No preview for this file type
...@@ -43,6 +43,8 @@ class PredictorFac: ...@@ -43,6 +43,8 @@ class PredictorFac:
return 1, res return 1, res
elif predict_type == 'brand': elif predict_type == 'brand':
return 1, res return 1, res
elif predict_type == 'gn':
return 1, res
if __name__ == "__main__": if __name__ == "__main__":
def get_test_data(): def get_test_data():
......
...@@ -11,8 +11,10 @@ from utils.redis_cli import redis_cli ...@@ -11,8 +11,10 @@ from utils.redis_cli import redis_cli
from predict.kw_predict import KwPredict from predict.kw_predict import KwPredict
from utils.status import code2msg from utils.status import code2msg
import re
class KwHandler(tornado.web.RequestHandler):
pat = re.compile(r'(?:.*\-.*|\d+)')
class BrandKwHandler(tornado.web.RequestHandler):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.predic = KwPredict('validSingle') self.predic = KwPredict('validSingle')
...@@ -20,9 +22,10 @@ class BrandKwHandler(tornado.web.RequestHandler): ...@@ -20,9 +22,10 @@ class BrandKwHandler(tornado.web.RequestHandler):
async def get(self): async def get(self):
target = unquote(self.get_argument('keyword', '')) target = unquote(self.get_argument('keyword', ''))
predic_type = unquote(self.get_argument('predic_type', 'brand'))
brand_set = redis_cli.smembers('brand_set') brand_set = redis_cli.smembers('brand_set')
if not target: if not target or not predic_type:
code = '100001' code = '100001'
res = code2msg(code) res = code2msg(code)
else: else:
...@@ -49,14 +52,27 @@ class BrandKwHandler(tornado.web.RequestHandler): ...@@ -49,14 +52,27 @@ class BrandKwHandler(tornado.web.RequestHandler):
self.write(res) self.write(res)
async def post(self): async def post(self):
target = self.request.body
list_data = json.loads(self.request.body) list_data = json.loads(self.request.body)
dic_res = {}
for kw in list_data:
if len(kw) <=2:
dic_res[kw] = 0
elif self.pat.findall(kw):
dic_res[kw] = 1
else:
res1 = self.predic.predict(kw, 'gn')
res2 = self.predic.predict(kw, 'param')
if res1['result'] == 1 or res2['result'] == 1:
dic_res[kw] = 1
else:
dic_res[kw] = 0
self.write({'status': 1,'result':dic_res})
def gen_app(): def gen_app():
return tornado.web.Application(handlers=[(k, v) for k, v in register_tornado_handlers.items()]) return tornado.web.Application(handlers=[(k, v) for k, v in register_tornado_handlers.items()])
register_tornado_handlers = {'/brandkw': BrandKwHandler} register_tornado_handlers = {'/keyword': KwHandler}
def http_server(port): def http_server(port):
......
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