Example #1
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)
Example #2
0
    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')
Example #3
0
    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')
Example #4
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)