Commit f8ef7a8a authored by zhanglu's avatar zhanglu

tag敏感词检测

parent c8e872f8
......@@ -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
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment