Esempio n. 1
0
    def run(self, coderack, slipnet, workspace):
        if toolbox.flip_coin((100.0 - workspace.temperature) / 100.0):
            return # Fizzle

        structures = workspace.structures()
        if not structures:
            return # Fizzle

        structure = random.choice(structures)
        if not structure:
            return # Fizzle

        if isinstance(structure, Bond) and structure.group:
            structures = [structure, structure.group]
        else:
            structures = [structure]

        for structure in structures:
            probability = structure.total_weakness() / 100.0
            probability = workspace.temperature_adjusted_probability(probability)
            if not toolbox.flip_coin(probability):
                return # Fizzle

        for structure in structures:
            if isinstance(structure, Bond):
                workspace.break_bond(structure)
            elif isinstance(structure, Group):
                workspace.break_group(structure)
            elif isinstance(structure, Correspondence):
                workspace.break_correspondence(structure)
Esempio n. 2
0
    def run(self, coderack, slipnet, workspace):
        correspondence = self.arguments[0]
        flip_object2 = self.arguments[1]

        object1 = correspondence.object1
        object2 = correspondence.object2
        flipped = object2.flipped_version()

        objects = workspace.objects()
        if (object1 not in objects) or \
            ((object2 not in objects) and \
            (not (flip_object2 and
                  workspace.target_string.get_existing_group(flipped)))):
            return  # Fizzle

        correspondence.update_strengths()
        strength = correspondence.total_strength

        probability = strength / 100.0
        probability = workspace.temperature_adjusted_probability(probability)
        if not toolbox.flip_coin(probability):
            workspace.remove_proposed_correspondence(correspondence)
            return  # Fizzle

        for mapping in correspondence.get_concept_mappings():
            mapping.description_type1.activation_buffer += workspace.activation
            mapping.descriptor1.activation_buffer += workspace.activation
            mapping.description_type2.activation_buffer += workspace.activation
            mapping.descriptor2.activation_buffer += workspace.activation

        correspondence.proposal_level = 2

        # Post the correspondence builder codelet.
        return [(CorrespondenceBuilder([correspondence,
                                        flip_object2]), strength)]
Esempio n. 3
0
    def run(self, coderack, slipnet, workspace):
        correspondence = self.arguments[0]
        flip_object2 = self.arguments[1]

        object1 = correspondence.object1
        object2 = correspondence.object2
        flipped = object2.flipped_version()

        objects = workspace.objects()
        if (object1 not in objects) or (
            (object2 not in objects) and (not (flip_object2 and workspace.target_string.get_existing_group(flipped)))
        ):
            return  # Fizzle

        correspondence.update_strengths()
        strength = correspondence.total_strength

        probability = strength / 100.0
        probability = workspace.temperature_adjusted_probability(probability)
        if not toolbox.flip_coin(probability):
            workspace.remove_proposed_correspondence(correspondence)
            return  # Fizzle

        for mapping in correspondence.get_concept_mappings():
            mapping.description_type1.activation_buffer += workspace.activation
            mapping.descriptor1.activation_buffer += workspace.activation
            mapping.description_type2.activation_buffer += workspace.activation
            mapping.descriptor2.activation_buffer += workspace.activation

        correspondence.proposal_level = 2

        # Post the correspondence builder codelet.
        return [(CorrespondenceBuilder([correspondence, flip_object2]), strength)]
Esempio n. 4
0
 def similar_has_property_links(self):
     """Return a list of has property links that are similar."""
     similar_links = []
     for link in self.has_property_links:
         prob = link.degree_of_association() / 100.0
         if toolbox.flip_coin(prob):
             similar_links.append(link)
     return similar_links
Esempio n. 5
0
 def similar_has_property_links(self):
     """Return a list of has property links that are similar."""
     similar_links = []
     for link in self.has_property_links:
         prob = link.degree_of_association() / 100.0
         if toolbox.flip_coin(prob):
             similar_links.append(link)
     return similar_links
