def forget(obj_tag): obj_atom = get_obj_atom("", obj_tag) log_to_terminal("forgetting %s" % obj_atom) global_vars.prolog_files["objects"].close() global_vars.prolog_files["objects"] = open("objects.pl", "r") content = global_vars.prolog_files["objects"].readlines() global_vars.prolog_files["objects"].close() os.remove("objects.pl") global_vars.prolog_files["objects"] = open("objects.pl", "a") for line in content: if (not obj_atom in line) or (("replaced_by" in line) and (obj_atom + ")." in line)): global_vars.prolog_files["objects"].write(line) else: global_vars.prolog_retract_handle(line.replace(".\n", ""))
def forget(obj_tag): obj_atom = get_obj_atom('', obj_tag) log_to_terminal("forgetting %s" % obj_atom) global_vars.prolog_files["objects"].close() global_vars.prolog_files["objects"] = open('objects.pl', 'r') content = global_vars.prolog_files["objects"].readlines() global_vars.prolog_files["objects"].close() os.remove("objects.pl") global_vars.prolog_files["objects"] = open('objects.pl', 'a') for line in content: if (not obj_atom in line) or (("replaced_by" in line) and (obj_atom + ")." in line)): global_vars.prolog_files["objects"].write(line) else: global_vars.prolog_retract_handle(line.replace(".\n", ""))
def remember(old_object_atom, new_object_atom="", asserting=True): global_vars.prolog_files["objects"].close() global_vars.prolog_files["objects"] = open("objects.pl", "r") content = global_vars.prolog_files["objects"].readlines() global_vars.prolog_files["objects"].close() os.remove("objects.pl") global_vars.prolog_files["objects"] = open("objects.pl", "a") for line in content: if not old_object_atom in line: global_vars.prolog_files["objects"].write(line) else: global_vars.prolog_retract_handle(line.replace(".\n", "")) logical_form = "prev_" + line global_vars.prolog_files["old_objects"].write(logical_form) if asserting: global_vars.prolog_assert_handle(logical_form) if new_object_atom != "": logical_form = "replaced_by(%s,%s)" % (old_object_atom, new_object_atom) global_vars.prolog_files["old_objects"].write(logical_form + ".\n") if asserting: global_vars.prolog_assert_handle(logical_form)
def reset(req): try: actions_learnt_list = [] query_results = global_vars.prolog_handle ('combinedPlan', ["X"]).ris for i in query_results: kbPlanName = i.atoms[0] planName = kbPlanName[0].upper() + kbPlanName[1:] actions_learnt_list.append(kbPlanName) global_vars.prolog_retract_handle('plan(%s,X,Y)'%kbPlanName) global_vars.prolog_retract_handle('pcl(%s,X)'%kbPlanName) remove_file(global_vars.plan_directory + "/" + planName + ".pnml") remove_all_relatives_of_all_elements_named_from(planName + ".exec", "ChooseAction.pnml") global_vars.prolog_retractAll_handle('combinedPlan(X)') reset_plan_prolog_file(actions_learnt_list) except: rospy.logerr("Could not contact the PrologInterface node") rospy.loginfo("Combine_pnp resetted") return "Done"
def reset(req): try: actions_learnt_list = [] query_results = global_vars.prolog_handle('combinedPlan', ["X"]).ris for i in query_results: kbPlanName = i.atoms[0] planName = kbPlanName[0].upper() + kbPlanName[1:] actions_learnt_list.append(kbPlanName) global_vars.prolog_retract_handle('plan(%s,X,Y)' % kbPlanName) global_vars.prolog_retract_handle('pcl(%s,X)' % kbPlanName) remove_file(global_vars.plan_directory + "/" + planName + ".pnml") remove_all_relatives_of_all_elements_named_from( planName + ".exec", "ChooseAction.pnml") global_vars.prolog_retractAll_handle('combinedPlan(X)') reset_plan_prolog_file(actions_learnt_list) except: rospy.logerr("Could not contact the PrologInterface node") rospy.loginfo("Combine_pnp resetted") return "Done"
def remember(old_object_atom, new_object_atom="", asserting=True): global_vars.prolog_files["objects"].close() global_vars.prolog_files["objects"] = open('objects.pl', 'r') content = global_vars.prolog_files["objects"].readlines() global_vars.prolog_files["objects"].close() os.remove("objects.pl") global_vars.prolog_files["objects"] = open('objects.pl', 'a') for line in content: if not old_object_atom in line: global_vars.prolog_files["objects"].write(line) else: global_vars.prolog_retract_handle(line.replace(".\n", "")) logical_form = "prev_" + line global_vars.prolog_files["old_objects"].write(logical_form) if asserting: global_vars.prolog_assert_handle(logical_form) if (new_object_atom != ""): logical_form = "replaced_by(%s,%s)" % (old_object_atom, new_object_atom) global_vars.prolog_files["old_objects"].write(logical_form + ".\n") if asserting: global_vars.prolog_assert_handle(logical_form)