Exemple #1
0
        """
        Get list of tasks (queued and completed)
        ---
        tags: [tasks]
        responses:
            200:
                description: tasks
                type: array
                items:
                    $ref: '#/definitions/Task'
        """
        tasks = get_tasks()
        return tasks


api.add_resource(Tasks, '/tasks/')


class TaskStatus(Resource):
    def get(self, task_id):
        """Get status for task
        ---
        tags: [tasks]
        parameters:
          - in: path
            name: task_id
            description: "task id"
            type: string
            required: true
        responses:
            200:
Exemple #2
0
                content:
                    application/json:
                        schema:
                            type: array
                            items:
                                type: string
        """
        r = requests.get(f"http://{os.environ['BUILDER_HOST']}:{os.environ['BUILDER_PORT']}/api/concepts")
        concepts = r.json()
        bad_concepts =['NAME.DISEASE', 'NAME.PHENOTYPE', 'NAME.DRUG']
        concepts = [c for c in concepts if not c in bad_concepts]
        concepts.sort()

        return concepts

api.add_resource(Concepts, '/concepts/')


class Omnicorp(Resource):
    def get(self, id1, id2):
        """
        Get publications for a pair of identifiers
        ---
        tags: [util]
        parameters:
          - in: path
            name: id1
            description: "curie of first term"
            schema:
                type: string
            required: true
Exemple #3
0
        answers = [json.loads(answer['body']) for answer in answers]
        message = {
            'question_graph': question_graph,
            'answers': answers
        }
        if include_kg:
            url = f'http://{os.environ["RANKER_HOST"]}:{os.environ["RANKER_PORT"]}/api/knowledge_graph'
            
            response = requests.post(url, json=message)
            if response.status_code >= 300:
                return 'Trouble contacting the ranker, there is probably a problem with the neo4j database', 500

            message['knowledge_graph'] = response.json()
        return message, 200

api.add_resource(AnswersetAPI, '/a/<qid_aid>/')


class QuestionVisibilityAPI(Resource):

    @auth_required('session', 'basic')
    def post(self, question_id):
        """
        Set Question Visiblity.
        ---
        tags: [questions]
        parameters:
          - in: path
            name: question_id
            description: "question id"
            schema:
Exemple #4
0
# New Feedback Submission
class FeedbackAPI(Resource):
    @auth_required('session', 'basic')
    def post(self):
        """Create new feedback
        ---
        tags: [feedback]
        parameters:
          - in: body
            name: feedback
            description: "new feedback"
            schema:
                $ref: '#/definitions/Feedback'
        responses:
            201:
                description: "confirmation"
                type: string
        """
        f = Feedback(user_id=current_user.id,
                     question_id=request.json['question_id'],
                     answer_id=request.json['answer_id'],
                     accuracy=request.json['accuracy'],
                     impact=request.json['impact'],
                     notes=request.json['notes'])

        return "Feedback created", 201


api.add_resource(FeedbackAPI, '/feedback/')
Exemple #5
0
            )
            ug_task = update_kg.signature(args=[question_id],
                                          kwargs={'user_email': user_email},
                                          immutable=True)
            as_task = answer_question.signature(
                args=[question_id],
                kwargs={'user_email': user_email},
                immutable=True)
            task = answer_question.apply_async(
                args=[question_id],
                kwargs={'user_email': user_email},
                link_error=ug_task | as_task)
            logger.info(
                f'Update task for question {question_id} for user {user_email} to the queue has recieved task_id {task.id}'
            )

        elif request.headers.get('AnswerNow', default='true') == 'true':
            logger.info(
                f'Adding answer task for question {question_id} for user {user_email} to the queue'
            )
            task = answer_question.apply_async(
                args=[question_id], kwargs={'user_email': user_email})
            logger.info(
                f'Answer task for question {question_id} for user {user_email} to the queue has recieved task_id {task.id}'
            )

        return question_id, 201