Esempio n. 6
0
    def run(self, coderack, slipnet, workspace):
        flip_obj2 = False

        object1 = workspace.initial_string.get_random_object(
            'inter_string_salience')
        object2 = workspace.target_string.get_random_object(
            'inter_string_salience')

        if object1.spans_whole_string() != object2.spans_whole_string():
            return  # Fizzle

        mappings = workspace.get_concept_mappings(
            object1, object2, object1.relevant_descriptions(),
            object2.relevant_descriptions())

        possible = False
        for mapping in mappings:
            probability = mapping.slippability() / 100.0
            probability = workspace.temperature_adjusted_probability(
                probability)
            if toolbox.flip_coin(probability):
                possible = True

        if not possible:
            return  # Fizzle

        distinguished_mappings = [m for m in mappings if m.is_distinguishing()]
        if not distinguished_mappings:
            return  # Fizzle

        opposite_mappings = []
        for mapping in distinguished_mappings:
            description_type = mapping.description_type1
            if description_type != slipnet.plato_string_position_category and \
               description_type != slipnet.plato_bond_facet:
                opposite_mappings.append(mapping)

        opposite_descriptions = [
            m.description_type1 for m in opposite_mappings
        ]
        if all([
                object1.is_string_spanning_group(),
                object2.is_string_spanning_group(),
                not slipnet.plato_opposite.is_active(),
                slipnet.are_all_opposite_concept_mappings(opposite_mappings),
                slipnet.plato_direction_category in opposite_descriptions
        ]):
            old_object2_string_number = object2.string_number
            object2 = object2.flipped_version()
            object2.string_number = old_object2_string_number
            mappings = workspace.get_concept_mappings(
                object1, object2, object1.relevant_descriptions(),
                object2.relevant_descriptions())
            flip_obj2 = True

        return workspace.propose_correspondence(object1, object2, mappings,
                                                flip_obj2)
Esempio n. 7
0
 def similar_has_property_links(self):
     """Return a list of has property links that are similar."""
     similar_links = []
     for link in self.has_property_links:
         prob = link.degree_of_association() / 100.0
         # FIXME: Requires access to the workspace.  Is it needed?
         #prob = get_temperature_adjusted_probability(prob)
         if toolbox.flip_coin(prob):
             similar_links.append(link)
     return similar_links
Esempio n. 8
0
    def run(self, coderack, slipnet, workspace):
        flip_obj2 = False

        object1 = workspace.initial_string.get_random_object("inter_string_salience")
        object2 = workspace.target_string.get_random_object("inter_string_salience")

        if object1.spans_whole_string() != object2.spans_whole_string():
            return  # Fizzle

        mappings = workspace.get_concept_mappings(
            object1, object2, object1.relevant_descriptions(), object2.relevant_descriptions()
        )

        possible = False
        for mapping in mappings:
            probability = mapping.slippability() / 100.0
            probability = workspace.temperature_adjusted_probability(probability)
            if toolbox.flip_coin(probability):
                possible = True

        if not possible:
            return  # Fizzle

        distinguished_mappings = [m for m in mappings if m.is_distinguishing()]
        if not distinguished_mappings:
            return  # Fizzle

        opposite_mappings = []
        for mapping in distinguished_mappings:
            description_type = mapping.description_type1
            if (
                description_type != slipnet.plato_string_position_category
                and description_type != slipnet.plato_bond_facet
            ):
                opposite_mappings.append(mapping)

        opposite_descriptions = [m.description_type1 for m in opposite_mappings]
        if all(
            [
                object1.is_string_spanning_group(),
                object2.is_string_spanning_group(),
                not slipnet.plato_opposite.is_active(),
                slipnet.are_all_opposite_concept_mappings(opposite_mappings),
                slipnet.plato_direction_category in opposite_descriptions,
            ]
        ):
            old_object2_string_number = object2.string_number
            object2 = object2.flipped_version()
            object2.string_number = old_object2_string_number
            mappings = workspace.get_concept_mappings(
                object1, object2, object1.relevant_descriptions(), object2.relevant_descriptions()
            )
            flip_obj2 = True

        return workspace.propose_correspondence(object1, object2, mappings, flip_obj2)
Esempio n. 9
0
    def run(self, coderack, slipnet, workspace):
        rule = self.arguments[0]

        rule.update_strengths()
        strength = rule.total_strength

        probability = strength / 100.0
        probability = workspace.temperature_adjusted_probability(probability)
        if not toolbox.flip_coin(probability):
            return # fizzle
        return [(RuleBuilder([rule]), strength)]
