def newAnnotation(request): document_id=int(request.POST['document_id']) text=request.POST['newNec'] annotation_id=int(request.POST['newNecCategoryId']) if annotation_id == 'Delete': return documentByAnnotator(request, document_id, annotator_id=request.user.id, error=None) if not text: return documentByAnnotator(request, document_id, annotator_id=request.user.id, error="Please select text to add new anntations") annotator=Annotator.objects.get(id=request.user.id) annotation_type=AnnotationType.objects.get(id=int(annotation_id)) document=Document.objects.get(id=document_id) annotations = Annotation.objects.filter(document=document, annotator=annotator) indices=util.findIndices(document.text, text) for ind in indices: if Annotation.objects.filter(document=document, begin_index=ind[0], end_index=ind[1], annotator=annotator): continue begin=ind[0] end=ind[1] allNamedEntities=Annotation.objects.filter(document=document, annotator=annotator) for absNE in allNamedEntities: if util.overlap((absNE.begin_index, absNE.end_index), (ind[0],ind[1])): absNE.delete() #add new one annotation = Annotation(document=document, annotation=text, begin_index=begin, end_index=end, annotation_type=annotation_type, annotator=annotator) annotation.save() return documentByAnnotator(request, document_id, annotator_id=request.user.id, error=None)
def newAnnotation(request): #import pdb #pdb.set_trace() document_id=int(request.POST['document_id']) text=request.POST['newNec'] annotation_id=int(request.POST['newNecCategoryId']) if annotation_id == 'Delete': return documentByAnnotator(request, document_id, annotator_id=request.user.id, error=None) if not text: return documentByAnnotator(request, document_id, annotator_id=request.user.id, error="Please select text to add new anntations") annotator=Annotator.objects.get(id=request.user.id) annotation_type=AnnotationType.objects.get(id=int(annotation_id)) document=Document.objects.get(id=document_id) annotations = Annotation.objects.filter(document=document, annotator=annotator) indices=util.findIndices(document.text, text) for ind in indices: if Annotation.objects.filter(document=document, begin_index=ind[0], end_index=ind[1], annotator=annotator): continue begin=ind[0] end=ind[1] allNamedEntities=Annotation.objects.filter(document=document, annotator=annotator) foundOverlap = False for absNE in allNamedEntities: if util.overlap((absNE.begin_index, absNE.end_index), (ind[0],ind[1])): foundOverlap = True #absNE.delete() # blah! # don't erase any existing entities if foundOverlap: continue #add new one annotation = Annotation(document=document, annotation=text, begin_index=begin, end_index=end, annotation_type=annotation_type, annotator=annotator) annotation.save() annotations = Annotation.objects.filter(document=document, annotator=annotator) text=util.htmlFormat(document.text, annotations) #return documentByAnnotator(request, document_id, annotator_id=request.user.id, error=None) return HttpResponse(text)
def newAnnotation(request): #import pdb #pdb.set_trace() document_id = int(request.POST['document_id']) text = request.POST['newNec'] annotation_id = int(request.POST['newNecCategoryId']) if annotation_id == 'Delete': return documentByAnnotator(request, document_id, annotator_id=request.user.id, error=None) if not text: return documentByAnnotator( request, document_id, annotator_id=request.user.id, error="Please select text to add new anntations") annotator = Annotator.objects.get(id=request.user.id) annotation_type = AnnotationType.objects.get(id=int(annotation_id)) document = Document.objects.get(id=document_id) annotations = Annotation.objects.filter(document=document, annotator=annotator) indices = util.findIndices(document.text, text) for ind in indices: if Annotation.objects.filter(document=document, begin_index=ind[0], end_index=ind[1], annotator=annotator): continue begin = ind[0] end = ind[1] allNamedEntities = Annotation.objects.filter(document=document, annotator=annotator) foundOverlap = False for absNE in allNamedEntities: if util.overlap((absNE.begin_index, absNE.end_index), (ind[0], ind[1])): foundOverlap = True #absNE.delete() # blah! # don't erase any existing entities if foundOverlap: continue #add new one annotation = Annotation(document=document, annotation=text, begin_index=begin, end_index=end, annotation_type=annotation_type, annotator=annotator) annotation.save() annotations = Annotation.objects.filter(document=document, annotator=annotator) text = util.htmlFormat(document.text, annotations) #return documentByAnnotator(request, document_id, annotator_id=request.user.id, error=None) return HttpResponse(text)