def validate_user(self): user_id = access_control.get_current_user_id() if not user_id: self.redirect(users.create_login_url(self.request.uri)) return False if not may_see_home_view(user_id): self.response.write( 'User ' + user_id + ' is not allowed to access this page! <a href="' + users.create_logout_url( '/argunit/home') + '">Logout</a>') return False return True
def validate_user(self): user_id = access_control.get_current_user_id() if not user_id: self.redirect(users.create_login_url(self.request.uri)) return False if not may_see_home_view(user_id): self.response.write( 'User ' + user_id + ' is not allowed to access this page! <a href="' + users.create_logout_url('/argunit/home') + '">Logout</a>') return False return True
def post(self): if not self.validate_user(): return user_id = access_control.get_current_user_id() if self.request.path.endswith('nextdoc'): json_req = json.loads(self.request.body) self.respond_with_next_document(user_id, json_req) elif self.request.path.endswith('previousdoc'): json_req = json.loads(self.request.body) self.respond_with_previous_document(user_id, json_req) elif self.request.path.endswith('setapproval'): json_req = json.loads(self.request.body) annotator = json_req['annotator'] document = json_req['document'] isApproved = json_req['approved'] ManageDataHandler().setApproval(annotator, document, isApproved) self.response.headers['Content-Type'] = 'application/json' self.response.write(json.dumps({'message': "0"}))
def get(self): if not self.validate_user(): return user_id = access_control.get_current_user_id() if self.request.path.endswith('/compare'): user_data = load_user_data(user_id) topics = user_data.selected_topics documents_sorted_by_id = get_docs_in_topics_by_id(topics); template_values = {'user': user_id, 'logout_url': users.create_logout_url('/argunit/'), 'all_views': access_control.get_view_ids(user_id), 'current_view': access_control.COMPARE_VIEW_ID} if not documents_sorted_by_id: template_values.update({'has_document': False, 'message': "No documents in collection"}) else: doc_filename = self.request.get('doc', None) doc = mark_as_current_doc(user_id, doc_filename, documents_sorted_by_id[0]) all_users = sorted(access_control.get_all_users()) print(all_users) annotator_id_1 = self.request.get("annotator1") if not annotator_id_1: annotator_id_1 = all_users[0] annotator_id_2 = self.request.get("annotator2") if not annotator_id_2: annotator_id_2 = all_users[1] showAnnotator3 = self.request.get("showAnnotator3") != '' annotator_id_3 = self.request.get("annotator3") if not annotator_id_3: annotator_id_3 = all_users[2] opening_time = time.strftime("%H:%M:%S %Z", time.localtime()) current_topic = get_current_topic(user_id) all_topics = get_all_topics() annotation1 = self.load_annotations(annotator_id_1, doc) annotation2 = self.load_annotations(annotator_id_2, doc) annotation3 = self.load_annotations(annotator_id_3, doc) arg_units1 = annotation1.arg_units if annotation1 else [] arg_units2 = annotation2.arg_units if annotation2 else [] arg_units3 = annotation3.arg_units if annotation3 else [] approved1 = annotation1.approved if annotation1 else False approved2 = annotation2.approved if annotation2 else False approved3 = annotation3.approved if annotation3 else False notes1 = annotation1.notes if annotation1 else "" notes2 = annotation2.notes if annotation2 else "" notes3 = annotation3.notes if annotation3 else "" template_values.update({'navigation_docs': documents_sorted_by_id, 'documents_sorted_by_id': documents_sorted_by_id, 'text': doc.text, 'doc_url': doc.url, 'doc_filename': doc.filename, 'num_sentences': doc.num_sentences, 'num_tokens': doc.num_tokens, 'time': opening_time, 'showAnnotator3': showAnnotator3, 'annotator1': annotator_id_1, 'annotator2': annotator_id_2, 'annotator3': annotator_id_3, 'approved1': approved1, 'approved2': approved2, 'approved3': approved3, 'arg_units1': json.dumps(arg_units1), 'arg_units2': json.dumps(arg_units2), 'arg_units3': json.dumps(arg_units3), 'notes1': notes1, 'notes2': notes2, 'notes3': notes3, 'current_topic': current_topic, 'all_topics': all_topics, 'all_users': all_users, 'has_document': True, 'message': ""}) template = JINJA_ENVIRONMENT.get_template('compare.html') self.response.write(template.render(template_values)) elif self.request.path.endswith('/selecttopic'): topics = self.request.get_all('topic', None) annotator1 = self.request.get('annotator1'); annotator2 = self.request.get('annotator2'); annotator3 = self.request.get('annotator3'); set_as_current_topics(user_id, topics) self.redirect('/argunit/compare' + "?annotator1=" + annotator1 + "&annotator2=" + annotator2 + "&annotator3=" + annotator3)
def get(self): if not self.validate_user(): return if self.request.path.endswith('/annotate'): user_id = access_control.get_current_user_id() # Allow to take the role of another user if self.request.get('user', None) in access_control.get_all_users(): user_id = self.request.get('user', None) documents_sorted_by_id = get_docs_ordered_by_id(user_id); processing_state = get_processing_state(user_id) # Per user_id annotation statistics num_annotated, num_approved = self.get_evaluation_stats() template_values = {'user': user_id, 'logout_url': users.create_logout_url('/argunit/'), 'all_views': access_control.get_view_ids(user_id), 'current_view': access_control.ANNOTATE_VIEW_ID} if not documents_sorted_by_id: template_values.update({ 'has_document': False, 'navigation_docs': [], 'num_annotated': num_annotated, 'num_approved': num_approved, 'message': "No documents to display." }) else: doc_filename = self.request.get('doc', None) doc = mark_as_current_doc(user_id, doc_filename, documents_sorted_by_id[0]) topics = get_all_topics() current_topic = get_current_topic(user_id) opening_time = time.strftime("%H:%M:%S %Z", time.localtime()) docs_with_processing_state = [(d, processing_state[d.filename]) for d in documents_sorted_by_id] # Get arg_units to show arg_units = [] relations = [] concepts = [] doc_approved = False notes = "" personal_annotations = DocumentAnnotation.all().filter('user_id =', user_id).filter( 'document =', doc.filename).get() if personal_annotations: doc_approved = personal_annotations.approved notes = personal_annotations.notes arg_units = [str(item) for item in personal_annotations.arg_units] relations = [str(item) for item in personal_annotations.relations] concepts = [str(item) for item in personal_annotations.concepts] template_values.update({'navigation_docs': docs_with_processing_state, 'documents_sorted_by_id': documents_sorted_by_id, 'text': doc.text, 'doc_url': doc.url, 'doc_filename': doc.filename, 'doc_approved': doc_approved, 'num_sentences': doc.num_sentences, 'num_tokens': doc.num_tokens, 'time': opening_time, 'arg_units': json.dumps(arg_units), 'relations': json.dumps(relations), 'concepts': json.dumps(concepts), 'all_topics': topics, 'current_topic': current_topic, 'num_annotated': num_annotated, 'num_approved': num_approved, 'notes': notes, 'has_document': True, 'message': ""}) template = JINJA_ENVIRONMENT.get_template('annotate.html') self.response.write(template.render(template_values)) elif self.request.path.endswith('/selecttopic'): user_id = access_control.get_current_user_id() topics = self.request.get_all('topic', None) set_as_current_topics(user_id, topics) self.redirect('/argunit/annotate')
def get(self): user_id = access_control.get_current_user_id() if not self.validate_user(): return elif self.request.path.endswith('dump'): self.dump_corpus() elif self.request.path.endswith('dropall'): self.drop_all_data() self.redirect( '%s?%s' % (self.base_path(), urllib.urlencode({"message": 'Dropped all data.'}))) elif self.request.path.endswith('dropanno'): self.drop_all_annotations() self.redirect('%s?%s' % ( self.base_path(), urllib.urlencode({"message": 'Dropped all annotations.'}))) elif self.request.path.endswith('loaddata'): response_text = self.load_documents() self.redirect( '%s?%s' % (self.base_path(), urllib.urlencode({"verbatim_message": response_text}))) elif self.request.path.endswith('forceupdate'): response_text = self.load_documents(force_update=True) self.redirect( '%s?%s' % (self.base_path(), urllib.urlencode({"verbatim_message": response_text}))) elif self.request.path.endswith('unapprove'): annotator = self.request.get("annotator") document = self.request.get("doc") self.setApproval(annotator, document, False); response_text = "Unapproved: %s:%s" % (annotator, document) self.redirect( '%s?%s' % (self.base_path(), urllib.urlencode({"message": response_text}))) elif self.request.path.endswith('/managedata'): all_documents = [doc.filename for doc in Document.all()] all_documents.sort() all_users = access_control.get_all_users() all_users.sort() status_table = dict() for user in all_users: status_table[user] = dict() for doc in all_documents: anno = DocumentAnnotation.all().filter("user_id =", user).filter("document =", doc).get() if not anno: status_table[user][doc] = UNPROCESSED elif not anno.approved: status_table[user][doc] = IN_PROGRESS else: status_table[user][doc] = COMPLETE documents_per_line = 44 num_docs = len(all_documents) num_lines = (num_docs + documents_per_line - 1) / documents_per_line partitioned_docs = [] for i in range(0, num_lines): partitioned_docs.append(all_documents[i * documents_per_line:min(num_docs, ( i + 1) * documents_per_line)]) message = self.request.get('message', "") verbatim_message = self.request.get('verbatim_message', "") metadata = CorpusMetadata.all().get() segmenter = "unknown" preprocessing_date = "unknown" if metadata: segmenter = metadata.segmenter preprocessing_date = metadata.preprocessing_date template_values = {'user': user_id, 'logout_url': users.create_logout_url('/argunit/'), 'all_views': access_control.get_view_ids(user_id), 'current_view': access_control.MANAGE_DATA_VIEW_ID, 'num_documents': len(all_documents), 'segmenter': segmenter, 'preprocessing_date': preprocessing_date, 'all_documents': all_documents, 'docs_per_line': documents_per_line, 'partitioned_docs': partitioned_docs, 'all_users': all_users, 'status_table': status_table, 'message': message, 'verbatim_message': verbatim_message} template = JINJA_ENVIRONMENT.get_template('managedata.html') self.response.write(template.render(template_values)) else: self.redirect('/argunit/managedata')
def get(self): if not self.validate_user(): return if self.request.path.endswith('/annotate'): user_id = access_control.get_current_user_id() # Allow to take the role of another user if self.request.get('user', None) in access_control.get_all_users(): user_id = self.request.get('user', None) documents_sorted_by_id = get_docs_ordered_by_id(user_id) processing_state = get_processing_state(user_id) # Per user_id annotation statistics num_annotated, num_approved = self.get_evaluation_stats() template_values = { 'user': user_id, 'logout_url': users.create_logout_url('/argunit/'), 'all_views': access_control.get_view_ids(user_id), 'current_view': access_control.ANNOTATE_VIEW_ID } if not documents_sorted_by_id: template_values.update({ 'has_document': False, 'navigation_docs': [], 'num_annotated': num_annotated, 'num_approved': num_approved, 'message': "No documents to display." }) else: doc_filename = self.request.get('doc', None) doc = mark_as_current_doc(user_id, doc_filename, documents_sorted_by_id[0]) topics = get_all_topics() current_topic = get_current_topic(user_id) opening_time = time.strftime("%H:%M:%S %Z", time.localtime()) docs_with_processing_state = [(d, processing_state[d.filename]) for d in documents_sorted_by_id] # Get arg_units to show arg_units = [] relations = [] concepts = [] doc_approved = False notes = "" personal_annotations = DocumentAnnotation.all().filter( 'user_id =', user_id).filter('document =', doc.filename).get() if personal_annotations: doc_approved = personal_annotations.approved notes = personal_annotations.notes arg_units = [ str(item) for item in personal_annotations.arg_units ] relations = [ str(item) for item in personal_annotations.relations ] concepts = [ str(item) for item in personal_annotations.concepts ] template_values.update({ 'navigation_docs': docs_with_processing_state, 'documents_sorted_by_id': documents_sorted_by_id, 'text': doc.text, 'doc_url': doc.url, 'doc_filename': doc.filename, 'doc_approved': doc_approved, 'num_sentences': doc.num_sentences, 'num_tokens': doc.num_tokens, 'time': opening_time, 'arg_units': json.dumps(arg_units), 'relations': json.dumps(relations), 'concepts': json.dumps(concepts), 'all_topics': topics, 'current_topic': current_topic, 'num_annotated': num_annotated, 'num_approved': num_approved, 'notes': notes, 'has_document': True, 'message': "" }) template = JINJA_ENVIRONMENT.get_template('annotate.html') self.response.write(template.render(template_values)) elif self.request.path.endswith('/selecttopic'): user_id = access_control.get_current_user_id() topics = self.request.get_all('topic', None) set_as_current_topics(user_id, topics) self.redirect('/argunit/annotate')
def get(self): user_id = access_control.get_current_user_id() if not self.validate_user(): return elif self.request.path.endswith('dump'): self.dump_corpus() elif self.request.path.endswith('dropall'): self.drop_all_data() self.redirect('%s?%s' % (self.base_path(), urllib.urlencode({"message": 'Dropped all data.'}))) elif self.request.path.endswith('dropanno'): self.drop_all_annotations() self.redirect( '%s?%s' % (self.base_path(), urllib.urlencode({"message": 'Dropped all annotations.'}))) elif self.request.path.endswith('loaddata'): response_text = self.load_documents() self.redirect( '%s?%s' % (self.base_path(), urllib.urlencode({"verbatim_message": response_text}))) elif self.request.path.endswith('forceupdate'): response_text = self.load_documents(force_update=True) self.redirect( '%s?%s' % (self.base_path(), urllib.urlencode({"verbatim_message": response_text}))) elif self.request.path.endswith('unapprove'): annotator = self.request.get("annotator") document = self.request.get("doc") self.setApproval(annotator, document, False) response_text = "Unapproved: %s:%s" % (annotator, document) self.redirect('%s?%s' % (self.base_path(), urllib.urlencode({"message": response_text}))) elif self.request.path.endswith('/managedata'): all_documents = [doc.filename for doc in Document.all()] all_documents.sort() all_users = access_control.get_all_users() all_users.sort() status_table = dict() for user in all_users: status_table[user] = dict() for doc in all_documents: anno = DocumentAnnotation.all().filter( "user_id =", user).filter("document =", doc).get() if not anno: status_table[user][doc] = UNPROCESSED elif not anno.approved: status_table[user][doc] = IN_PROGRESS else: status_table[user][doc] = COMPLETE documents_per_line = 44 num_docs = len(all_documents) num_lines = (num_docs + documents_per_line - 1) / documents_per_line partitioned_docs = [] for i in range(0, num_lines): partitioned_docs.append(all_documents[ i * documents_per_line:min(num_docs, (i + 1) * documents_per_line)]) message = self.request.get('message', "") verbatim_message = self.request.get('verbatim_message', "") metadata = CorpusMetadata.all().get() segmenter = "unknown" preprocessing_date = "unknown" if metadata: segmenter = metadata.segmenter preprocessing_date = metadata.preprocessing_date template_values = { 'user': user_id, 'logout_url': users.create_logout_url('/argunit/'), 'all_views': access_control.get_view_ids(user_id), 'current_view': access_control.MANAGE_DATA_VIEW_ID, 'num_documents': len(all_documents), 'segmenter': segmenter, 'preprocessing_date': preprocessing_date, 'all_documents': all_documents, 'docs_per_line': documents_per_line, 'partitioned_docs': partitioned_docs, 'all_users': all_users, 'status_table': status_table, 'message': message, 'verbatim_message': verbatim_message } template = JINJA_ENVIRONMENT.get_template('managedata.html') self.response.write(template.render(template_values)) else: self.redirect('/argunit/managedata')
def get(self): if not self.validate_user(): return user_id = access_control.get_current_user_id() if self.request.path.endswith('/compare'): user_data = load_user_data(user_id) topics = user_data.selected_topics documents_sorted_by_id = get_docs_in_topics_by_id(topics) template_values = { 'user': user_id, 'logout_url': users.create_logout_url('/argunit/'), 'all_views': access_control.get_view_ids(user_id), 'current_view': access_control.COMPARE_VIEW_ID } if not documents_sorted_by_id: template_values.update({ 'has_document': False, 'message': "No documents in collection" }) else: doc_filename = self.request.get('doc', None) doc = mark_as_current_doc(user_id, doc_filename, documents_sorted_by_id[0]) all_users = sorted(access_control.get_all_users()) print(all_users) annotator_id_1 = self.request.get("annotator1") if not annotator_id_1: annotator_id_1 = all_users[0] annotator_id_2 = self.request.get("annotator2") if not annotator_id_2: annotator_id_2 = all_users[1] showAnnotator3 = self.request.get("showAnnotator3") != '' annotator_id_3 = self.request.get("annotator3") if not annotator_id_3: annotator_id_3 = all_users[2] opening_time = time.strftime("%H:%M:%S %Z", time.localtime()) current_topic = get_current_topic(user_id) all_topics = get_all_topics() annotation1 = self.load_annotations(annotator_id_1, doc) annotation2 = self.load_annotations(annotator_id_2, doc) annotation3 = self.load_annotations(annotator_id_3, doc) arg_units1 = annotation1.arg_units if annotation1 else [] arg_units2 = annotation2.arg_units if annotation2 else [] arg_units3 = annotation3.arg_units if annotation3 else [] approved1 = annotation1.approved if annotation1 else False approved2 = annotation2.approved if annotation2 else False approved3 = annotation3.approved if annotation3 else False notes1 = annotation1.notes if annotation1 else "" notes2 = annotation2.notes if annotation2 else "" notes3 = annotation3.notes if annotation3 else "" template_values.update({ 'navigation_docs': documents_sorted_by_id, 'documents_sorted_by_id': documents_sorted_by_id, 'text': doc.text, 'doc_url': doc.url, 'doc_filename': doc.filename, 'num_sentences': doc.num_sentences, 'num_tokens': doc.num_tokens, 'time': opening_time, 'showAnnotator3': showAnnotator3, 'annotator1': annotator_id_1, 'annotator2': annotator_id_2, 'annotator3': annotator_id_3, 'approved1': approved1, 'approved2': approved2, 'approved3': approved3, 'arg_units1': json.dumps(arg_units1), 'arg_units2': json.dumps(arg_units2), 'arg_units3': json.dumps(arg_units3), 'notes1': notes1, 'notes2': notes2, 'notes3': notes3, 'current_topic': current_topic, 'all_topics': all_topics, 'all_users': all_users, 'has_document': True, 'message': "" }) template = JINJA_ENVIRONMENT.get_template('compare.html') self.response.write(template.render(template_values)) elif self.request.path.endswith('/selecttopic'): topics = self.request.get_all('topic', None) annotator1 = self.request.get('annotator1') annotator2 = self.request.get('annotator2') annotator3 = self.request.get('annotator3') set_as_current_topics(user_id, topics) self.redirect('/argunit/compare' + "?annotator1=" + annotator1 + "&annotator2=" + annotator2 + "&annotator3=" + annotator3)