Esempio n. 10
0
    def run(self, coderack, slipnet, workspace):
        rule = self.arguments[0]

        rule.update_strengths()
        strength = rule.total_strength

        probability = strength / 100.0
        probability = workspace.temperature_adjusted_probability(probability)
        if not toolbox.flip_coin(probability):
            return # fizzle
        return [(RuleBuilder([rule]), strength)]
Esempio n. 11
0
    def run(self, coderack, slipnet, workspace):
        description = self.arguments[0]

        description.descriptor.activation_buffer += workspace.activation

        description.update_strengths()
        strength = description.total_strength

        probability = strength / 100.0
        probability = workspace.temperature_adjusted_probability(probability)
        if not toolbox.flip_coin(probability):
            return # Fizzle
        
        return [(DescriptionBuilder([description]), strength)]
Esempio n. 12
0
    def run(self, coderack, slipnet, workspace):
        bond = self.arguments[0]

        bond.update_strengths()
        strength = bond.total_strength

        probability = strength / 100.0
        probability = workspace.temperature_adjusted_probability(probability)
        if not toolbox.flip_coin(probability):
            bond.string.remove_proposed_bond(bond)
            return # Fizzle

        bond.proposal_level = 2

        bond.from_object_descriptor.activation_buffer += workspace.activation
        bond.to_object_descriptor.activation_buffer += workspace.activation
        bond.bond_facet.activation_buffer += workspace.activation

        return [(BondBuilder([bond]), strength)]
Esempio n. 13
0
    def run(self, coderack, slipnet, workspace):
        group = self.arguments[0]

        group.update_strengths()
        strength = group.total_strength

        probability = strength / 100.0
        probability = workspace.temperature_adjusted_probability(probability)
        if not toolbox.flip_coin(probability):
            group.string.remove_proposed_group(group)
            return # Fizzle

        group.proposal_level = 2

        group.bond_category.activation_buffer += workspace.activation
        if group.direction_category:
            group.direction_category.activation_buffer += workspace.activation

        return [(GroupBuilder([group]), strength)]
Esempio n. 14
0
    def run(self, coderack, slipnet, workspace):
        group = self.arguments[0]

        group.update_strengths()
        strength = group.total_strength

        probability = strength / 100.0
        probability = workspace.temperature_adjusted_probability(probability)
        if not toolbox.flip_coin(probability):
            group.string.remove_proposed_group(group)
            return # Fizzle

        group.proposal_level = 2

        group.bond_category.activation_buffer += workspace.activation
        if group.direction_category:
            group.direction_category.activation_buffer += workspace.activation

        return [(GroupBuilder([group]), strength)]
Esempio n. 15
0
    def run(self, coderack, slipnet, workspace):
        bond = self.arguments[0]

        bond.update_strengths()
        strength = bond.total_strength

        probability = strength / 100.0
        probability = workspace.temperature_adjusted_probability(probability)
        if not toolbox.flip_coin(probability):
            bond.string.remove_proposed_bond(bond)
            return  # Fizzle

        bond.proposal_level = 2

        bond.from_object_descriptor.activation_buffer += workspace.activation
        bond.to_object_descriptor.activation_buffer += workspace.activation
        bond.bond_facet.activation_buffer += workspace.activation

        return [(BondBuilder([bond]), strength)]
Esempio n. 16
0
 def update(self):
     """Update activations and link lenths."""
     for node in self.slipnodes:
         node.decay()
         if node.is_active():
             for link in node.outgoing_links():
                 amount_to_spread = round(node.activation * \
                         (link.intrinsic_degree_of_association() / 100.0))
                 link.to_node.activation_buffer += amount_to_spread
         
     for node in self.slipnodes:
         node.activation = min(100, node.activation + node.activation_buffer)
         if node.clamp:
             node.activation = 100
         else:
             if node.activation >= 50:
                 full_activation_probability = (node.activation / 100.0) ** 3
                 if toolbox.flip_coin(full_activation_probability):
                     node.activation = 100
         node.activation_buffer = 0
