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
ebf97191
authored
Jun 03, 2020
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
增加kw_predict
parent
c82b2a08
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
12 deletions
classify_server.py
predic_fac.py
predict/dict_predict.py
predict/kw_predict.py
classify_server.py
View file @
ebf97191
...
...
@@ -18,12 +18,14 @@ class Classify(classify_pb2_grpc.classifyServicer):
def
Classify
(
self
,
request
,
context
):
try
:
dic_data
=
json
.
loads
(
request
.
keyword
)
res
=
self
.
predictorfac
.
predict
(
dic_data
)
res
[
'status'
]
=
1
except
:
except
json
.
decoder
.
JSONDecodeError
:
res
=
self
.
predictorfac
.
predict
(
request
.
keyword
)
res
[
'status'
]
=
1
except
:
res
=
{
'status'
:
0
,
'err_msg'
:
'未知'
...
...
predic_fac.py
View file @
ebf97191
...
...
@@ -14,10 +14,11 @@ class PredictorFac():
self
.
dict_predictor
=
dict_predict
.
DicPredict
(
'dict'
,
extractor
,
classifier
)
def
_get_predictor
(
self
,
data
):
if
isinstance
(
data
,
str
):
return
self
.
kw_predictor
elif
isinstance
(
data
,
dict
):
if
isinstance
(
data
,
dict
):
return
self
.
dict_predictor
else
:
return
self
.
kw_predictor
def
predict
(
self
,
dic_data
,
predict_type
=
'all'
):
predictor
=
self
.
_get_predictor
(
dic_data
)
...
...
@@ -29,7 +30,7 @@ if __name__ == "__main__":
def
get_test_data
():
import
pandas
as
pd
import
json
df
=
pd
.
read_excel
(
r'C:\Users\ICHUNT\Desktop\bomlist\
51AB0571_ CCTV ASST询价_SZIMS.xlsx'
,
header
=
None
,
sheet_name
=
'3'
)
df
=
pd
.
read_excel
(
r'C:\Users\ICHUNT\Desktop\bomlist\
立创.xlsx'
,
header
=
None
)
df
.
fillna
(
'?'
,
inplace
=
True
)
dic_dft
=
df
.
to_dict
(
orient
=
'list'
)
return
json
.
dumps
(
dic_dft
)
...
...
@@ -40,6 +41,7 @@ if __name__ == "__main__":
data
=
get_test_data
()
p
=
PredictorFac
(
model_config
)
data
=
json
.
loads
(
data
)
print
(
data
)
res
=
p
.
predict
(
data
,
predict_type
=
'all'
)
pretty_col
=
{
'第
%
s列'
%
k
:
v
for
k
,
v
in
data
.
items
()}
print
(
pretty_col
)
res
=
p
.
predict
(
pretty_col
,
predict_type
=
'all'
)
print
(
res
)
predict/dict_predict.py
View file @
ebf97191
...
...
@@ -137,7 +137,7 @@ class DicPredict(BasePredictor):
return
model_id_res
def
predict
(
self
,
dic_data
,
predict_type
=
'all'
):
self
.
info
.
info
(
'预测类型为
%
s接收数据: '
%
predict_type
+
str
(
dic_data
))
self
.
info
.
info
(
'预测类型为
:
%
s, 接收数据:
%
s'
%
(
predict_type
,
str
(
dic_data
)
))
dic_data
=
self
.
pre_deal
(
dic_data
)
if
predict_type
==
'all'
:
...
...
predict/kw_predict.py
View file @
ebf97191
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from
predict.base_handler
import
BasePredictor
from
static_config
import
EN_TO_ZH_MAP
class
KwPredict
(
BasePredictor
):
def
predict
(
self
,
key
):
res
,
prab
=
self
.
get_single_predict
(
key
)
def
predict
(
self
,
string
,
predict_type
=
'all'
):
self
.
info
.
info
(
'预测类型为:
%
s, 接收数据:
%
s'
%
(
predict_type
,
string
))
result
,
prab
=
self
.
get_single_predict
(
string
)
zh_prob
=
{
EN_TO_ZH_MAP
[
k
]:
v
for
k
,
v
in
prab
.
items
()}
res
=
{
'result'
:
EN_TO_ZH_MAP
[
result
],
'probably_dict'
:
zh_prob
}
return
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