Ejemplo n.º 1
0
 def _get_any_merge_candidate(self, t1: Template,
                              t2: Template) -> MergeCandidate:
     """ Unused version of _get_best_merge_candidate, but might be prefered for performance gains """
     max_length = max(t1.get_number_of_non_slots(),
                      t2.get_number_of_non_slots())
     min_slots = min(t1.get_number_of_slots(), t2.get_number_of_slots())
     merged_template = next(
         Template.merge_templates_wagner_fischer(
             t1, t2, minimal_variables=self._minimal_variables))
     return MergeCandidate(
         t1, t2,
         _get_distance_of_merged(merged_template, max_length, min_slots))
Ejemplo n.º 2
0
    def _get_best_merge_candidate(self, t1: Template,
                                  t2: Template) -> MergeCandidate:
        """
        Calculates the distance between two given templates, that can contain slots
        """
        max_length = max(t1.get_number_of_non_slots(),
                         t2.get_number_of_non_slots())
        min_slots = min(t1.get_number_of_slots(), t2.get_number_of_slots())

        merged_templates = set(
            Template.merge_templates_wagner_fischer(
                t1, t2, minimal_variables=self._minimal_variables))
        merge_candidates = []
        for merged_template in merged_templates:
            distance = _get_distance_of_merged(merged_template, max_length,
                                               min_slots)
            merge_candidates.append(
                MergeCandidate(t1, t2, distance, merged=merged_template))
        return min(merge_candidates)
Ejemplo n.º 3
0
def _get_distance_of_merged(merged_template: Template, max_length: int,
                            min_slots: int) -> int:
    length_diff = max_length - merged_template.get_number_of_non_slots()
    slot_diff = merged_template.get_number_of_slots() - min_slots
    return length_diff + slot_diff