Esempio n. 17
0
    def update(self):
        """Update activations and link lenths."""
        for node in self.slipnodes:
            node.decay()
            if node.is_active():
                for link in node.outgoing_links():
                    amount_to_spread = round(node.activation * \
                            (link.intrinsic_degree_of_association() / 100.0))
                    link.to_node.activation_buffer += amount_to_spread

        for node in self.slipnodes:
            node.activation = min(100,
                                  node.activation + node.activation_buffer)
            if node.clamp:
                node.activation = 100
            else:
                if node.activation >= 50:
                    full_activation_probability = (node.activation / 100.0)**3
                    if toolbox.flip_coin(full_activation_probability):
                        node.activation = 100
            node.activation_buffer = 0
Esempio n. 18
0
    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)
Esempio n. 19
0
    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)
Esempio n. 20
0
    def __init__(self, workspace, string, group_category, direction_category,
                 left_object, right_object, objects, bonds):
        """Initialize Group."""
        Object.__init__(self, workspace)
        Structure.__init__(self)
        self.type_name = 'group'
        self.workspace = workspace
        self.string = string
        self.structure_category = Group
        self.group_category = group_category
        self.direction_category = direction_category
        self.left_object = left_object
        self.right_object = right_object
        self.objects = objects
        self.bonds = bonds

        self.middle_object = None
        for obj in objects:
            if obj.get_descriptor(self.slipnet.plato_string_position_category) == \
                    self.slipnet.plato_middle:
                self.middle_object = obj
                break

        self.left_object_position = left_object.left_string_position
        self.right_object_position = right_object.right_string_position
        self.left_string_position = self.left_object_position
        self.right_string_position = self.right_object_position

        self.bond_category = self.slipnet.get_related_node(
            group_category, self.slipnet.plato_bond_category)
        self.bond_facet = None
        self.bond_descriptions = []

        if self.spans_whole_string():
            self.add_description(
                Description(self.workspace, self,
                            self.slipnet.plato_object_category,
                            self.slipnet.plato_whole))

        self.add_description(
            Description(self.workspace, self,
                        self.slipnet.plato_object_category,
                        self.slipnet.plato_group))

        category = self.slipnet.plato_string_position_category
        if self.is_leftmost_in_string() and not self.spans_whole_string():
            self.add_description(
                Description(self.workspace, self,
                            self.slipnet.plato_string_position_category,
                            self.slipnet.plato_leftmost))
        elif self.is_middle_in_string():
            self.add_description(
                Description(self.workspace, self,
                            self.slipnet.plato_string_position_category,
                            self.slipnet.plato_middle))
        elif self.is_rightmost_in_string() and not self.spans_whole_string():
            self.add_description(
                Description(self.workspace, self,
                            self.slipnet.plato_string_position_category,
                            self.slipnet.plato_rightmost))

        if group_category == self.slipnet.plato_sameness_group and \
                (bonds == [] or \
                    bonds[0].bond_facet == self.slipnet.plato_letter_category):
            category = self.slipnet.plato_letter_category
            new_group_letter_category = left_object.get_descriptor(category)
            self.add_description(
                Description(self.workspace, self, category,
                            new_group_letter_category))

        category = self.slipnet.plato_group_category
        self.add_description(
            Description(self.workspace, self,
                        self.slipnet.plato_group_category, group_category))

        if direction_category:
            self.add_description(
                Description(self.workspace, self,
                            self.slipnet.plato_direction_category,
                            direction_category))

        if bonds:
            new_bond_facet = bonds[0].bond_facet
            self.bond_facet = new_bond_facet
            category = self.slipnet.plato_bond_facet
            self.add_bond_description(
                Description(self.workspace, self,
                            self.slipnet.plato_bond_facet, new_bond_facet))

        self.add_bond_description(
            Description(self.workspace, self, self.slipnet.plato_bond_category,
                        self.bond_category))

        if toolbox.flip_coin(self.length_description_probability()):
            category = self.slipnet.plato_length
            plato_number = self.slipnet.get_plato_number(self.length())
            self.add_description(
                Description(self.workspace, self, self.slipnet.plato_length,
                            self.slipnet.get_plato_number(self.length())))
