Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Commit

Permalink
Add: Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amant555 committed Jun 23, 2021
1 parent c2baa28 commit 35d0554
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions label_studio/tasks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_serializer_class(self):
# POST, PATCH, PUT
else:
return TaskSimpleSerializer

def retrieve(self, request, *args, **kwargs):
task = self.get_object()

Expand All @@ -99,10 +99,10 @@ def retrieve(self, request, *args, **kwargs):
proxy = bool_from_request(request.GET, 'proxy', True)
result['data'] = task.resolve_uri(result['data'], proxy=proxy)
return Response(result)

@swagger_auto_schema(tags=['Tasks'], manual_parameters=[
openapi.Parameter(name='proxy', type=openapi.TYPE_BOOLEAN, in_=openapi.IN_QUERY,
description='Use the proxy parameter inline for credential access to task data')
openapi.Parameter(name='proxy', type=openapi.TYPE_BOOLEAN, in_=openapi.IN_QUERY,
description='Use the proxy parameter inline for credential access to task data')
])
def get(self, request, *args, **kwargs):
return super(TaskAPI, self).get(request, *args, **kwargs)
Expand Down Expand Up @@ -165,26 +165,38 @@ def struct(start, end, label, text):
"to_name": "text", "type": "labels"}
return data

def de_duplicate(list1):
list2 = []
for i in list1:
if i not in list2:
list2.append(i)
return list2

def fetch_diff(list1, list2):
list3 = []
for i in list1:
if not i in list2:
list3.append(i)
return list3

obj = get_object_with_check_and_log(request, Annotation, pk=annotation_id)
last_update = copy.deepcopy(obj.result)
text = copy.deepcopy(obj.task.data['text'])
draft = copy.deepcopy(request.data['result'])
deleted = []
added = []
for i in draft:
if not i in last_update:
added.append(i)
for i in last_update:
if not i in draft:
deleted.append(i)
deleted = []#fetch_diff(last_update, draft)
added = fetch_diff(draft, last_update)
new_draft = []
for deleted_annotation in deleted:
for i in draft:
if not deleted_annotation['value']['text'] == i['value']['text']:
if not '@'.join(
[deleted_annotation['value']['text'],
deleted_annotation['value']['labels'][0]]).strip() == '@'.join(
[i['value']['text'], i['value']['labels'][0]]).strip():
new_draft.append(i)
if not new_draft:
# import pdb;pdb.set_trace()
if not new_draft and not deleted:
new_draft = draft
for annotation in tqdm(added):
for annotation in tqdm(added): # ToDo Remove duplicate from added
annotated_text = annotation['value']['text']
label = annotation['value']['labels'][0]
original_start = annotation['value']['start']
Expand All @@ -195,10 +207,7 @@ def struct(start, end, label, text):
end = found.span()[1]
if start != original_start and end != original_end:
new_draft.append(struct(start, end, label, annotated_text))
request.data['result'] = []
for i in new_draft:
if i not in request.data['result']:
request.data['result'].append(i)
request.data['result'] = de_duplicate(new_draft)
return request

def update(self, request, *args, **kwargs):
Expand Down Expand Up @@ -226,7 +235,7 @@ def patch(self, request, *args, **kwargs):
def delete(self, request, *args, **kwargs):
return super(AnnotationAPI, self).delete(request, *args, **kwargs)


class AnnotationsListAPI(RequestDebugLogMixin, generics.ListCreateAPIView):
"""
get:
Expand Down Expand Up @@ -310,7 +319,6 @@ def perform_create(self, ser):


class AnnotationDraftListAPI(RequestDebugLogMixin, generics.ListCreateAPIView):

parser_classes = (JSONParser, MultiPartParser, FormParser)
serializer_class = AnnotationDraftSerializer
permission_required = ViewClassPermission(
Expand All @@ -337,7 +345,6 @@ def perform_create(self, serializer):


class AnnotationDraftAPI(RequestDebugLogMixin, generics.RetrieveUpdateDestroyAPIView):

parser_classes = (JSONParser, MultiPartParser, FormParser)
serializer_class = AnnotationDraftSerializer
queryset = AnnotationDraft.objects.all()
Expand Down

0 comments on commit 35d0554

Please sign in to comment.