def handle_upload(request, doc_id): if not request.user.is_authenticated(): raise PermissionDenied( "You do not have permission to perform this action.") page = request.POST['next'] has_headers = request.POST['has_headers'] start = 1 if has_headers else 0 # try: t = [i.strip('\r\n') for i in request.FILES['InputFile'].readlines()] # f = codecs.open('/home/elmira/heritage_corpus/tempfiles/request.txt', 'w') # prevsent = 0 # wordn = 1 for ln in range(start, len(t)): sent, word, wordnum, _, _, tag, corr, annotator = t[ln].split('\t') sent = int(sent) # if word == ' ': # continue # if sent == prevsent: # wordn += 1 # else: # prevsent = sent # wordn = 1 if tag: tag1 = [i.strip() for i in tag.split(',')] # f.write(str(len(word.decode('utf-8')))) # f.write('\r\n') sent = Sentence.objects.get(pk=sent) owner = User.objects.get(username=annotator) annot = Annotation(owner=owner, document=sent, guid=str(uuid.uuid4()), data=json.dumps({ "ranges": [{ "start": "/span[" + wordnum + "]", "end": "/span[" + wordnum + "]", "startOffset": 0, "endOffset": len(word.decode('utf-8')) }], "quote": word, "text": "", "tags": tag1, "corrs": corr })) annot.tag = tag annot.start, annot.end = int(wordnum), int(wordnum) annot.save() a = False # f.close() # except: # a = True return redirect(page, alert=a)
def handle_upload(request, doc_id): if not request.user.is_authenticated(): raise PermissionDenied( "You do not have permission to perform this action.") page = request.POST['next'] has_headers = request.POST['has_headers'] start = 1 if has_headers else 0 t = [i.strip('\r\n') for i in request.FILES['InputFile'].readlines()] for ln in range(start, len(t)): sent, word, wordnum, _, _, tag, corr, annotator = t[ln].split('\t') sent = int(sent) if tag: tag1 = [i.strip() for i in tag.split(',')] sent = Sentence.objects.get(pk=sent) owner = User.objects.get(username=annotator) annot = Annotation(owner=owner, document=sent, guid=str(uuid.uuid4()), data=json.dumps({ "ranges": [{ "start": "/span[" + wordnum + "]", "end": "/span[" + wordnum + "]", "startOffset": 0, "endOffset": len(word.decode('utf-8')) }], "quote": word, "text": "", "tags": tag1, "corrs": corr })) annot.tag = tag annot.start, annot.end = int(wordnum), int(wordnum) annot.save() a = False return redirect(page, alert=a)
def handle_upload(request, doc_id): if not request.user.is_authenticated(): raise PermissionDenied("You do not have permission to perform this action.") page = request.POST['next'] has_headers = request.POST['has_headers'] start = 1 if has_headers else 0 # try: t = [i.strip('\r\n') for i in request.FILES['InputFile'].readlines()] # f = codecs.open('/home/elmira/heritage_corpus/tempfiles/request.txt', 'w') # prevsent = 0 # wordn = 1 for ln in range(start, len(t)): sent, word, wordnum, _, _, tag, corr, annotator = t[ln].split('\t') sent = int(sent) # if word == ' ': # continue # if sent == prevsent: # wordn += 1 # else: # prevsent = sent # wordn = 1 if tag: tag1 = [i.strip() for i in tag.split(',')] # f.write(str(len(word.decode('utf-8')))) # f.write('\r\n') sent = Sentence.objects.get(pk=sent) owner = User.objects.get(username=annotator) annot = Annotation(owner=owner, document=sent, guid=str(uuid.uuid4()), data=json.dumps({"ranges": [{"start": "/span["+wordnum+"]", "end": "/span["+wordnum+"]", "startOffset": 0, "endOffset": len(word.decode('utf-8'))}], "quote": word, "text": "", "tags": tag1, "corrs": corr})) annot.tag = tag annot.start, annot.end = int(wordnum), int(wordnum) annot.save() a = False # f.close() # except: # a = True return redirect(page, alert=a)