api.add_resource(QuestionsAPI, '/questions/')
Exemple #6
0
        max_results = parse_args_max_results(request.args)
        output_format = parse_args_output_format(request.args)
        max_connectivity = parse_args_max_connectivity(request.args)

        # Ger rebuild from request args
        question['rebuild'] = parse_args_rebuild(request.args)

        response = requests.post(
            f'http://manager:{os.environ["MANAGER_PORT"]}/api/simple/quick/?max_results={max_results}&max_connectivity={max_connectivity}&output_format={output_format}',
            json=question)
        answerset = response.json()

        return answerset


api.add_resource(Expand, '/simple/expand/<type1>/<id1>/<type2>/')


class Quick(Resource):
    def post(self):
        """
        Get answers to a question without caching
        ---
        tags: [simple]
        requestBody:
            name: question
            description: The machine-readable question graph.
            content:
                application/json:
                    schema:
                        $ref: '#/definitions/Question'
Exemple #7
0
                        $ref: '#/components/schemas/Message'
            required: true
        responses:
            200:
                description: A URL for further viewing
        """

        logger.info('Recieving Answerset for storage and later viewing')
        message = request.json

        # Save the message to archive folder
        for _ in range(25):
            try:
                uid = str(uuid4())
                this_file = os.path.join(view_storage_dir, f'{uid}.json')
                with open(this_file, 'x') as answerset_file:
                    logger.info('Saving Message')
                    json.dump(message, answerset_file)
                break
            except:
                logger.info('Error encountered writting file. Retrying')
                pass
        else:
            logger.info('Error encountered writting file')
            return "Failed to save resource. Internal server error", 500

        return uid, 200


api.add_resource(View, '/simple/view/')
Exemple #8
0
            if not answerset in answersets:
                raise AssertionError()
        except Exception as err:
            return "Invalid answerset key.", 404

        user = getAuthData()

        feedback = list_feedback_by_question_answerset(question, answerset)

        return {'question': question.toJSON(),\
                'answerset': answerset.toStandard(),\
                'feedback': [f.toJSON() for f in feedback],\
                'other_answersets': [],
                'other_questions': []}, 200

api.add_resource(AnswersetAPI, '/a/<qa_id>/')

class AnswerAPI(Resource):
    def get(self, qa_id, answer_id):
        """
        Get answer
        ---
        tags: [answer]
        parameters:
          - in: path
            name: qa_id
            description: "<question_id>_<answerset_id>"
            type: string
            required: true
          - in: path
            name: answer_id
Exemple #9
0
        request_url = ''
        if task['type'] == TASK_TYPES['answer']:
            request_url = f"http://{os.environ['RANKER_HOST']}:{os.environ['RANKER_PORT']}/api/task/{task['remote_task_id']}"
            response = requests.delete(request_url)
            # We could check the reponses, but there is nothing we would tell the user either way
            # elif task['type'] == TASK_TYPES['update']:
            #     request_url = f"http://{os.environ['BUILDER_HOST']}:{os.environ['BUILDER_PORT']}/api/task/{task['remote_task_id']}/log"
            # else:
            #     raise Exception('Invalid task type')
        # except:
        #     return 'Task not found', 404

        return '', 204


api.add_resource(TaskStatus, '/t/<task_id>/')


class NLP(Resource):
    def post(self):
        """
        Parse Question
        ---
        tags: [util]
        summary: "Convert a natural-language question into machine-readable form."
        consumes:
          - text/plain
        requestBody:
            name: "question"
            description: "Natural-language question"
            required: true
Exemple #10
0
            user_email = auth.username
            user = get_user_by_email(user_email)
        else:
            user = current_user
        logger.info('Deleting question %s', question_id)
        try:
            question = get_question_by_id(question_id)
        except Exception as err:
            return "Invalid question key.", 404
        if not (user == question.user or user.has_role('admin')):
            return "UNAUTHORIZED", 401 # not authorized
        db.session.delete(question)
        db.session.commit()
        return "SUCCESS", 200

api.add_resource(QuestionAPI, '/q/<question_id>/')

# get feedback by question
class GetFeedbackByQuestion(Resource):
    def get(self, question_id):
        """
        Create new feedback
        ---
        tags: [feedback]
        parameters:
          - in: path
            name: question_id
            description: "question id"
            type: string
            required: true
        responses: