frequencyAPI.py 1.07 KB
Newer Older
1 2
import flask
import requests
3
from flask_restful import Resource
4
import rapidjson as json
5
from flask_restful.reqparse import RequestParser
6 7 8 9 10 11 12 13

from mcserver import Config
from mcserver.app.services import NetworkService


class FrequencyAPI(Resource):
    def __init__(self):
        # TODO: FIX THE REQUEST PARSING FOR ALL APIs
14
        self.reqparse: RequestParser = NetworkService.base_request_parser.copy()
15 16 17 18 19 20 21 22 23 24 25 26
        self.reqparse.add_argument("urn", type=str, required=True, default="", location="form", help="No URN provided")
        super(FrequencyAPI, self).__init__()

    def get(self):
        """ Returns results for a frequency query from ANNIS for a given CTS URN and AQL. """
        # get request arguments
        args: dict = flask.request.args
        urn: str = args["urn"]
        url: str = f"{Config.INTERNET_PROTOCOL}{Config.HOST_IP_CSM}:{Config.CORPUS_STORAGE_MANAGER_PORT}" + \
                   Config.SERVER_URI_FREQUENCY
        response: requests.Response = requests.get(url, params=dict(urn=urn))
        return NetworkService.make_json_response(json.loads(response.text))