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
0a001818
authored
Jan 25, 2021
by
陈森彬
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
增加过滤用户输入极特别的情况
parent
ea9d33ab
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
8 deletions
config.py
utils/functions.py
valid_server.py
config.py
View file @
0a001818
...
...
@@ -122,3 +122,6 @@ temp_map = ["C0G", "NP0", "COG", "NPO", "X7R", "X5R", "Y5V", "X6S", "X7S", "X7T"
unit_regex
=
"μΩ|uΩ|mΩ|Ω|kΩ|KΩ|MΩ|GΩ|TΩ|pF|PF|Pf|pf|nF|NF|Nf|nf|µF|μF|uF|UF|Uf|uf|mF|MF|Mf|mf|F|pH|Ph|PH|ph|nH|µH|UH|μh|uh|Uh|uH|mH|Mh|MH|mh|H|mA|A|a|V|v|kV|Kv|kv|KV|W|w|kW|kw|KW|Kw|
%
|毫欧|欧姆|欧|千欧|兆欧|伏特|伏|千伏|瓦特|瓦"
special_tuple
=
(
"-"
,)
special_str
=
"~!@#$
%
^&*()_+-*/<>,.。,[]
\
/"
utils/functions.py
View file @
0a001818
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import
re
from
config
import
unit_map
,
cast_map
,
unit_regex
,
special_tuple
,
encap_list
,
temp_map
from
config
import
unit_map
,
cast_map
,
unit_regex
,
special_tuple
,
encap_list
,
temp_map
,
special_str
unit_pattern
=
re
.
compile
(
'(
\
d+|
\
d+[
\\
\
./?]
\
d+)('
+
unit_regex
+
')([.a-zA-Z
\\
-]?)'
)
...
...
@@ -199,6 +199,17 @@ def check_temp(kw):
return
False
def
check_symbol
(
kw
):
"""
确认是不是符号
:param kw:
:return:
"""
if
kw
not
in
special_str
:
return
True
return
False
def
get_unit
(
unit_list
):
unit_str
=
""
for
u_str
in
unit_list
:
...
...
valid_server.py
View file @
0a001818
...
...
@@ -7,7 +7,7 @@ import tornado.web
import
tornado.ioloop
from
utils.functions
import
pre_judge
,
word_conversion
,
cut_params
,
check_param
,
unit_conversion
,
get_not_exist_list
,
\
check_encap
,
check_temp
check_encap
,
check_temp
,
check_symbol
from
utils.redis_cli
import
redis_cli
from
predict.kw_predict
import
KwPredict
...
...
@@ -91,12 +91,13 @@ class UCHandler(tornado.web.RequestHandler):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
()
.
__init__
(
*
args
,
**
kwargs
)
self
.
predic
=
KwPredict
(
'validSingle'
)
self
.
w_par
=
re
.
compile
(
r'[\u4e00-\u9fa5]+'
)
self
.
encap_par
=
re
.
compile
(
r'\d+'
)
self
.
unit_pattern
=
re
.
compile
(
'([^0-9±/,.])'
)
self
.
w_par
=
re
.
compile
(
r'[\u4e00-\u9fa5]+'
)
# 中文匹配
self
.
encap_par
=
re
.
compile
(
r'\d+'
)
# 封装匹配
self
.
unit_pattern
=
re
.
compile
(
'([^0-9±/,.])'
)
# 单位匹配
async
def
post
(
self
):
data_list
=
json
.
loads
(
self
.
request
.
body
)
print
(
data_list
)
if
not
data_list
:
code
=
'100002'
res
=
code2msg
(
code
)
...
...
@@ -134,12 +135,14 @@ class UCHandler(tornado.web.RequestHandler):
if
check_encap
(
encap_res
[
0
]):
encap_list
.
append
(
encap_res
[
0
])
continue
if
kw_info
and
check_symbol
(
kw_info
):
words_list
.
append
(
kw_info
)
res
[
'status'
]
=
1
res
[
'words'
]
=
words_list
res
[
'attrs'
]
=
attrs_list
res
[
'encap'
]
=
encap_list
res
[
'words'
]
=
list
(
set
(
words_list
))
res
[
'attrs'
]
=
list
(
set
(
attrs_list
))
res
[
'encap'
]
=
list
(
set
(
encap_list
))
print
(
res
)
self
.
write
(
res
)
...
...
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