Esempio n. 21
0
    def __init__(self, workspace, string, group_category, direction_category,
                 left_object, right_object, objects, bonds):
        """Initialize Group."""
        Object.__init__(self, workspace)
        Structure.__init__(self)
        self.type_name = 'group'
        self.workspace = workspace
        self.string = string
        self.structure_category = Group
        self.group_category = group_category
        self.direction_category = direction_category
        self.left_object = left_object
        self.right_object = right_object
        self.objects = objects
        self.bonds = bonds
        self.proposal_level = None

        self.middle_object = None
        for obj in objects:
            if obj.get_descriptor(self.slipnet.plato_string_position_category) == \
                    self.slipnet.plato_middle:
                self.middle_object = obj
                break

        self.left_object_position = left_object.left_string_position
        self.right_object_position = right_object.right_string_position
        self.left_string_position = self.left_object_position
        self.right_string_position = self.right_object_position

        self.bond_category = self.slipnet.get_related_node(group_category,
                                                           self.slipnet.plato_bond_category)
        self.bond_facet = None
        self.bond_descriptions = []

        if self.spans_whole_string():
            self.add_description(Description(self.workspace, self,
                                             self.slipnet.plato_object_category,
                                             self.slipnet.plato_whole))

        self.add_description(Description(self.workspace, self,
                                         self.slipnet.plato_object_category,
                                         self.slipnet.plato_group))

        category = self.slipnet.plato_string_position_category
        if self.is_leftmost_in_string() and not self.spans_whole_string():
            self.add_description(Description(self.workspace, self,
                                             self.slipnet.plato_string_position_category,
                                             self.slipnet.plato_leftmost))
        elif self.is_middle_in_string():
            self.add_description(Description(self.workspace, self,
                                             self.slipnet.plato_string_position_category,
                                             self.slipnet.plato_middle))
        elif self.is_rightmost_in_string() and not self.spans_whole_string():
            self.add_description(Description(self.workspace, self,
                                             self.slipnet.plato_string_position_category,
                                             self.slipnet.plato_rightmost))

        if group_category == self.slipnet.plato_sameness_group and \
                (bonds == [] or \
                    bonds[0].bond_facet == self.slipnet.plato_letter_category):
            category = self.slipnet.plato_letter_category
            new_group_letter_category = left_object.get_descriptor(category)
            self.add_description(Description(self.workspace, self,
                                             category,
                                             new_group_letter_category))

        category = self.slipnet.plato_group_category
        self.add_description(Description(self.workspace, self,
                                         self.slipnet.plato_group_category,
                                         group_category))

        if direction_category:
            self.add_description(Description(self.workspace, self,
                                             self.slipnet.plato_direction_category,
                                             direction_category))

        if bonds:
            new_bond_facet = bonds[0].bond_facet
            self.bond_facet = new_bond_facet
            category = self.slipnet.plato_bond_facet
            self.add_bond_description(Description(self.workspace, self,
                                                  self.slipnet.plato_bond_facet,
                                                  new_bond_facet))

        self.add_bond_description(Description(self.workspace, self,
                                              self.slipnet.plato_bond_category,
                                              self.bond_category))

        if toolbox.flip_coin(self.length_description_probability()):
            self.add_description(Description(self.workspace, self,
                                             self.slipnet.plato_length,
                                             self.slipnet.get_plato_number(self.length())))
