def func(): for each in rule[0]: if each[0] == temp_dictLHS["query"]: lhs[each[0]+each[1]] = {x[0]:x[1] for x in each[3]} else: try: type_chunk, chunk_dict = chunks.createchunkdict(each[3]) except utilities.ACTRError as e: raise utilities.ACTRError("The rule string %s is not defined correctly; %s" %(name, e)) lhs[each[0]+each[1]] = chunks.makechunk("", type_chunk, **chunk_dict) yield lhs for each in rule[2]: if each[0] == temp_dictRHS["extra_test"]: rhs[each[0]+each[1]] = {x[0]:x[1] for x in each[3]} elif each[0] == temp_dictRHS["clear"]: rhs[each[0]+each[1]] = None elif each[0] == temp_dictRHS["execute"]: rhs[each[0]+each[1]] = each[3] else: try: type_chunk, chunk_dict = chunks.createchunkdict(each[3]) except utilities.ACTRError as e: raise utilities.ACTRError("The rule string %s is not defined correctly; %s" %(name, e)) rhs[each[0]+each[1]] = chunks.makechunk("", type_chunk, **chunk_dict) yield rhs
def func(): for each in rule[0]: if each[0] == temp_dictLHS["query"]: lhs[each[0] + each[1]] = {x[0]: x[1] for x in each[3]} else: type_chunk, chunk_dict = chunks.createchunkdict(each[3]) lhs[each[0] + each[1]] = chunks.makechunk( "", type_chunk, **chunk_dict) yield lhs for each in rule[2]: if each[0] == temp_dictRHS["extra_test"]: rhs[each[0] + each[1]] = {x[0]: x[1] for x in each[3]} elif each[0] == temp_dictRHS["clear"]: rhs[each[0] + each[1]] = None elif each[0] == temp_dictRHS["execute"]: rhs[each[0] + each[1]] = each[3] else: type_chunk, chunk_dict = chunks.createchunkdict(each[3]) rhs[each[0] + each[1]] = chunks.makechunk( "", type_chunk, **chunk_dict) yield rhs
def find(self, otherchunk, actrvariables=None, extra_tests=None): """ Set a chunk in vision based on what is on the screen. """ if extra_tests == None: extra_tests = {} if actrvariables == None: actrvariables = {} try: mod_attr_val = {x[0]: utilities.check_bound_vars(actrvariables, x[1]) for x in otherchunk.removeunused()} except utilities.ACTRError as arg: raise utilities.ACTRError("The chunk '%s' is not defined correctly; %s" % (otherchunk, arg)) chunk_used_for_search = chunks.Chunk(utilities.VISUALLOCATION, **mod_attr_val) found = None found_stim = None closest = float("inf") x_closest = float("inf") y_closest = float("inf") current_x = None current_y = None for each in self.environment.stimulus: position = (int(self.environment.stimulus[each]['position'][0]), int(self.environment.stimulus[each]['position'][1])) try: #checks absolute position if chunk_used_for_search.screen_x and int(chunk_used_for_search.screen_x) != position[0]: continue except (TypeError, ValueError): pass try: #checks absolute position if chunk_used_for_search.screen_y and int(chunk_used_for_search.screen_y) != position[1]: continue except (TypeError, ValueError): pass try: #checks on x and y relative positions if chunk_used_for_search.screen_x[0] == utilities.VISIONSMALLER and int(chunk_used_for_search.screen_x[1:]) <= position[0]: continue elif chunk_used_for_search.screen_x[0] == utilities.VISIONGREATER and int(chunk_used_for_search.screen_x[1:]) >= position[0]: continue except (TypeError, IndexError): pass try: #checks on x and y relative positions if chunk_used_for_search.screen_y[0] == utilities.VISIONSMALLER and int(chunk_used_for_search.screen_y[1:]) <= position[1]: continue elif chunk_used_for_search.screen_y[0] == utilities.VISIONGREATER and int(chunk_used_for_search.screen_y[1:]) >= position[1]: continue except (TypeError, IndexError): pass try: #checks on x and y absolute positions if chunk_used_for_search.screen_x == utilities.VISIONLOWEST and current_x != None and position[0] > current_x: continue elif chunk_used_for_search.screen_x == utilities.VISIONHIGHEST and current_x != None and position[0] < current_x: continue except TypeError: pass try: #checks on x and y absolute positions if chunk_used_for_search.screen_y == utilities.VISIONLOWEST and current_y != None and position[1] > current_y: continue elif chunk_used_for_search.screen_y == utilities.VISIONHIGHEST and current_y != None and position[1] < current_y: continue except TypeError: pass try: if extra_tests["attended"] == False or extra_tests["attended"] == 'False': if self.finst and self.environment.stimulus[each] in self.recent: continue else: if self.finst and self.environment.stimulus[each] not in self.recent: continue except KeyError: pass try: #checks on closest if (chunk_used_for_search.screen_x == utilities.VISIONCLOSEST or chunk_used_for_search.screen_y == utilities.VISIONCLOSEST) and utilities.calculate_pythagorian_distance(self.environment.current_focus, position) > closest: continue except TypeError: pass try: #checks on onewayclosest if (chunk_used_for_search.screen_x == utilities.VISIONONEWAYCLOSEST) and utilities.calculate_onedimensional_distance(self.environment.current_focus, position, horizontal=True) > x_closest: continue except TypeError: pass try: #checks on onewayclosest if (chunk_used_for_search.screen_y == utilities.VISIONONEWAYCLOSEST) and utilities.calculate_onedimensional_distance(self.environment.current_focus, position, horizontal=False) > y_closest: continue except TypeError: pass found_stim = self.environment.stimulus[each] visible_chunk = chunks.makechunk(nameofchunk="vis1", typename="_visuallocation", **{key: each[key] for key in self.environment.stimulus[each] if key != 'position' and key != 'text' and key != 'vis_delay'}) if visible_chunk <= chunk_used_for_search: temp_dict = visible_chunk._asdict() temp_dict.update({"screen_x":position[0], "screen_y":position[1]}) found = chunks.Chunk(utilities.VISUALLOCATION, **temp_dict) current_x = position[0] current_y = position[1] closest = utilities.calculate_pythagorian_distance(self.environment.current_focus, position) x_closest = utilities.calculate_onedimensional_distance(self.environment.current_focus, position, horizontal=True) y_closest = utilities.calculate_onedimensional_distance(self.environment.current_focus, position, horizontal=False) return found, found_stim
def find(self, otherchunk, actrvariables=None, extra_tests=None): """ Set a chunk in vision based on what is on the screen. """ if extra_tests == None: extra_tests = {} if actrvariables == None: actrvariables = {} try: mod_attr_val = {x[0]: utilities.check_bound_vars(actrvariables, x[1], negative_impossible=False) for x in otherchunk.removeunused()} except utilities.ACTRError as arg: raise utilities.ACTRError("The chunk '%s' is not defined correctly; %s" % (otherchunk, arg)) chunk_used_for_search = chunks.Chunk(utilities.VISUALLOCATION, **mod_attr_val) found = None found_stim = None closest = float("inf") x_closest = float("inf") y_closest = float("inf") current_x = None current_y = None for each in self.environment.stimulus: #extra test applied first try: if extra_tests["attended"] == False or extra_tests["attended"] == 'False': if self.finst and self.environment.stimulus[each] in self.recent: continue else: if self.finst and self.environment.stimulus[each] not in self.recent: continue except KeyError: pass #check value in text; in principle, you can search based on any value, so this is more powerful than actual visual search if chunk_used_for_search.value != chunk_used_for_search.EmptyValue() and chunk_used_for_search.value.values != self.environment.stimulus[each]["text"]: continue position = (int(self.environment.stimulus[each]['position'][0]), int(self.environment.stimulus[each]['position'][1])) #check absolute position; exception on AttributeError is to avoid the case in which the slot has empty value (in that case, the attribute "values" is undefined) try: if chunk_used_for_search.screen_x.values and int(chunk_used_for_search.screen_x.values) != position[0]: continue except (TypeError, ValueError, AttributeError): pass try: if chunk_used_for_search.screen_y.values and int(chunk_used_for_search.screen_y.values) != position[1]: continue except (TypeError, ValueError, AttributeError): pass #check on x and y relative positions try: if chunk_used_for_search.screen_x.values[0] == utilities.VISIONSMALLER and int(chunk_used_for_search.screen_x.values[1:]) <= position[0]: continue elif chunk_used_for_search.screen_x.values[0] == utilities.VISIONGREATER and int(chunk_used_for_search.screen_x.values[1:]) >= position[0]: continue except (TypeError, IndexError, AttributeError): pass try: if chunk_used_for_search.screen_y.values[0] == utilities.VISIONSMALLER and int(chunk_used_for_search.screen_y.values[1:]) <= position[1]: continue elif chunk_used_for_search.screen_y.values[0] == utilities.VISIONGREATER and int(chunk_used_for_search.screen_y.values[1:]) >= position[1]: continue except (TypeError, IndexError, AttributeError): pass #check on x and y absolute positions try: if chunk_used_for_search.screen_x.values == utilities.VISIONLOWEST and current_x != None and position[0] > current_x: continue elif chunk_used_for_search.screen_x.values == utilities.VISIONHIGHEST and current_x != None and position[0] < current_x: continue except (TypeError, AttributeError): pass try: if chunk_used_for_search.screen_y.values == utilities.VISIONLOWEST and current_y != None and position[1] > current_y: continue elif chunk_used_for_search.screen_y.values == utilities.VISIONHIGHEST and current_y != None and position[1] < current_y: continue except (TypeError, AttributeError): pass #check on closest try: if (chunk_used_for_search.screen_x.values == utilities.VISIONCLOSEST or chunk_used_for_search.screen_y.values == utilities.VISIONCLOSEST) and utilities.calculate_pythagorian_distance(self.environment.current_focus, position) > closest: continue except (TypeError, AttributeError): pass #check on onewayclosest try: if (chunk_used_for_search.screen_x.values == utilities.VISIONONEWAYCLOSEST) and utilities.calculate_onedimensional_distance(self.environment.current_focus, position, horizontal=True) > x_closest: continue except (TypeError, AttributeError): pass try: if (chunk_used_for_search.screen_y.values == utilities.VISIONONEWAYCLOSEST) and utilities.calculate_onedimensional_distance(self.environment.current_focus, position, horizontal=False) > y_closest: continue except (TypeError, AttributeError): pass found_stim = self.environment.stimulus[each] visible_chunk = chunks.makechunk(nameofchunk="vis1", typename="_visuallocation", **{key: each[key] for key in self.environment.stimulus[each] if key != 'position' and key != 'text' and key != 'vis_delay'}) if visible_chunk <= chunk_used_for_search: temp_dict = visible_chunk._asdict() temp_dict.update({"screen_x":position[0], "screen_y":position[1]}) found = chunks.Chunk(utilities.VISUALLOCATION, **temp_dict) current_x = position[0] current_y = position[1] closest = utilities.calculate_pythagorian_distance(self.environment.current_focus, position) x_closest = utilities.calculate_onedimensional_distance(self.environment.current_focus, position, horizontal=True) y_closest = utilities.calculate_onedimensional_distance(self.environment.current_focus, position, horizontal=False) return found, found_stim