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
b4b0b6a7
authored
Jan 26, 2021
by
陈森彬
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
增加参数R/r的简写,封装匹配方式改变
parent
80b2746f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
10 deletions
config.py
utils/functions.py
valid_server.py
config.py
View file @
b4b0b6a7
...
...
@@ -121,13 +121,15 @@ encap_list = ["0030", "008004", "01005", "015008", "0201", "02016", "0202", "020
temp_map
=
[
"C0G"
,
"NP0"
,
"COG"
,
"NPO"
,
"X7R"
,
"X5R"
,
"Y5V"
,
"X6S"
,
"X7S"
,
"X7T"
,
"SL"
,
"U2J"
,
"UJ"
,
"X7U"
,
"X8R"
,
"Z5U"
,
"C0H"
,
"COH"
,
"U2K"
,
"X6T"
,
"X8G"
,
"X8L"
,
"Y5R"
,
"Y5U"
,
"ZLM"
]
unit_regex
=
"μΩ|uΩ|mΩ|Ω|R|r|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|
%
|毫欧|欧姆|欧|千欧|兆欧|伏特|伏|千伏|瓦特|瓦"
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|
%
|毫欧|欧姆|欧|千欧|兆欧|伏特|伏|千伏|瓦特|瓦"
r_regex
=
"Rr"
encap_regex
=
"0030|008004|01005|015008|0201|02016|0202|0204|03015|03019|0302|0303|0306|0402|0404|0405|0406|0502|0503|0504|0505|0508|0602|0603|0604|0605|0606|0612|0704|0707|0709|0803|0804|0805|0806|0815|0830|0905|0909|1003|1005|1006|1007|1008|1010|1012|1020|1106|1111|1113|1204|1205|1206|1207|1208|1209|1210|1211|1212|1213|1218|1225|1230|1246|1305|1410|1411|1412|1414|1505|1507|1510|1512|1515|1530|1606|1608|1611|1612|1616|1625|1708|1715|1805|1806|1807|1808|1810|1812|1816|1825|1835|1913|1916|1919|2005|2008|2010|2015|2016|2018|2020|2023|2043|2211|2214|2215|2218|2220|2225|2304|2312|2323|2325|2410|2414|2416|2420|2423|2424|2512|2520|2525|2615|2616|2706|2709|2711|2721|2727|2728|2812|2820|2824|2825|2828|2830|2910|2913|2915|2917|2920|2924|3010|3015|3017|3022|3024|3025|3040|3131|3225|3226|3312|3318|3333|3640|3838|3920|3925|3931|4030|4032|4122|4520|4823|4850|5040|5329|5829|5929|6028|6030|6031|6039|6054|6560"
encap_par_start
=
",| /,-"
legal_char
=
'CRL'
encap_par_str
=
",| /,-CRL"
split_char
=
'|,,/ '
special_tuple
=
(
"-"
,)
...
...
utils/functions.py
View file @
b4b0b6a7
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import
re
from
config
import
unit_map
,
cast_map
,
unit_regex
,
special_tuple
,
encap_list
,
temp_map
,
special_str
,
encap_regex
from
config
import
unit_map
,
cast_map
,
unit_regex
,
special_tuple
,
encap_list
,
temp_map
,
special_str
,
encap_regex
,
\
r_regex
,
legal_char
,
split_char
unit_pattern
=
re
.
compile
(
'([.a-zA-Z
\\
-]?)(
\
d+|
\
d+[
\\
\
./?]
\
d+)('
+
unit_regex
+
')([.a-zA-Z
\\
-]?)'
)
encap_pattern
=
re
.
compile
(
'.*('
+
encap_regex
+
').*'
)
r_pattern
=
re
.
compile
(
'([.a-zA-Z
\\
-]?)(
\
d+['
+
r_regex
+
']
\
d+|['
+
r_regex
+
']
\
d+|
\
d+['
+
r_regex
+
'])([.a-zA-Z
\\
-]?)'
)
encap_pattern
=
re
.
compile
(
'(.{0,2})('
+
encap_regex
+
')(.{0,2})'
,
re
.
I
)
prefixchar
=
[
i
+
j
for
i
in
split_char
for
j
in
legal_char
]
tailchar
=
[
i
+
j
for
i
in
legal_char
for
j
in
split_char
]
prefixchar
.
extend
(
list
(
legal_char
))
tailchar
.
extend
(
list
(
split_char
))
prefixchar
.
append
(
''
)
tailchar
.
append
(
''
)
def
is_float
(
s
):
...
...
@@ -179,6 +188,21 @@ def get_not_exist_list(attrs_list, cut_list):
return
not_exist_list
def
valid_encap
(
prefix
,
tail
):
prefix_flag
=
False
tail_flag
=
False
if
prefix
in
prefixchar
or
prefix
[
-
1
]
in
split_char
:
prefix_flag
=
True
if
tail
in
tailchar
or
tail
[
0
]
in
split_char
:
tail_flag
=
True
if
prefix_flag
and
tail_flag
:
return
True
return
False
def
check_encap
(
kw
):
"""
确认是不是封装
...
...
@@ -187,7 +211,9 @@ def check_encap(kw):
"""
encap_res
=
encap_pattern
.
findall
(
kw
)
if
encap_res
:
return
encap_res
encap_res
=
encap_res
[
0
]
if
valid_encap
(
encap_res
[
0
],
encap_res
[
2
]):
return
encap_res
[
1
]
return
False
...
...
@@ -213,6 +239,25 @@ def check_symbol(kw):
return
False
def
check_param_r
(
kw
):
check_res
=
r_pattern
.
findall
(
kw
)
if
not
check_res
:
check_res
=
False
else
:
check_res
=
check_res
[
0
]
new_list
=
[]
if
not
check_res
[
0
]
.
isalpha
()
and
not
check_res
[
2
]
.
isalpha
():
cut_list
=
re
.
split
(
'[Rr]'
,
check_res
[
1
])
if
not
cut_list
[
0
]
and
cut_list
[
1
]:
new_list
.
append
(
"0."
+
str
(
cut_list
[
1
])
+
"Ω"
)
elif
cut_list
[
0
]
and
not
cut_list
[
1
]:
new_list
.
append
(
str
(
cut_list
[
0
])
+
"Ω"
)
else
:
new_list
.
append
(
check_res
[
1
]
.
replace
(
"R"
,
"."
)
.
replace
(
"r"
,
"."
)
+
"Ω"
)
check_res
=
new_list
return
check_res
def
get_unit
(
unit_list
):
unit_str
=
""
for
u_str
in
unit_list
:
...
...
valid_server.py
View file @
b4b0b6a7
...
...
@@ -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_symbol
check_encap
,
check_temp
,
check_symbol
,
check_param_r
from
utils.redis_cli
import
redis_cli
from
predict.kw_predict
import
KwPredict
...
...
@@ -131,12 +131,14 @@ class UCHandler(tornado.web.RequestHandler):
for
kw_info
in
unknown_list
:
if
check_temp
(
kw_info
):
attrs_list
.
append
(
kw_info
)
elif
check_param_r
(
kw_info
):
attrs_list
.
append
(
check_param_r
(
kw_info
)[
0
])
else
:
encap_res
=
check_encap
(
kw_info
)
if
encap_res
:
encap_list
.
append
(
encap_res
[
0
]
)
continue
if
kw_info
and
check_symbol
(
kw_info
):
encap_list
.
append
(
encap_res
)
if
kw_info
and
check_symbol
(
kw_info
)
and
not
encap_res
:
words_list
.
append
(
kw_info
)
res
[
'status'
]
=
1
...
...
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