def think_look_operation(self, op): """Sends back information about goals. This is mainly to be used for debugging minds. If no arguments are specified all goals will be reported, else a match will be done using 'index'. The information will be sent back as a Think operation wrapping an Info operation. This method is automatically invoked by the C++ BaseMind code, due to its *_*_operation name. """ think_op = Operation("think") goal_info_op = Operation("info") goal_infos = [] if not op.get_args(): # get all goals for (index, goal) in enumerate(self.goals): goal_infos.append(Entity(index=index, report=goal.report())) else: for arg in op.get_args(): goal = self.goals[arg.index] if goal and goal is not None: goal_infos.append( Entity(index=arg.index, report=goal.report())) goal_info_op.set_args(goal_infos) think_op.set_refno(op.get_serialno()) think_op.set_args([goal_info_op]) res = Oplist() res = res + think_op return res
def think_look_operation(self, op): """Sends back information about goals. This is mainly to be used for debugging minds. If no arguments are specified all goals will be reported, else a match will be done using 'index'. The information will be sent back as a Think operation wrapping an Info operation. This method is automatically invoked by the C++ BaseMind code, due to its *_*_operation name. """ think_op = Operation("think") goal_info_op = Operation("info") goal_infos = [] if not op.get_args(): # get all goals for (index, goal) in enumerate(self.goals): goal_infos.append(Entity(index=index, report=goal.report())) else: for arg in op.get_args(): goal = self.goals[arg.index] if goal and goal is not None: goal_infos.append(Entity(index=arg.index, report=goal.report())) goal_info_op.set_args(goal_infos) think_op.set_refno(op.get_serialno()) think_op.set_args([goal_info_op]) res = Oplist() res = res + think_op return res
def commune_all_thoughts(self, op, name): """Sends back information on all thoughts. This includes knowledge and goals, as well as known things. The thoughts will be sent back as a "think" operation, wrapping a Set operation, in a manner such that if the same think operation is sent back to the mind all thoughts will be restored. In this way the mind can support server side persistence of its thoughts. A name can optionally be supplied, which will be set on the Set operation. """ think_op = Operation("think") set_op = Operation("set") thoughts = [] for what in sorted(self.knowledge.knowings.keys()): d = self.knowledge.knowings[what] for key in sorted(d): if what != "goal": object_val = d[key] if isinstance(object_val, Location): # Serialize Location as tuple, with parent if available if object_val.parent is None: location = object_val.position else: location = ("$eid:" + object_val.parent.id, object_val.pos) goal_object = str(location) else: goal_object = str(d[key]) thoughts.append( Entity(predicate=what, subject=str(key), object=goal_object)) if len(self.things) > 0: things = {} for (id, thinglist) in sorted(self.things.items()): idlist = [] for thing in thinglist: idlist.append(thing.id) things[id] = idlist thoughts.append(Entity(things=things)) if len(self.pending_things) > 0: thoughts.append(Entity(pending_things=self.pending_things)) set_op.set_args(thoughts) think_op.set_args([set_op]) if not op.is_default_serialno(): think_op.set_refno(op.get_serialno()) if name: set_op.set_name(name) res = Oplist() res = res + think_op return res
def commune_all_thoughts(self, op, name): """Sends back information on all thoughts. This includes knowledge and goals, as well as known things. The thoughts will be sent back as a "think" operation, wrapping a Set operation, in a manner such that if the same think operation is sent back to the mind all thoughts will be restored. In this way the mind can support server side persistence of its thoughts. A name can optionally be supplied, which will be set on the Set operation. """ think_op = Operation("think") set_op = Operation("set") thoughts = [] for what in sorted(self.knowledge.knowings.keys()): d = self.knowledge.knowings[what] for key in sorted(d): if what != "goal": object_val = d[key] if type(object_val) is Location: # Serialize Location as tuple, with parent if available if object_val.parent is None: location = object_val.position else: location = ("$eid:" + object_val.parent.id, object_val.pos) goal_object = str(location) else: goal_object = str(d[key]) thoughts.append(Entity(predicate=what, subject=str(key), object=goal_object)) if len(self.things) > 0: things = {} for (id, thinglist) in sorted(self.things.items()): idlist = [] for thing in thinglist: idlist.append(thing.id) things[id] = idlist thoughts.append(Entity(things=things)) if len(self.pending_things) > 0: thoughts.append(Entity(pending_things=self.pending_things)) set_op.set_args(thoughts) think_op.set_args([set_op]) if not op.is_default_serialno(): think_op.set_refno(op.get_serialno()) if name: set_op.set_name(name) res = Oplist() res = res + think_op return res
def commune_goals(self, op, goal_entity): """Sends back information about goals only.""" think_op = Operation("think") set_op = Operation("set") thoughts = [] # It's important that the order of the goals is retained for goal in self.goals: if hasattr(goal, "str"): goal_string = goal.str else: goal_string = goal.__class__.__name__ thoughts.append(Entity(goal=goal_string, id=goal_string)) set_op.set_args(thoughts) think_op.set_args([set_op]) think_op.set_refno(op.get_serialno()) res = Oplist() res = res + think_op return res