class PredictTaskSchema(Schema): doc_type = fields.Nested(DocTypeSchema) doc = fields.Nested(DocSchema) task_id = fields.Integer(attribute="predict_task_id") task_result = fields.Dict(attribute="predict_task_result") task_state = fields.Function( lambda obj: StatusEnum(obj.predict_task_status).name) created_time = fields.DateTime()
class PredictJobSchema(Schema): doc_type = fields.Nested(DocTypeSchema) task_list = fields.List(fields.Nested(PredictTaskSchema)) extract_job_id = fields.Integer(attribute="predict_job_id") extract_job_name = fields.String(attribute="predict_job_name") extract_job_type = fields.String(attribute="predict_job_type.value") extract_job_state = fields.Function(lambda obj: StatusEnum(obj.predict_job_status).name) extract_job_desc = fields.String(attribute="predict_job_desc") is_batch = fields.Boolean() created_time = fields.DateTime()
class TrainJobSchema(Schema): # type: ignore model_id = fields.Integer(attribute='train_job_id') model_name = fields.String(attribute="train_job_name") model_desc = fields.String(attribute="train_job_desc") status = fields.Function(lambda obj: not obj.is_deleted) doc_type = fields.Nested(DocTypeSchema) created_time = fields.String() model_version = fields.String() train_list = fields.List(fields.Nested(TrainTaskSchema)) model_evaluate = fields.Nested(EvaluateTaskSchema) preprocess = fields.Dict()
class DocTypeSchema(Schema): doc_terms = fields.List(fields.Integer()) doc_term_list = fields.List(fields.Nested(DocTermSchema)) doc_relation_list = fields.List(fields.Nested(EntityDocRelationSchema)) doc_lexicon_list = fields.List(fields.Nested(WordsegDocLexiconSchema), attribute='doc_rules') doc_type_id = fields.Integer() doc_type_name = fields.String() doc_type_desc = fields.String() is_top = fields.Boolean(attribute="is_favorite") created_time = fields.DateTime() group_id = fields.Integer() status = fields.Function(lambda obj: not obj.is_deleted)
class MarkTaskSchema(Schema): # type: ignore task_id = fields.Integer(attribute="mark_task_id") doc = fields.Nested(DocSchema) doc_type = fields.Nested({ "doc_type_id": fields.Integer(), "doc_type_name": fields.String(), "doc_type_desc": fields.String(), }) user_task_list = fields.List(fields.Nested(UserTaskSchema)) task_state = fields.Function( lambda obj: StatusEnum(obj.mark_task_status).name) status = fields.Function(lambda obj: not obj.is_deleted) created_time = fields.String() task_result = fields.List(fields.Dict, attribute="mark_task_result")
class UserTaskSchema(Schema): doc = fields.Nested(DocSchema) doc_type = fields.Nested({ "doc_type_id": fields.Integer(), "doc_type_name": fields.String(), "doc_type_desc": fields.String(), }) task_id = fields.Integer(attribute="user_task_id") labeler_id = fields.Integer(attribute="annotator_id") manual_task_id = fields.Integer(attribute="mark_task_id") task_result = fields.List(fields.Dict, attribute="user_task_result") task_state = fields.Function( lambda obj: StatusEnum(obj.user_task_status).name) status = fields.Function(lambda obj: not obj.is_deleted) created_time = fields.String()
class MarkJobSchema(Schema): mark_job_id = fields.Integer() mark_job_name = fields.String() mark_job_type = fields.Function(lambda obj: obj.mark_job_type.value) assign_mode = fields.Function(lambda obj: obj.assign_mode.value) mark_job_state = fields.Function( lambda obj: StatusEnum(obj.mark_job_status).name) mark_job_desc = fields.String() task_list = fields.List(fields.Integer()) created_time = fields.DateTime() assessor_id = fields.Function(lambda obj: obj.reviewer_ids[0] if len(obj.reviewer_ids) > 0 else 0) doc_type = fields.Nested(DocTypeSchema, exclude=('doc_term_list', )) labeler_ids = fields.List(fields.Integer(), attribute='annotator_ids') stats = fields.Nested({ "all": fields.Integer(), "labeled": fields.Integer(), "audited": fields.Integer() })
class TrainTaskSchema(Schema): # type: ignore model_train_id = fields.Integer(attribute="train_task_id") model_train_config = fields.Dict(attribute="train_config") model_train_state = fields.Function( lambda obj: StatusEnum(obj.train_status).name) model_id = fields.Integer(attribute="train_job_id") mark_job_ids = fields.List(fields.Integer()) train_terms = fields.List(fields.Nested(TrainTermTaskSchema)) created_time = fields.DateTime() last_updated_time = fields.DateTime(attribute="updated_time") model_version = fields.String()
class DocTermSchema(Schema): doc_lexicon_list = fields.List(fields.Nested(WordsegDocLexiconSchema), attribute='doc_rules') doc_term_id = fields.Integer() doc_term_name = fields.String() doc_term_alias = fields.String() doc_term_index = fields.Integer() doc_term_color = fields.String() doc_term_desc = fields.String() doc_term_data_type = fields.String() doc_term_shortcut = fields.String()
class DocTypeListResource(Resource, CurrentUserMixin): @parse({ "offset": fields.Integer(missing=0), "limit": fields.Integer(missing=10), "mark_job_ids": fields.List(fields.Integer(), missing=[]), "is_online": fields.Integer() }) def get(self: Resource, args: typing.Dict) -> typing.Tuple[typing.Dict, int]: """ 获取所有文档条款 :param args: :return: """ nlp_task_id = Common().get_nlp_task_id_by_route() args.update({ 'nlp_task_id': nlp_task_id }) result, count = DocTypeService().get_doc_type(self.get_current_user(), args) return { "message": "请求成功", "result": result, "count": count, }, 200 @parse({ "doc_type_name": fields.String(required=True), "doc_type_desc": fields.String(), "group_id": fields.Integer(default=-1), "doc_term_list": fields.List(fields.Nested({ "doc_term_name": fields.String(required=True), "doc_term_alias": fields.String(default=""), "doc_term_shortcut": fields.String(default="", validate=lambda x: len(x) < 2), "doc_term_color": fields.String(required=True), "doc_term_index": fields.Integer(required=False), "doc_term_desc": fields.String(required=False, allow_none=True), "doc_term_data_type": fields.String(default=""), }), missing=[]) }) def post(self: Resource, args: typing.Dict) -> typing.Tuple[typing.Dict, int]: """ 创建一个文档类型包括它的条款 """ args.update({'nlp_task_id': Common().get_nlp_task_id_by_route()}) args.update({"group_id": self.get_current_user().user_groups[0]}) result = DocTypeService().create_doc_type(self.get_current_user(), args) return { "message": "创建成功", "result": result, }, 201
class DocTypeItemResource(Resource, CurrentUserMixin): def get(self: Resource, doc_type_id: int) -> typing.Tuple[typing.Dict, int]: """ 获取一个文档类型 """ result = DocTypeService().get_doc_type_items(doc_type_id) return { "message": "请求成功", "result": result, }, 200 @parse({ "doc_type_name": fields.String(), "doc_type_desc": fields.String(), "doc_term_list": fields.List(fields.Nested({ "doc_term_name": fields.String(required=True), "doc_term_alias": fields.String(default=""), "doc_term_color": fields.String(required=True), "doc_term_index": fields.Integer(required=False, allow_none=True), "doc_term_shortcut": fields.String(default=""), "doc_term_id": fields.Integer(required=False), "doc_term_desc": fields.String(required=False, allow_none=True), "doc_term_data_type": fields.String(default="String"), })) }) def patch(self: Resource, args: typing.Dict, doc_type_id: int) -> typing.Tuple[typing.Dict, int]: """ 修改一个文档类型,不包括修改它的条款 """ result = DocTypeService().update_doc_type(args, doc_type_id) return { "message": "更新成功", "result": result, }, 201 def delete(self: Resource, doc_type_id: int) -> typing.Tuple[typing.Dict, int]: """ 删除一个文档类型 """ DocTypeService().delete_doc_type(doc_type_id) return { "message": "删除成功", }, 204