diff --git a/generate.py b/generate.py index 9d1f3c316b0b00dfd1715b735cae476e5254ed94..d9b901acd44c494e7ceb3b48266c4ac2cea01d06 100755 --- a/generate.py +++ b/generate.py @@ -14,10 +14,11 @@ class select_query: return q + " " + " ".join(self.restrictions) class perform_query: - def __init__(self, action, what, destination, constraints, restrictions): + def __init__(self, action, what, destination, withs, constraints, restrictions): self.action = action self.what = what self.destination = destination + self.withs = withs self.constraints = constraints self.restrictions = restrictions def to_scql(self): @@ -28,17 +29,25 @@ class perform_query: q += self.destination else: q += " AS ".join(self.destination) + if len(self.withs) > 0: + q += " WITH " + ", ".join(map(" AS ".join, self.withs)) 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): +def expand_sentence_bocks(block): + if(any(filter(lambda x: isinstance(x, list), block))): + if(any(filter(lambda x: not isinstance(x, list), block))): + raise exeption("All elements in the list should be an array") + return map(" ".join, itertools.product(*block)) + return block + +def add_query(queries, sentence_fragments, query_def): # add a query to queries - # - sentences is an array of sentence segment that can be collected together + # - sentence_fragments 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)): + sentences = map(" ".join, itertools.product(*map(expand_sentence_bocks, sentence_fragments))) + for s in sentences: queries.append([s, query_def]) return queries @@ -64,21 +73,67 @@ desire_perf = ["I would like", "I am interested in", "I want to see", "He would 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")]], [])) +######### Selects ######### + +### 3d models + +queries = add_query(queries, [desire_perf, ["a point cloud of the rescue area"]], select_query([[mu("geo:Geometry"), "area"], [mu("scql_types:point_cloud"), "scan"]], [["scan.pose", "inside", "area"], ["area.uri", "=", mu("ex:rescue_area")]], [])) + +queries = add_query(queries, [desire_perf, ["a point cloud", "a 3d model"]], select_query([[mu("geo:Geometry"), "area"], [mu("scql_types:point_cloud"), "scan"]], [["area.klass", "=", mu("ex:area_of_interest")], ["scan.pose", "inside", "area"]], [])) +queries = add_query(queries, [desire_perf, [["a"], ["high resolution", "very detailed", "high quality"], ["point cloud", "3d model"]]], select_query([[mu("scql_types:point_cloud"), "scan"]], [["scan.pose", "inside", "area"], ["scan.density", ">", "100 point/m^2"]], [])) + +### Images/Models + +images_objects = [[["of all humans", "of all victims", "of all persons"], mu("ex:human")], + [["of all cars", "of all automobiles"], mu("ex:automobiles")], + [["of all vehicules"], mu("ex:vehicule")], + [["of all buildings"], mu("ex:building")], + [["of all houses"], mu("ex:house")], + [["of all shops"], mu("ex:shop")], + [["of all crossings"], mu("ex:crossing")] + ] + +properties = [ ["color", mu("ex:color"), ["red", mu("ex:red")], ["green", mu("ex:green")], ["blue", mu("ex:blue")], ["orange", mu("ex:orange")]], + ["size", mu("ex:size"), ["big", mu("ex:big")], ["medium", mu("ex:medium")], ["small", mu("ex:small")]] ] + +for io in images_objects: + queries = add_query(queries, [desire_perf, ["a image", "a picture"], io[0]], select_query([[mu("geo:Geometry"), "area"], [mu("scql_types:salient_point"), "sp"], [mu("scql_types:image"), "image"]], [["area.klass", "=", mu("ex:area_of_interest")], ["sp.klass", "=", io[1]], ["sp.pose", "inside", "area"], ["distance(image.pose, sp.pose)", "<", "1m"]], [])) + for prop in properties: + for value in prop[2]: + queries = add_query(queries, [desire_perf, ["a image", "a picture"], io[0], ["with a " + value[0] + " " + prop[0]]], select_query([[mu("geo:Geometry"), "area"], [mu("scql_types:salient_point"), "sp"], [mu("scql_types:image"), "image"]], [["area.klass", "=", mu("ex:area_of_interest")], ["sp.klass", "=", io[1]], ["sp.pose", "inside", "area"], ["distance(image.pose, sp.pose)", "<", "1m"], ["sp." + prop[1], "=", value[1]]], [])) + + +######### Performs ######### + +### Bring boxes to location + +# TODO the following queries should probably include an area restriction as well + +box_contents = [[["medication", "medicines"], mu("ex:medication")], [["food", "a meal"], mu("ex:food")], [["camping gear", "a tent", "shelter"], mu("ex:camping_gear")]] + +bring_boxes_perf = ["I would like you to bring a box with", "Could you bring a box with", "I need you to transport a box which contains", "I need you to deliver a box with"] +bring_boxes_dest = ["to specific coordinates", "to this location", "near the goal"] + +for bc in box_contents: + queries = add_query(queries, [bring_boxes_perf, bc[0] , bring_boxes_dest], perform_query(mu("scql_actions:bring_to"), ["ex:box", "box"], ["scql_types:geo_pose", "pose"], [], [["pose.klass", "=", "ex:location_of_interest" ], ["box", mu("ex:contains"), bc[1]]], [])) + +# Bring boxes to human in needs -queries = add_query(queries, [desire_perf, ["a point cloud"]], select_query([[mu("scql_types:lidar_frame>"), "scan"]], [["scan.pose", "inside", "%area"]], [])) +human_sick_injured_statuses = [[["all sick humans", "all sick persons", "all humans with disease"], "ex:sick"],[["all injured humans", "all humans with injury"], "ex:injured"]] +human_in_need_statuses = ["all humans in need", "all persons in need", "all persons that need to be rescued"] +all_human_bad_statuses = "[" + ", ".join([mu("ex:injured"), mu("ex:sick"), mu("ex:dying")]) + "]" -#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")]], [])) +for bc in box_contents: + for bbd in human_sick_injured_statuses: + queries = add_query(queries, [bring_boxes_perf, bc[0] , bbd[0]], perform_query(mu("scql_actions:bring_to"), ["ex:box", "box"], ["human.pose"], [["scql_types:salient_point", "human"]], [["human.klass", "=", "ex:human"], ["human.status", "=", bbd[1]], ["box", mu("ex:contains"), bc[1]]], [])) -#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 + queries = add_query(queries, [bring_boxes_perf, bc[0], human_in_need_statuses], perform_query(mu("scql_actions:bring_to"), ["ex:box", "box"], ["human.pose"], [["scql_types:salient_point", "human"]], [["human.klass", "=", mu("ex:human")], ["human.status", "in", all_human_bad_statuses], ["box", mu("ex:contains"), bc[1]]], [])) -#SELECT scql_types:image img, scql_types:salient_point sp WHERE distance(img.pose, sp.pose) < 1 AND sp.type = ex:human +# SELECT variant of "Bring boxes to human in needs" +for bbd in human_sick_injured_statuses: + queries = add_query(queries, [desire_perf, bbd[0]], select_query([[mu("scql_types:salient_point"), "human"]], [["human.klass", "=", "ex:human"], ["human.status", "=", bbd[1]]], [])) -#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> +queries = add_query(queries, [desire_perf, human_in_need_statuses], select_query([[mu("scql_types:salient_point"), "human"]], [["human.klass", "=", "ex:human"], ["human.status", "in", all_human_bad_statuses]], [])) generate_scql(queries)