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
1fcdf57b
authored
May 19, 2021
by
陈森彬
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
匹配带"-"号的百分数,kΩ的特殊匹配
parent
5ead7a1a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
config.py
utils/functions.py
config.py
View file @
1fcdf57b
...
@@ -86,7 +86,10 @@ unit_map = {
...
@@ -86,7 +86,10 @@ unit_map = {
},
},
'
%
'
:
{
'
%
'
:
0.01
,
},
'
%
'
:
{
'
%
'
:
0.01
,
'-
%
'
:
0.01
,
},
}
}
cast_map
=
{
cast_map
=
{
...
@@ -136,3 +139,5 @@ special_tuple = ("-",)
...
@@ -136,3 +139,5 @@ special_tuple = ("-",)
special_str
=
"~!@#$
%
^&*()_+-*/<>,.。,[]
\
/"
special_str
=
"~!@#$
%
^&*()_+-*/<>,.。,[]
\
/"
attr_regex
=
"F|H|K|A|W|KW"
attr_regex
=
"F|H|K|A|W|KW"
special_attr_regex
=
"Ω"
utils/functions.py
View file @
1fcdf57b
...
@@ -2,10 +2,10 @@
...
@@ -2,10 +2,10 @@
# -*- coding:utf-8 -*-
# -*- coding:utf-8 -*-
import
re
import
re
from
config
import
unit_map
,
cast_map
,
unit_regex
,
special_tuple
,
attr_regex
,
temp_map
,
special_str
,
encap_regex
,
\
from
config
import
unit_map
,
cast_map
,
unit_regex
,
special_tuple
,
attr_regex
,
temp_map
,
special_str
,
encap_regex
,
\
r_regex
,
legal_char
,
split_char
r_regex
,
legal_char
,
split_char
,
special_attr_regex
unit_pattern
=
re
.
compile
(
'([.a-zA-Z
\\
-]?)(
\
d+|
\
d+[
\\
\
./?]
\
d+)('
+
unit_regex
+
')([.a-zA-Z
\\
-]?)'
)
unit_pattern
=
re
.
compile
(
'([.a-zA-Z
\\
-]?)(
\
d+|
\
d+[
\\
\
./?]
\
d+)('
+
unit_regex
+
')([.a-zA-Z
\\
-]?)'
)
attr_pattern
=
re
.
compile
(
'(
\
d+|
\
.
\
d+)('
+
attr_regex
+
')'
)
attr_pattern
=
re
.
compile
(
'(
\
d+|
\
.
\
d+)('
+
attr_regex
+
')
('
+
special_attr_regex
+
')
'
)
r_pattern
=
re
.
compile
(
r_pattern
=
re
.
compile
(
'([.a-zA-Z
\\
-]?)(
\
d+['
+
r_regex
+
']
\
d+|['
+
r_regex
+
']
\
d+|
\
d+['
+
r_regex
+
'])([.a-zA-Z
\\
-]?)'
)
'([.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
)
encap_pattern
=
re
.
compile
(
'(.{0,2})('
+
encap_regex
+
')(.{0,2})'
,
re
.
I
)
...
@@ -76,9 +76,13 @@ def check_param(kw):
...
@@ -76,9 +76,13 @@ def check_param(kw):
else
:
else
:
new_list
=
[]
new_list
=
[]
for
param
in
check_res
:
for
param
in
check_res
:
if
"
%
"
not
in
param
:
if
not
param
[
0
]
.
isalpha
()
and
param
[
0
]
not
in
special_tuple
and
not
param
[
3
]
.
isalpha
()
and
param
[
if
not
param
[
0
]
.
isalpha
()
and
param
[
0
]
not
in
special_tuple
and
not
param
[
3
]
.
isalpha
()
and
param
[
3
]
not
in
special_tuple
:
3
]
not
in
special_tuple
:
new_list
.
append
(
param
[
1
]
+
param
[
2
])
new_list
.
append
(
param
[
1
]
+
param
[
2
])
else
:
if
not
param
[
0
]
.
isalpha
()
and
not
param
[
3
]
.
isalpha
()
and
param
[
3
]
not
in
special_tuple
:
new_list
.
append
(
param
[
0
]
+
param
[
1
]
+
param
[
2
])
check_res
=
new_list
check_res
=
new_list
return
check_res
return
check_res
...
@@ -126,10 +130,13 @@ def unit_conversion(unit_res, kw):
...
@@ -126,10 +130,13 @@ def unit_conversion(unit_res, kw):
"""
"""
unit_str
=
get_unit
(
unit_res
)
unit_str
=
get_unit
(
unit_res
)
for
unit_key
,
unit_data
in
unit_map
.
items
():
for
unit_key
,
unit_data
in
unit_map
.
items
():
if
unit_str
in
unit_data
:
if
unit_str
in
unit_data
:
if
"/"
not
in
kw
:
# 单独处理除号
if
"/"
not
in
kw
:
# 单独处理除号
if
"
%
"
in
kw
:
# 百分号的单独处理
if
"
%
"
in
kw
:
# 百分号的单独处理
if
"-"
in
unit_str
:
unit_str
=
unit_str
.
replace
(
"-"
,
""
)
unit_num
=
int
(
kw
.
replace
(
unit_str
,
""
)
.
replace
(
"-"
,
""
))
else
:
unit_num
=
int
(
kw
.
replace
(
unit_str
,
""
))
unit_num
=
int
(
kw
.
replace
(
unit_str
,
""
))
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
unit_str
]))
true_unit
=
str
(
delete_extra_zero
(
unit_num
*
unit_data
[
unit_str
]))
elif
"."
in
kw
:
# 处理小数点
elif
"."
in
kw
:
# 处理小数点
...
@@ -301,11 +308,12 @@ def get_unit(unit_list):
...
@@ -301,11 +308,12 @@ def get_unit(unit_list):
unit_str
+=
u_str
unit_str
+=
u_str
return
unit_str
return
unit_str
def
check_attr
(
kw_info
):
def
check_attr
(
kw_info
):
res
=
attr_pattern
.
findall
(
kw_info
)
res
=
attr_pattern
.
findall
(
kw_info
)
if
not
res
:
if
not
res
:
return
False
return
False
else
:
else
:
if
res
[
0
][
0
]
and
res
[
0
][
1
]
and
"."
not
in
res
[
0
][
0
]:
if
res
[
0
][
0
]
and
res
[
0
][
1
]
and
"."
not
in
res
[
0
][
0
]
and
not
res
[
0
][
2
]
:
return
True
return
True
return
False
return
False
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