Skip to content

Commit

Permalink
add ReasonStdApi
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-hao committed Jul 28, 2020
1 parent b220cb8 commit a2be5ea
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ def after_request(response):

@api.representation('application/json')
def output_json(data, code, headers=None):
resp = make_response(simplejson.dumps({"terms and conditions": terms_and_conditions, "return value": data["return value"]}, ignore_nan=True), code)
resp = make_response(simplejson.dumps(data, ignore_nan=True), code)
resp.headers.extend(headers or {})
return resp

@api.representation('text/tabular')
def output_tabular(data, code, headers=None):
resp = make_response(format.format_tabular(terms_and_conditions, data["return value"]), code)
resp = make_response(format.format_tabular(terms_and_conditions, data.get("return value", data)), code)
resp.headers.extend(headers or {})
return resp

Expand Down Expand Up @@ -165,10 +165,11 @@ def post(self, table, year):
return wrapped(return_value)


def wrapped(data):
return {
"return value": data
}
def wrapped(data, reasoner=False):
if reasoner:
return {"terms and conditions": terms_and_conditions, **data}
else:
return {"terms and conditions": terms_and_conditions, "return value": data}

class SERVCohortId(Resource):
def put(self, table, year, cohort_id):
Expand Down Expand Up @@ -742,7 +743,7 @@ def post(self):
except Exception as e:
traceback.print_exc()
return_value = str(e)
return wrapped(return_value)
return wrapped(return_value, reasoner=request.args.get("reasoner", False))


class SERVKnowledgeGraphSchema(Resource):
Expand All @@ -763,7 +764,7 @@ def get(self):
except Exception as e:
traceback.print_exc()
return_value = str(e)
return wrapped(return_value)
return wrapped(return_value, reasoner=request.args.get("reasoner", False))


class SERVKnowledgeGraphOverlay(Resource):
Expand All @@ -780,6 +781,12 @@ def post(self):
required: true
schema:
$ref: '#/definitions/QueryOverlay'
- in: query
name: reasoner
description: return conforming to the ReasonerStdApi
required: false
schema:
type: boolean
responses:
200:
description: Success
Expand All @@ -797,7 +804,7 @@ def post(self):
except Exception as e:
traceback.print_exc()
return_value = str(e)
return wrapped(return_value)
return wrapped(return_value, reasoner=request.args.get("reasoner", False))


class SERVKnowledgeGraphOneHop(Resource):
Expand All @@ -814,6 +821,12 @@ def post(self):
required: true
schema:
$ref: '#/definitions/QueryOneHop'
- in: query
name: reasoner
description: return conforming to the ReasonerStdApi
required: false
schema:
type: boolean
responses:
200:
description: Success
Expand All @@ -831,7 +844,7 @@ def post(self):
except Exception as e:
traceback.print_exc()
return_value = str(e)
return wrapped(return_value)
return wrapped(return_value, reasoner=request.args.get("reasoner", False))


api.add_resource(SERVCohort, '/<string:table>/<int:year>/cohort')
Expand Down

0 comments on commit a2be5ea

Please sign in to comment.