Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
bom_identify
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
91bd21e6
authored
Jan 18, 2021
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
单个关键词预测单独抽离
parent
34016db7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
14 deletions
valid_server.py
valid_server.py
View file @
91bd21e6
...
...
@@ -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
()])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment