Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
saturn
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpha
saturn
Commits
f8ef7a8a
Commit
f8ef7a8a
authored
Dec 20, 2018
by
zhanglu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag敏感词检测
parent
c8e872f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
+19
-5
sensitive.py
api/utils/sensitive.py
+12
-4
topic.py
api/views/topic.py
+7
-1
No files found.
api/utils/sensitive.py
View file @
f8ef7a8a
...
...
@@ -44,7 +44,7 @@ class Sensitive(object):
return
res
@classmethod
def
check
(
cls
,
text_list
,
driver
=
DRIVERS
.
YIDUN
):
def
check
(
cls
,
text_list
,
driver
=
DRIVERS
.
YIDUN
,
detail
=
False
):
"""检测"""
endpoint
=
cls
.
endpoint
[
driver
]
...
...
@@ -55,14 +55,18 @@ class Sensitive(object):
spawn
.
run
()
data
=
[]
result
=
{}
if
driver
==
DRIVERS
.
YIDUN
:
for
res
in
spawn
.
result
:
data
.
append
(
cls
.
_yidun_paraser
(
res
))
data
.
append
(
cls
.
_yidun_paraser
(
res
,
False
))
return
data
for
text
,
r
in
(
text_list
,
data
):
result
[
text
]
=
r
return
result
@classmethod
def
_yidun_paraser
(
cls
,
data
):
def
_yidun_paraser
(
cls
,
data
,
detail
=
False
):
"""易盾结果解析"""
# {
# 'code': 200,
...
...
@@ -93,4 +97,8 @@ class Sensitive(object):
for
lable
in
lables
:
hints
.
extend
(
lable
.
get
(
'details'
,
{})
.
get
(
"hint"
))
# 是否需要详细敏感词列表
if
not
detail
:
return
True
if
hints
else
False
return
hints
api/views/topic.py
View file @
f8ef7a8a
...
...
@@ -2,6 +2,7 @@ import json
from
api.views.base_view
import
BaseView
from
libs.sensitive
import
Sensitive
class
CreateTopicForBatch
(
BaseView
):
...
...
@@ -19,15 +20,20 @@ class CreateTopicForBatch(BaseView):
if
not
topic_list
:
return
self
.
ok
()
# TODO: 过滤topic.content敏感词
tag_names
=
[]
for
item
in
topic_list
:
tag_names
.
extend
(
item
.
get
(
"tags"
,
[]))
item
[
"user_id"
]
=
user_id
check_info
=
Sensitive
.
check
(
list
(
filter
(
None
,
set
(
tag_names
))))
tags
=
check_info
.
values
()
# 先创建标签
_tag_error
,
_tag_data
=
self
.
call_rpc
(
"venus/community/tag/batch_create_tag_by_name"
,
tag_names
=
list
(
filter
(
None
,
set
(
tag_names
))
)
tag_names
=
list
(
tags
)
)
if
_tag_error
:
return
self
.
error
(
_tag_error
)
...
...
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