<commit_before># -*- mode: Python;-*-

import sys
import operator


# Cost is basically: was there a match or not.
# The other numbers are cumulative costs and matches...

def lowest_cost_action(ic, dc, sc, im, dm, sm, cost):
    """Given the following values, choose the action (insertion, deletion,
    or substitution), that results in the lowest cost (ties are broken using
    the 'match' score).  This is used within the dynamic programming algorithm.
    * ic - insertion cost
    * dc - deletion cost
    * sc - substitution cost
    * im - insertion match (score)
    * dm - deletion match (score)
    * sm - substitution match (score)
    """
    best_action = None
    best_match_count = -1
    min_cost = min(ic, dc, sc)
    if min_cost == sc and cost == 0:
        best_action = 'equal'
        best_match_count = sm
    elif min_cost == sc and cost == 1:
        best_action = 'replace'
        best_match_count = sm
    elif min_cost == ic and im > best_match_count:
        best_action = 'insert'
        best_match_count = im
    elif min_cost == dc and dm > best_match_count:
        best_action = 'delete'
        best_match_count = dm
    return best_action


def highest_match_action(ic, dc, sc, im, dm, sm, cost):
    """Given the following values, choose the action (insertion, deletion, or
    substitution), that results in the highest match score (ties are broken
    using the distance values).  This is used within the dynamic programming
    algorithm.
    * ic - insertion cost
    * dc - deletion cost
    * sc - substitution cost
    * im - insertion match (score)
    * dm - deletion match (score)
    * sm - substitution match (score)
    """
    best_action = None
    lowest_cost = float("inf")
    max_match = max(im, dm, sm)
    if max_match == sm and cost == 0:
        best_action = 'equal'
        lowest_cost = sm
    elif max_match == sm and cost == 1:
        best_action = 'replace'
        lowest_cost = sm
    elif max_match == im and ic < lowest_cost:
        best_action = 'insert'
        lowest_cost = ic
    elif max_match == dm and dc < lowest_cost:
        best_action = 'delete'
        lowest_cost = dc
    return best_action


class SequenceMatcher:
    """Similar to the difflib SequenceMatcher, but uses Levenshtein/edit
    distance.

    Members:
      a - first sequence
      b - second sequence
      opcodes - the cached opcodes
      dist - the cached distance value
      _matches - the cached match count
    """

    def __init__(self, a=[], b=[], test=operator.eq,
                 action_function=lowest_cost_action):
        """Initialize the object with sequences a and b.  Optionally, one can
        specify a test function that is used to compare sequence elements.
        This defaults to the built in eq operator (i.e. operator.eq).
        """
        self.seq1 = a
        self.seq2 = b
        self._reset_object()
        self.action_function = action_function

    def set_seqs(self, a, b):
        """Specify two alternative sequences -- reset any cached values also."""
        set_seq1(a)
        set_seq2(b)
        self._reset_object()

    def _reset_object(self):
        """Clear out the cached values for distance, matches, and opcodes."""
        self.opcodes = None
        self.dist = None
        self._matches = None

    def set_seq1(self, a):
        """Specify a new sequence for sequence 1."""
        _reset_object()
        self.seq1 = a<commit_msg>Avoid mutable default arguments (#2)<commit_after># -*- mode: Python;-*-

import sys
import operator


# Cost is basically: was there a match or not.
# The other numbers are cumulative costs and matches...

def lowest_cost_action(ic, dc, sc, im, dm, sm, cost):
    """Given the following values, choose the action (insertion, deletion,
    or substitution), that results in the lowest cost (ties are broken using
    the 'match' score).  This is used within the dynamic programming algorithm.
    * ic - insertion cost
    * dc - deletion cost
    * sc - substitution cost
    * im - insertion match (score)
    * dm - deletion match (score)
    * sm - substitution match (score)
    """
    best_action = None
    best_match_count = -1
    min_cost = min(ic, dc, sc)
    if min_cost == sc and cost == 0:
        best_action = 'equal'
        best_match_count = sm
    elif min_cost == sc and cost == 1:
        best_action = 'replace'
        best_match_count = sm
    elif min_cost == ic and im > best_match_count:
        best_action = 'insert'
        best_match_count = im
    elif min_cost == dc and dm > best_match_count:
        best_action = 'delete'
        best_match_count = dm
    return best_action


def highest_match_action(ic, dc, sc, im, dm, sm, cost):
    """Given the following values, choose the action (insertion, deletion, or
    substitution), that results in the highest match score (ties are broken
    using the distance values).  This is used within the dynamic programming
    algorithm.
    * ic - insertion cost
    * dc - deletion cost
    * sc - substitution cost
    * im - insertion match (score)
    * dm - deletion match (score)
    * sm - substitution match (score)
    """
    best_action = None
    lowest_cost = float("inf")
    max_match = max(im, dm, sm)
    if max_match == sm and cost == 0:
        best_action = 'equal'
        lowest_cost = sm
    elif max_match == sm and cost == 1:
        best_action = 'replace'
        lowest_cost = sm
    elif max_match == im and ic < lowest_cost:
        best_action = 'insert'
        lowest_cost = ic
    elif max_match == dm and dc < lowest_cost:
        best_action = 'delete'
        lowest_cost = dc
    return best_action


class SequenceMatcher:
    """Similar to the difflib SequenceMatcher, but uses Levenshtein/edit
    distance.

    Members:
      a - first sequence
      b - second sequence
      opcodes - the cached opcodes
      dist - the cached distance value
      _matches - the cached match count
    """

    def __init__(self, a=None, b=None, test=operator.eq,
                 action_function=lowest_cost_action):
        """Initialize the object with sequences a and b.  Optionally, one can
        specify a test function that is used to compare sequence elements.
        This defaults to the built in eq operator (i.e. operator.eq).
        """
        if a is None:
            a = []
        if b is None:
            b = []
        self.seq1 = a
        self.seq2 = b
        self._reset_object()
        self.action_function = action_function

    def set_seqs(self, a, b):
        """Specify two alternative sequences -- reset any cached values also."""
        set_seq1(a)
        set_seq2(b)
        self._reset_object()

    def _reset_object(self):
        """Clear out the cached values for distance, matches, and opcodes."""
        self.opcodes = None
        self.dist = None
        self._matches = None

    def set_seq1(self, a):
        """Specify a new sequence for sequence 1."""
        _reset_object()
        self.seq1 = a
{'fraction_non_alphanumeric': 0.08766928011404133, 'fraction_numerical': 0.003563791874554526, 'mean_word_length': 2.31725768321513, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7447678', 'n_tokens_mistral': 2066, 'n_tokens_neox': 1991, 'n_words': 755}