Skip to content

Commit

Permalink
add: validate query framework
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholsn committed Aug 26, 2014
1 parent d8211de commit 6c896fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
23 changes: 12 additions & 11 deletions niquery/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,32 @@ def bet(in_file_uri):

class Validate(Resource):
def get(self):
"""
Returns a list of queries used for validation of NIDM queries.
"""
ask = AskQuery()
return ask.sparql_meta.to_dict(outtype='records')


class ValidateResult(Resource):
def get(self, task_id):
retval = add.AsyncResult(task_id).get(timeout=1.0)
return repr(retval)
"""
Returns the raw query text of a given query.
"""
ask = AskQuery()
qid = "http://purl.org/niquery/id/{0}.rq".format(task_id)
result = ask.describe_query(qid)
return result.to_dict()


class Inference(Resource):
def get(self):
x = 5
y = 10
res = add.apply_async([x, y])
context = {"id": res.task_id, "x": x, "y": y}
result = "add((x){}, (y){})".format(context['x'], context['y'])
goto = "{}".format(context['id'])
return jsonify(result=result, goto=goto)
pass


class InferenceResult(Resource):
def get(self, task_id):
retval = add.AsyncResult(task_id).get(timeout=1.0)
return repr(retval)
pass


class Compute(Resource):
Expand Down
6 changes: 3 additions & 3 deletions niquery/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _filter_queries(self, ns):
select_filter = self.sparql_meta.format == str(ns)
return self.sparql_meta[select_filter]

def _get_query_string(self, index):
def get_query_string(self, index):
"""
Extracts the actual query text to execute, based on the query index.
"""
Expand Down Expand Up @@ -96,7 +96,7 @@ def execute(self, query_index, turtle_file=None, turtle_url=None):
df : pandas.Dataframe
Dataframe object of SELECT SPARQL query
"""
query = self._get_query_string(query_index)
query = self.get_query_string(query_index)
self._graph.parse(source=turtle_file,
location=turtle_url,
format='turtle')
Expand Down Expand Up @@ -124,7 +124,7 @@ def execute(self, query_index, turtle_file=None, turtle_url=None):
result : bool
Boolean result from ASK SPARQL query
"""
query = self._get_query_string(query_index)
query = self.get_query_string(query_index)
self._graph.parse(source=turtle_file,
location=turtle_url,
format='turtle')
Expand Down

0 comments on commit 6c896fc

Please sign in to comment.