示例#1
0
 def get(self: Resource, args: typing.Dict) -> typing.Tuple[typing.Dict, int]:
     items = MarkJobService().get_mark_job_data_by_ids(args["mark_job_ids"], args, doc_type_key="entity_doc_type", prefix='RE')
     return {
                "message": "请求成功",
                "result": items,
                "count": len(items),
            }, 200
示例#2
0
    def post(self: Resource, args: typing.Dict) -> typing.Tuple[typing.Dict, int]:
        MarkJobService().delete_mark_jobs(args["job_ids"])

        return {
                   "message": "批量删除成功",
                   "result": args
               }, 200
示例#3
0
    def post(self: Resource, args: typing.Dict) -> typing.Tuple[typing.Dict, int]:
        """
        message queue回调统一入口
        """
        message = args['message']
        logger.info(f"receive callback info from mq. response is: {json.dumps(args)}")

        if message['business'] in [
            'label',  # 实体预标注
            'classify_label',  # 分类预标注
            'relation_label',  # 实体关系预标注
            'wordseg_label'  # 分词预标注
        ]:
            update_params = {}
            if args.get("task_state"):
                if args['task_state'] == 'success':     # 如果mq预标注返回成功,则初试状态是unlabel
                    update_params.update(mark_task_status=int(StatusEnum.unlabel))
                else:   # 如果mq预标注返回失败,则初试状态是fail
                    update_params.update(mark_task_status=int(StatusEnum.fail))
            if args.get("task_result"):
                update_params.update(mark_task_result=args["task_result"])
            mark_task, user_task_list = MarkJobService()\
                .update_mark_task_and_user_task_by_mark_task_id(mark_task_id=message["task_id"], args=update_params)
            MarkJobService().update_mark_job_status_by_mark_task(mark_task=mark_task)
            result = UserTaskSchema(many=True).dump(user_task_list)
            return {
                       "message": "更新成功",
                       "result": result,
                   }, 201
        elif message['business'] in [
            'extract',  # 实体抽取
            'classify_extract',  # 分类抽取
            'relation_extract',  # 实体关系抽取
            'wordseg_extract'  # 分词抽取
        ]:
            update_params = {}
            if args.get("task_state"):
                update_params.update(predict_task_status=status_str2int_mapper()[args["task_state"]])
            if args.get("task_result"):
                update_params.update(predict_task_result=args["task_result"])
            predict_task = PredictService().update_predict_task_by_id(predict_task_id=message["task_id"], args=update_params)
            result = PredictTaskSchema().dump(predict_task)
            return {
                       "message": "更新成功",
                       "result": result,
                   }, 201
示例#4
0
 def post(self: Resource,
          args: typing.Dict) -> typing.Tuple[typing.Dict, int]:
     mark_job_ids = args['mark_job_ids'].split(',')
     MarkJobService().re_pre_label_mark_job(mark_job_ids,
                                            nlp_task=NlpTaskEnum.wordseg)
     return {
         "message": "请求成功",
     }, 200
示例#5
0
 def get(self: Resource,
         args: typing.Dict) -> typing.Tuple[typing.Dict, int]:
     count, result = MarkJobService().get_mark_job_list_by_nlp_task(
         args, NlpTaskEnum.relation)
     return {
         "message": "请求成功",
         "result": result,
         "count": count,
     }, 200
示例#6
0
 def get(
         self: Resource,
         job_id: int
 ) -> typing.Tuple[typing.Dict, int]:
     file_path = MarkJobService().export_mark_file(nlp_task_id=int(NlpTaskEnum.classify), mark_job_id=job_id)
     return {
                "message": "请求成功",
                "file_path": file_path
            }, 200
示例#7
0
 def post(self: Resource, args: typing.Dict):
     files = args['files']
     args['task_type'] = 'manual'
     # validate file extensions
     for f in files:
         if get_ext(f.filename) not in ["txt"]:
             abort(400, message="导入已标注序列标注数据仅支持txt格式。")
     result = MarkJobService().import_mark_job(files, args, nlp_task=NlpTaskEnum.extract)
     return {
                "message": "创建成功",
                "result": result
            }, 201
示例#8
0
    def post(self: Resource,
             args: typing.Dict) -> typing.Tuple[typing.Dict, int]:
        files = args['files']
        job_type = Common().check_job_type_by_files(files)
        if not job_type:
            abort(400, message='请上传全部纯文本文档(txt/csv)或者全部电子文档(pdf/word文档)')
        else:
            args['mark_job_type'] = job_type

        result = MarkJobService().create_mark_job(files, NlpTaskEnum.relation,
                                                  args)

        return {"message": "创建成功", "result": result}, 201
示例#9
0
 def post(
         self: Resource,
         args: typing.Dict
 ) -> typing.Tuple[typing.Dict, int]:
     try:
         file_path = MarkJobService().export_multi_mark_file(
             nlp_task_id=int(NlpTaskEnum.classify), mark_job_id_list=args["job_ids"])
         return {
                    "message": "请求成功",
                    "file_path": file_path
                }, 200
     except ValueError as e:
         abort(400, message=e.args[0])
示例#10
0
 def post(self: Resource,
          args: typing.Dict) -> typing.Tuple[typing.Dict, int]:
     """
     上传已标注数据
     """
     files = args['files']
     # validate file extensions
     for f in files:
         if get_ext(f.filename) not in ["txt"]:
             abort(400, message="上传已标注分词数据仅支持txt格式。")
     result = MarkJobService().import_mark_job(files,
                                               args,
                                               nlp_task=NlpTaskEnum.wordseg)
     return {"message": "创建成功", "result": result}, 201
示例#11
0
 def post(self: Resource,
          args: typing.Dict) -> typing.Tuple[typing.Dict, int]:
     files = args["files"]
     assign_mode = args["assign_mode"]
     if assign_mode == AssignModeEnum.together:
         abort(400, message="不支持共同标注")
     job_type = Common().check_job_type_by_files(files)
     if job_type != "text":
         abort(400, message="请上传纯文本文档(txt/csv)")
     else:
         args['mark_job_type'] = job_type
     try:
         result = MarkJobService().create_mark_job(files,
                                                   NlpTaskEnum.wordseg,
                                                   args)
         return {"message": "创建成功", "result": result}, 201
     except TypeError:
         abort(400, message="上传文件类型错误")
示例#12
0
 def post(
         self: Resource,
         args: typing.Dict
 ) -> typing.Tuple[typing.Dict, int]:
     files = args['files']
     for f in files:
         if get_ext(f.filename) not in ["csv"]:
             abort(400, message="已标注分类数据仅支持csv格式。")
     try:
         result = MarkJobService().import_mark_job(files, args, nlp_task=NlpTaskEnum.classify)
         return {
                    "message": "创建成功",
                    "result": result
                }, 201
     except UnicodeDecodeError:
         abort(400, message="文件编码错误 请上传utf-8编码文件")
     except KeyError:
         abort(400, message="文件格式不合规 请查看csv文件模版")
示例#13
0
    def delete(self: Resource, job_id: int) -> typing.Tuple[typing.Dict, int]:
        MarkJobService().delete_mark_job(job_id)

        return {
            "message": "删除成功",
        }, 200
示例#14
0
 def post(self: Resource,
          args: typing.Dict) -> typing.Tuple[typing.Dict, int]:
     MarkJobService.delete_mark_jobs(args['job_ids'])
     return {
         "message": "删除成功",
     }, 200