def run(self, coderack, slipnet, workspace): category = self.arguments[0] initial_string = workspace.initial_string target_string = workspace.target_string i_relevance = initial_string.local_bond_category_relevance(category) t_relevance = target_string.local_bond_category_relevance(category) i_unhappiness = initial_string.intra_string_unhappiness t_unhappiness = target_string.intra_string_unhappiness values = [ round(toolbox.average(i_relevance, i_unhappiness)), round(toolbox.average(t_relevance, t_unhappiness)) ] string = toolbox.weighted_select(values, [initial_string, target_string]) obj = string.get_random_object('intra_string_salience') neighbor = obj.choose_neighbor() if neighbor == None: return # Fizzle facet = workspace.choose_bond_facet(obj, neighbor) if facet == None: return # Fizzle object_descriptor = obj.get_descriptor(facet) neighbor_descriptor = neighbor.get_descriptor(facet) if object_descriptor == None or neighbor_descriptor == None: return # Fizzle if slipnet.get_bond_category(object_descriptor, neighbor_descriptor) == category: from_object = obj to_object = neighbor from_descriptor = object_descriptor to_descriptor = neighbor_descriptor elif slipnet.get_bond_category(neighbor_descriptor, object_descriptor) == category: from_object = neighbor to_object = obj from_descriptor = neighbor_descriptor to_descriptor = object_descriptor else: return # Fizzle return workspace.propose_bond(from_object, to_object, category, facet, from_descriptor, to_descriptor)
def run(self, coderack, slipnet, workspace): category = self.arguments[0] initial_string = workspace.initial_string target_string = workspace.target_string i_relevance = initial_string.local_bond_category_relevance(category) t_relevance = target_string.local_bond_category_relevance(category) i_unhappiness = initial_string.intra_string_unhappiness t_unhappiness = target_string.intra_string_unhappiness values = [round(toolbox.average(i_relevance, i_unhappiness)), round(toolbox.average(t_relevance, t_unhappiness))] string = toolbox.weighted_select(values, [initial_string, target_string]) obj = string.get_random_object('intra_string_salience') neighbor = obj.choose_neighbor() if neighbor is None: return # Fizzle facet = workspace.choose_bond_facet(obj, neighbor) if facet is None: return # Fizzle object_descriptor = obj.get_descriptor(facet) neighbor_descriptor = neighbor.get_descriptor(facet) if object_descriptor is None or neighbor_descriptor is None: return # Fizzle if slipnet.get_bond_category(object_descriptor, neighbor_descriptor) == category: from_object = obj to_object = neighbor from_descriptor = object_descriptor to_descriptor = neighbor_descriptor elif slipnet.get_bond_category(neighbor_descriptor, object_descriptor) == category: from_object = neighbor to_object = obj from_descriptor = neighbor_descriptor to_descriptor = object_descriptor else: return # Fizzle return workspace.propose_bond(from_object, to_object, category, facet, from_descriptor, to_descriptor)
def run(self, coderack, slipnet, workspace): category = self.arguments[0] initial_string = workspace.initial_string target_string = workspace.target_string i_relevance = initial_string.local_direction_category_relevance( category) t_relevance = target_string.local_direction_category_relevance( category) i_unhappiness = initial_string.intra_string_unhappiness t_unhappiness = target_string.intra_string_unhappiness values = [ round(toolbox.average(i_relevance, i_unhappiness)), round(toolbox.average(t_relevance, t_unhappiness)) ] string = toolbox.weighted_select(values, [initial_string, target_string]) obj = string.get_random_object('intra_string_salience') if category == slipnet.plato_left: neighbor = obj.choose_left_neighbor() elif category == slipnet.plato_right: neighbor = obj.choose_right_neighbor() if neighbor == None: return # Fizzle facet = workspace.choose_bond_facet(obj, neighbor) if facet == None: return # Fizzle object_descriptor = obj.get_descriptor(facet) neighbor_descriptor = neighbor.get_descriptor(facet) if object_descriptor == None or neighbor_descriptor == None: return # Fizzle bond_category = slipnet.get_bond_category(object_descriptor, neighbor_descriptor) if bond_category == None or not bond_category.directed: return # Fizzle return workspace.propose_bond(obj, neighbor, bond_category, facet, object_descriptor, neighbor_descriptor)
def run(self, coderack, slipnet, workspace): category = self.arguments[0] initial_string = workspace.initial_string target_string = workspace.target_string i_relevance = initial_string.local_direction_category_relevance(category) t_relevance = target_string.local_direction_category_relevance(category) i_unhappiness = initial_string.intra_string_unhappiness t_unhappiness = target_string.intra_string_unhappiness values = [round(toolbox.average(i_relevance, i_unhappiness)), round(toolbox.average(t_relevance, t_unhappiness))] string = toolbox.weighted_select(values, [initial_string, target_string]) obj = string.get_random_object('intra_string_salience') if category == slipnet.plato_left: neighbor = obj.choose_left_neighbor() elif category == slipnet.plato_right: neighbor = obj.choose_right_neighbor() if neighbor is None: return # Fizzle facet = workspace.choose_bond_facet(obj, neighbor) if facet is None: return # Fizzle object_descriptor = obj.get_descriptor(facet) neighbor_descriptor = neighbor.get_descriptor(facet) if object_descriptor is None or neighbor_descriptor is None: return # Fizzle bond_category = slipnet.get_bond_category(object_descriptor, neighbor_descriptor) if bond_category is None or not bond_category.directed: return # Fizzle return workspace.propose_bond(obj, neighbor, bond_category, facet, object_descriptor, neighbor_descriptor)
def calculate_internal_strength(self): """Return the rule's internal strength.""" if self.has_no_change(): return 100 conceptual_depth1 = self.descriptor1.conceptual_depth if self.relation: conceptual_depth2 = self.relation.conceptual_depth else: conceptual_depth2 = self.descriptor2.conceptual_depth conceptual_difference = abs(conceptual_depth1 - conceptual_depth2) for obj in self.workspace.initial_string.get_objects(): if obj.is_changed: i_object = obj break if i_object.correspondence: i_object_corresponding_object = i_object.correspondence.object2 else: i_object_corresponding_object = None if not i_object_corresponding_object: shared_descriptor_term = 0 else: slipped_descriptors = [] for description in i_object_corresponding_object.relevant_descriptions( ): slips = description.apply_slippages( i_object_corresponding_object, self.workspace.slippages()) slipped_descriptors.append(slips.descriptor) if self.descriptor1 in slipped_descriptors: shared_descriptor_term = 100 else: return 0 depth = (100 - self.descriptor1.conceptual_depth) / 10. shared_descriptor_weight = round(depth**1.4) weights = [18, 12, shared_descriptor_weight] items = [ toolbox.average(conceptual_depth1, conceptual_depth2), 100 - conceptual_difference, shared_descriptor_term ] rule_strength = round(toolbox.weighted_average(weights, items)) return min(rule_strength, 100)
def calculate_internal_strength(self): """Return the rule's internal strength.""" if self.has_no_change(): return 100 conceptual_depth1 = self.descriptor1.conceptual_depth if self.relation: conceptual_depth2 = self.relation.conceptual_depth else: conceptual_depth2 = self.descriptor2.conceptual_depth conceptual_difference = abs(conceptual_depth1 - conceptual_depth2) for obj in self.workspace.initial_string.get_objects(): if obj.is_changed: i_object = obj break if i_object.correspondence: i_object_corresponding_object = i_object.correspondence.object2 else: i_object_corresponding_object = None if not i_object_corresponding_object: shared_descriptor_term = 0 else: slipped_descriptors = [] for description in i_object_corresponding_object.relevant_descriptions(): slips = description.apply_slippages(i_object_corresponding_object, self.workspace.slippages()) slipped_descriptors.append(slips.descriptor) if self.descriptor1 in slipped_descriptors: shared_descriptor_term = 100 else: return 0 depth = (100 - self.descriptor1.conceptual_depth) / 10. shared_descriptor_weight = round(depth ** 1.4) weights = [18, 12, shared_descriptor_weight] items = [toolbox.average(conceptual_depth1, conceptual_depth2), 100 - conceptual_difference, shared_descriptor_term] rule_strength = round(toolbox.weighted_average(weights, items)) return min(rule_strength, 100)
def calculate_internal_strength(self): """Return the correspondence's internal strength. A function of how many concept mappings there are, how strong they are and how much internal coherence there is among concept mappings.""" relevant_distinguishing_cms = self.relevant_distinguishing_concept_mappings() if relevant_distinguishing_cms == []: return 0 strengths = [cm.strength() for cm in relevant_distinguishing_cms] average_strength = toolbox.average(*strengths) number_of_cms = len(relevant_distinguishing_cms) number_of_cms_factor = {1:.8, 2:1.2}.get(number_of_cms, 1.6) if self.is_internally_coherent(): internal_coherence_factor = 2.5 else: internal_coherence_factor = 1 return min(100, round(average_strength * internal_coherence_factor * \ number_of_cms_factor))
def calculate_total_salience(self): """Return the total salience of the object.""" return round(toolbox.average(self.intra_string_salience, self.inter_string_salience))
def update_intra_string_unhappiness(self): """Calculate the average of the intra-string unhappiness of all the objects in the string.""" unhappiness = [o.intra_string_unhappiness for o in self.get_objects()] self.intra_string_unhappiness = round(toolbox.average(*unhappiness))
def salience(self): """Return the salience of the bond.""" return round(toolbox.average(self.importance(), self.unhappiness()))
def calculate_total_happiness(self): """Return the total string happiness.""" return round(toolbox.average(self.intra_string_happiness, self.inter_string_happiness))
def run(self, coderack, slipnet, workspace): category = self.arguments[0] bond_category = slipnet.get_related_node(category, slipnet.plato_bond_category) i_string = workspace.initial_string i_relevance = i_string.local_bond_category_relevance(bond_category) i_unhappiness = i_string.intra_string_unhappiness t_string = workspace.target_string t_relevance = t_string.local_bond_category_relevance(bond_category) t_unhappiness = t_string.intra_string_unhappiness weights = [round(toolbox.average(i_relevance, i_unhappiness)), round(toolbox.average(t_relevance, t_unhappiness))] choices = [i_string, t_string] string = toolbox.weighted_select(weights, choices) obj = string.get_random_object('intra_string_salience') if obj.spans_whole_string(): return # Fizzle if obj.is_leftmost_in_string(): direction = slipnet.plato_right elif obj.is_rightmost_in_string(): direction = slipnet.plato_left else: activations = [slipnet.plato_left.activation, slipnet.plato_right.activation] choices = [slipnet.plato_left, slipnet.plato_right] direction = toolbox.weighted_select(activations, choices) number = toolbox.weighted_index(string.bonds_to_scan_distribution) if direction == slipnet.plato_left: bond = obj.left_bond else: bond = obj.right_bond if bond is None or bond.bond_category != bond_category: if obj.type_name == 'group': return # Fizzle objects = [obj] bonds = [] if category == slipnet.plato_sameness_group: single_letter_group_direction = None else: choices = [slipnet.plato_left, slipnet.plato_right] weights = [node.local_descriptor_support(string, slipnet.plato_group) \ for node in choices] index = toolbox.weighted_index(weights) single_letter_group_direction = choices[index] single_letter_group = Group(workspace, string, category, single_letter_group_direction, obj, obj, objects, bonds) probability = single_letter_group.single_letter_group_probability() if toolbox.flip_coin(probability): return workspace.propose_group(objects, bonds, category, single_letter_group_direction) return # Fizzle direction_category = bond.direction_category facet = bond.bond_facet opposite_bond_category = slipnet.get_related_node(bond_category, slipnet.plato_opposite) if direction_category: opposite_direction_category = slipnet.get_related_node(direction_category, slipnet.plato_opposite) else: opposite_direction_category = None objects = [bond.left_object, bond.right_object] bonds = [bond] next_bond = bond for _ in range(2, number): bond_to_add = None if direction == slipnet.plato_left: next_bond = next_bond.choose_left_neighbor() if next_bond is None: break else: next_object = next_bond.left_object else: next_bond = next_bond.choose_right_neighbor() if next_bond is None: break else: next_object = next_bond.right_object if next_bond is None: bond_to_add = None elif all([next_bond.bond_category == bond_category, next_bond.direction_category == direction_category, next_bond.bond_facet == facet]): bond_to_add = next_bond elif all([next_bond.bond_category == opposite_bond_category, next_bond.direction_category == opposite_direction_category, next_bond.bond_facet == facet]): bond_to_add = next_bond.flipped_version() if bond_to_add: objects.append(next_object) bonds.append(bond_to_add) else: break return workspace.propose_group(objects, bonds, category, direction_category)
def calculate_total_salience(self): """Return the total salience of the object.""" return round( toolbox.average(self.intra_string_salience, self.inter_string_salience))
def run(self, coderack, slipnet, workspace): category = self.arguments[0] # Choose a string based on local direction category relevance. i_string = workspace.initial_string i_relevance = i_string.local_direction_category_relevance(category) i_unhappiness = i_string.intra_string_unhappiness t_string = workspace.target_string t_relevance = t_string.local_direction_category_relevance(category) t_unhappiness = t_string.intra_string_unhappiness choices = [i_string, t_string] weights = [round(toolbox.average(i_relevance, i_unhappiness)), round(toolbox.average(t_relevance, t_unhappiness))] string = toolbox.weighted_select(weights, choices) obj = string.get_random_object('intra_string_salience') if obj.spans_whole_string(): return # Fizzle if obj.is_leftmost_in_string(): direction = slipnet.plato_right elif obj.is_rightmost_in_string(): direction = slipnet.plato_left else: choices = [slipnet.plato_left, slipnet.plato_right] activations = [slipnet.plato_left.activation, slipnet.plato_right.activation] direction = toolbox.weighted_select(activations, choices) number = toolbox.weighted_index(string.bonds_to_scan_distribution) if direction == slipnet.plato_left: bond = obj.left_bond else: bond = obj.right_bond if not bond or bond.direction_category != category: return # Fizzle bond_category = bond.bond_category facet = bond.bond_facet opposite_bond_category = slipnet.get_related_node(bond_category, slipnet.plato_opposite) opposite_category = slipnet.get_related_node(category, slipnet.plato_opposite) objects = [bond.left_object, bond.right_object] bonds = [bond] next_bond = bond for _ in range(2, number): bond_to_add = None if direction == slipnet.plato_left: next_bond = next_bond.choose_left_neighbor() if not next_bond: break else: next_object = next_bond.left_object else: next_bond = next_bond.choose_right_neighbor() if not next_bond: break else: next_object = next_bond.right_object if not next_bond: bond_to_add = None elif (next_bond.bond_category == bond_category) and \ (next_bond.direction_category == category) and \ (next_bond.bond_facet == facet): bond_to_add = next_bond elif (next_bond.bond_category == opposite_bond_category) and \ (next_bond.direction_category == opposite_category) and \ (next_bond.bond_facet == facet): bond_to_add = next_bond.flipped_version() if bond_to_add: objects.append(next_object) bonds.append(bond_to_add) else: break group_category = slipnet.get_related_node(bond_category, slipnet.plato_group_category) return workspace.propose_group(objects, bonds, group_category, category)
def calculate_external_strength(self): """Return the external strength of the description.""" return toolbox.average(self.local_support(), self.description_type.activation)
def run(self, coderack, slipnet, workspace): category = self.arguments[0] bond_category = slipnet.get_related_node(category, slipnet.plato_bond_category) i_string = workspace.initial_string i_relevance = i_string.local_bond_category_relevance(bond_category) i_unhappiness = i_string.intra_string_unhappiness t_string = workspace.target_string t_relevance = t_string.local_bond_category_relevance(bond_category) t_unhappiness = t_string.intra_string_unhappiness weights = [round(toolbox.average(i_relevance, i_unhappiness)), round(toolbox.average(t_relevance, t_unhappiness))] choices = [i_string, t_string] string = toolbox.weighted_select(weights, choices) obj = string.get_random_object('intra_string_salience') if obj.spans_whole_string(): return # Fizzle if obj.is_leftmost_in_string(): direction = slipnet.plato_right elif obj.is_rightmost_in_string(): direction = slipnet.plato_left else: activations = [slipnet.plato_left.activation, slipnet.plato_right.activation] choices = [slipnet.plato_left, slipnet.plato_right] direction = toolbox.weighted_select(activations, choices) number = toolbox.weighted_index(string.bonds_to_scan_distribution) if direction == slipnet.plato_left: bond = obj.left_bond else: bond = obj.right_bond if bond == None or bond.bond_category != bond_category: if obj.type_name == 'group': return # Fizzle objects = [obj] bonds = [] if category == slipnet.plato_sameness_group: single_letter_group_direction = None else: choices = [slipnet.plato_left, slipnet.plato_right] weights = [node.local_descriptor_support(string, slipnet.plato_group) \ for node in choices] index = toolbox.weighted_index(weights) single_letter_group_direction = choices[index] single_letter_group = Group(workspace, string, category, single_letter_group_direction, obj, obj, objects, bonds) probability = single_letter_group.single_letter_group_probability() if toolbox.flip_coin(probability): return workspace.propose_group(objects, bonds, category, single_letter_group_direction) return # Fizzle direction_category = bond.direction_category facet = bond.bond_facet opposite_bond_category = slipnet.get_related_node(bond_category, slipnet.plato_opposite) if direction_category: opposite_direction_category = slipnet.get_related_node(direction_category, slipnet.plato_opposite) else: opposite_direction_category = None objects = [bond.left_object, bond.right_object] bonds = [bond] next_bond = bond for i in range(2, number): bond_to_add = None if direction == slipnet.plato_left: next_bond = next_bond.choose_left_neighbor() if next_bond == None: break else: next_object = next_bond.left_object else: next_bond = next_bond.choose_right_neighbor() if next_bond == None: break else: next_object = next_bond.right_object if next_bond == None: bond_to_add = None elif all([next_bond.bond_category == bond_category, next_bond.direction_category == direction_category, next_bond.bond_facet == facet]): bond_to_add = next_bond elif all([next_bond.bond_category == opposite_bond_category, next_bond.direction_category == opposite_direction_category, next_bond.bond_facet == facet]): bond_to_add = next_bond.flipped_version() if bond_to_add: objects.append(next_object) bonds.append(bond_to_add) else: break return workspace.propose_group(objects, bonds, category, direction_category)
def run(self, coderack, slipnet, workspace): category = self.arguments[0] # Choose a string based on local direction category relevance. i_string = workspace.initial_string i_relevance = i_string.local_direction_category_relevance(category) i_unhappiness = i_string.intra_string_unhappiness t_string = workspace.target_string t_relevance = t_string.local_direction_category_relevance(category) t_unhappiness = t_string.intra_string_unhappiness choices = [i_string, t_string] weights = [round(toolbox.average(i_relevance, i_unhappiness)), round(toolbox.average(t_relevance, t_unhappiness))] string = toolbox.weighted_select(weights, choices) obj = string.get_random_object('intra_string_salience') if obj.spans_whole_string(): return # Fizzle if obj.is_leftmost_in_string(): direction = slipnet.plato_right elif obj.is_rightmost_in_string(): direction = slipnet.plato_left else: choices = [slipnet.plato_left, slipnet.plato_right] activations = [slipnet.plato_left.activation, slipnet.plato_right.activation] direction = toolbox.weighted_select(activations, choices) number = toolbox.weighted_index(string.bonds_to_scan_distribution) if direction == slipnet.plato_left: bond = obj.left_bond else: bond = obj.right_bond if not bond or bond.direction_category != category: return # Fizzle bond_category = bond.bond_category facet = bond.bond_facet opposite_bond_category = slipnet.get_related_node(bond_category, slipnet.plato_opposite) opposite_category = slipnet.get_related_node(category, slipnet.plato_opposite) objects = [bond.left_object, bond.right_object] bonds = [bond] next_bond = bond for i in range(2, number): bond_to_add = None if direction == slipnet.plato_left: next_bond = next_bond.choose_left_neighbor() if not next_bond: break else: next_object = next_bond.left_object else: next_bond = next_bond.choose_right_neighbor() if not next_bond: break else: next_object = next_bond.right_object if not next_bond: bond_to_add = None elif (next_bond.bond_category == bond_category) and \ (next_bond.direction_category == category) and \ (next_bond.bond_facet == facet): bond_to_add = next_bond elif (next_bond.bond_category == opposite_bond_category) and \ (next_bond.direction_category == opposite_category) and \ (next_bond.bond_facet == facet): bond_to_add = next_bond.flipped_version() if bond_to_add: objects.append(next_object) bonds.append(bond_to_add) else: break group_category = slipnet.get_related_node(bond_category, slipnet.plato_group_category) return workspace.propose_group(objects, bonds, group_category, category)
def calculate_total_happiness(self): """Return the total string happiness.""" return round( toolbox.average(self.intra_string_happiness, self.inter_string_happiness))
def conceptual_depth(self): """Return the conceptual depth of the mapping.""" return toolbox.average(self.descriptor1.conceptual_depth, self.descriptor2.conceptual_depth)