Esempio n. 22
0
    def run(self, coderack, slipnet, workspace):
        flip_obj2 = False

        object1 = workspace.initial_string.get_random_object(
            'relative_importance')

        object1_description = object1.choose_relevant_distinguishing_description_by_conceptual_depth(
        )
        if not object1_description:
            return  # Fizzle
        object1_descriptor = object1_description.descriptor

        object2_descriptor = object1_descriptor
        for slippage in workspace.slippages():
            if slippage.descriptor1 == object1_descriptor:
                object2_descriptor = slippage.descriptor2
                break

        object2_candidates = []
        for obj in workspace.target_string.get_objects():
            for description in obj.relevant_descriptions():
                if description.descriptor == object2_descriptor:
                    object2_candidates.append(obj)
        if not object2_candidates:
            return  # Fizzle

        weights = [obj.inter_string_salience for obj in object2_candidates]
        object2 = toolbox.weighted_select(weights, object2_candidates)

        if object1.spans_whole_string() != object2.spans_whole_string():
            return  # Fizzle

        mappings = workspace.get_concept_mappings(
            object1, object2, object1.relevant_descriptions(),
            object2.relevant_descriptions())
        if not mappings:
            return

        possible = False
        for mapping in mappings:
            probability = mapping.slippability() / 100.0
            probability = workspace.temperature_adjusted_probability(
                probability)
            if toolbox.flip_coin(probability):
                possible = True
                break
        if not possible:
            return  # Fizzle

        distinguished_mappings = [m for m in mappings if m.is_distinguishing()]
        if not distinguished_mappings:
            return  # Fizzle

        possible_opposite_mappings = []
        for mapping in distinguished_mappings:
            description_type = mapping.description_type1
            if description_type != slipnet.plato_string_position_category and \
               description_type != slipnet.plato_bond_facet:
                possible_opposite_mappings.append(mapping)

        opposite_descriptions = [m.description_type1 for m in mappings]
        if all([
                object1.is_string_spanning_group(),
                object2.is_string_spanning_group(),
                not slipnet.plato_opposite.is_active(),
                slipnet.are_all_opposite_concept_mappings(
                    possible_opposite_mappings),
                slipnet.plato_direction_category in opposite_descriptions
        ]):
            old_object2_string_number = object2.string_number
            object2 = object2.flipped_version()
            object2.string_number = old_object2_string_number
            mappings = workspace.get_concept_mappings(
                object1, object2, object1.relevant_descriptions(),
                object2.relevant_descriptions())
            flip_obj2 = True

        return workspace.propose_correspondence(object1, object2, mappings,
                                                flip_obj2)
Esempio n. 23
0
    def run(self, coderack, slipnet, workspace):
        flip_obj2 = False

        object1 = workspace.initial_string.get_random_object("relative_importance")

        object1_description = object1.choose_relevant_distinguishing_description_by_conceptual_depth()
        if not object1_description:
            return  # Fizzle
        object1_descriptor = object1_description.descriptor

        object2_descriptor = object1_descriptor
        for slippage in workspace.slippages():
            if slippage.descriptor1 == object1_descriptor:
                object2_descriptor = slippage.descriptor2
                break

        object2_candidates = []
        for obj in workspace.target_string.get_objects():
            for description in obj.relevant_descriptions():
                if description.descriptor == object2_descriptor:
                    object2_candidates.append(obj)
        if not object2_candidates:
            return  # Fizzle

        weights = [obj.inter_string_salience for obj in object2_candidates]
        object2 = toolbox.weighted_select(weights, object2_candidates)

        if object1.spans_whole_string() != object2.spans_whole_string():
            return  # Fizzle

        mappings = workspace.get_concept_mappings(
            object1, object2, object1.relevant_descriptions(), object2.relevant_descriptions()
        )
        if not mappings:
            return

        possible = False
        for mapping in mappings:
            probability = mapping.slippability() / 100.0
            probability = workspace.temperature_adjusted_probability(probability)
            if toolbox.flip_coin(probability):
                possible = True
                break
        if not possible:
            return  # Fizzle

        distinguished_mappings = [m for m in mappings if m.is_distinguishing()]
        if not distinguished_mappings:
            return  # Fizzle

        possible_opposite_mappings = []
        for mapping in distinguished_mappings:
            description_type = mapping.description_type1
            if (
                description_type != slipnet.plato_string_position_category
                and description_type != slipnet.plato_bond_facet
            ):
                possible_opposite_mappings.append(mapping)

        opposite_descriptions = [m.description_type1 for m in mappings]
        if all(
            [
                object1.is_string_spanning_group(),
                object2.is_string_spanning_group(),
                not slipnet.plato_opposite.is_active(),
                slipnet.are_all_opposite_concept_mappings(possible_opposite_mappings),
                slipnet.plato_direction_category in opposite_descriptions,
            ]
        ):
            old_object2_string_number = object2.string_number
            object2 = object2.flipped_version()
            object2.string_number = old_object2_string_number
            mappings = workspace.get_concept_mappings(
                object1, object2, object1.relevant_descriptions(), object2.relevant_descriptions()
            )
            flip_obj2 = True

        return workspace.propose_correspondence(object1, object2, mappings, flip_obj2)