Skip to content
Snippets Groups Projects
Commit 62b8a594 authored by Cyrille Berger's avatar Cyrille Berger
Browse files

first version

parents
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python3
import itertools
class select_query:
def __init__(self, variables, constraints, restrictions):
self.variables = variables
self.constraints = constraints
self.restrictions = restrictions
def to_scql(self):
q = "SELECT " + " ".join(map(" AS ".join, self.variables))
if len(self.constraints) > 0:
q += " WHERE " + " AND ".join(map(" ".join, self.constraints))
return q + " " + " ".join(self.restrictions)
class perform_query:
def __init__(self, action, what, destination, constraints, restrictions):
self.action = action
self.what = what
self.destination = destination
self.constraints = constraints
self.restrictions = restrictions
def to_scql(self):
q = "PERFORM " + self.action + " AS ".join(self.what)
if len(self.destination) > 0:
q += " TO "
if isinstance(self.destination, str):
q += self.destination
else:
q += " AS ".join(self.destination)
if len(self.constraints) > 0:
q += " WHERE " + " AND ".join(map(" ".join, self.constraints))
return q + " " + " ".join(self.restrictions)
def add_query(queries, sentences, query_def):
# add a query to queries
# - sentences is an array of sentence segment that can be collected together
# - query_def definition of a query
for s in map(" ".join, itertools.product(*sentences)):
queries.append([s, query_def])
return queries
def generate_scql(queries):
# Take a list of queries and generate the scQL query
for s,q in queries:
print(s)
print(q.to_scql())
prefix_to_uri = {
"ex": "http://example.org/",
"scql_actions": "http://askco.re/scql/actions#",
"scql_types": "http://askco.re/scql/types#",
"geo": "http://www.opengis.net/ont/geosparql#"
}
def mu(curie):
# split curie accordin to :
x = curie.split(":", 1)
return prefix_to_uri[x[0]] + x[1]
desire_perf = ["I would like", "I am interested in", "I want to see", "He would like", "He is interested in"]
queries = []
queries = add_query(queries, [desire_perf, ["a point cloud of the rescue area"]], select_query([[mu("geo:Geometry"), "area"],[mu("scql_types:lidar_frame"), "scan"]], [["scan.pose", "inside", "area"], ["area.uri", "=", mu("ex:rescue_area")]], []))
queries = add_query(queries, [desire_perf, ["a point cloud"]], select_query([[mu("scql_types:lidar_frame>"), "scan"]], [["scan.pose", "inside", "%area"]], []))
#PERFORM scql_actions:bring_to askcore_things:box AS box TO "POINT(10, 10)"^^geo:wktLiteral WHERE box <askcore_things:contains> <askcore_things:medication>
queries = add_query(queries, [["I would like you to bring a box to sepcific coordinates"]], perform_query(mu("scql_actions:bring_to"), ["ex:box", "box"], f'"POINT(10, 10)"^^{mu("geo:wktLiteral")}', [["box", mu("ex:contains"), mu("ex:medication")]], []))
#PERFORM scql_actions:bring_to scql_types:agent_pose AS source TO scql_types:agent_pose AS target WHERE target.agent = <agent_1> AND source.agent = <agent_2>
#PERFORM scql_actions:move_to TO scql_types:salient_point AS point WHERE point.pose INSIDE %area
#PERFORM scql_actions:move_to TO scql_types:agent_pose AS target WHERE target.agent = <agent_1>
#PERFORM scql_actions:explore scql_types:lidar_frame IN %area USING scql:dataset = %dataset_uri
#SELECT scql_types:image img, scql_types:salient_point sp WHERE distance(img.pose, sp.pose) < 1 AND sp.type = ex:human
#PERFORM scql_actions:bring_to askcore_things:box AS box TO scql_types:salient_point sp WHERE sp.type = ex:human AND sp.pose inside %area AND box <askcore_things:contains> <askcore_things:medication>
generate_scql(queries)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment