Пример #1
0
 def post(self, *args, **kwargs):
     response = self.request.data['response']
     template = self.request.data['template']
     project = get_object_or_404(Project, pk=self.kwargs['project_id'])
     task = TaskFactory.create(project.project_type)
     template = MappingTemplate(label_collection=task.label_collection,
                                template=template)
     labels = template.render(response)
     if not labels.dict():
         raise SampleDataException()
     return Response(labels.dict(), status=status.HTTP_200_OK)
Пример #2
0
 def post(self, *args, **kwargs):
     response = self.request.data["response"]
     template = self.request.data["template"]
     task_type = self.request.data["task_type"]
     label_collection = get_label_collection(task_type)
     template = MappingTemplate(label_collection=label_collection,
                                template=template)
     try:
         labels = template.render(response)
     except json.decoder.JSONDecodeError:
         raise TemplateMappingError()
     if not labels.dict():
         raise SampleDataException()
     return Response(labels.dict(), status=status.HTTP_200_OK)
def pipeline(text: str, request_model: RequestModel,
             mapping_template: MappingTemplate,
             post_processing: BasePostProcessor) -> Labels:
    response = request_model.send(text)
    labels = mapping_template.render(response)
    labels = post_processing.transform(labels)
    return labels
Пример #4
0
def execute_pipeline(text: str, project_type: str, model_name: str,
                     model_attrs: dict, template: str, label_mapping: dict):
    task = TaskFactory.create(project_type)
    model = RequestModelFactory.create(model_name=model_name,
                                       attributes=model_attrs)
    template = MappingTemplate(label_collection=task.label_collection,
                               template=template)
    post_processor = PostProcessor(label_mapping)
    labels = pipeline(text=text,
                      request_model=model,
                      mapping_template=template,
                      post_processing=post_processor)
    return labels.dict()
Пример #5
0
def execute_pipeline(data: str, config: AutoLabelingConfig):
    label_collection = get_label_collection(config.task_type)
    model = RequestModelFactory.create(model_name=config.model_name,
                                       attributes=config.model_attrs)
    template = MappingTemplate(label_collection=label_collection,
                               template=config.template)
    post_processor = PostProcessor(config.label_mapping)
    labels = pipeline(text=data,
                      request_model=model,
                      mapping_template=template,
                      post_processing=post_processor)
    labels = create_labels(config.task_type, labels)
    return labels