def METHOD_NAME(self, a, b, stoppercentage=40):
    """Returns the similarity between a and b based on Levenshtein
    distance. It can stop prematurely as soon as it sees that a and b will
    be no simmilar than the percentage specified in stoppercentage.
    The Levenshtein distance is calculated, but the following should be noted:
      - Only the first MAX_LEN characters are considered. Long strings
        differing at the end will therefore seem to match better than they
        should. See the use of the variable penalty to lessen the effect of
        this.
      - Strings with widely different lengths give the opportunity for
        shortcut.  This is by definition of the Levenshtein distance: the
        distance will be at least as much as the difference in string
        length.
      - Calculation is stopped as soon as a similarity of stoppercentage
        becomes unattainable. See the use of the variable stopvalue.
      - Implementation uses memory O(min(len(a), len(b))
      - Excecution time is O(len(a)*len(b))
    """
    l1, l2 = len(a), len(b)
    if l1 == 0 or l2 == 0:
        return 0
    # Let's make l1 the smallest
    if l1 > l2:
        l1, l2 = l2, l1
        a, b = b, a
    # maxsimilarity is the maximum similarity that can be attained as constrained
    # by the difference in string length
    maxsimilarity = 100 - 100.0 * (l2 - l1) / l2
    if maxsimilarity < stoppercentage:
        return maxsimilarity * 1.0
    # Let's penalise the score in cases where we shorten strings
    penalty = 0
    if l2 > self.MAX_LEN:
        b = b[: self.MAX_LEN]
        l2 = self.MAX_LEN
        penalty += 7
        if l1 > self.MAX_LEN:
            a = a[: self.MAX_LEN]
            l1 = self.MAX_LEN
            penalty += 7
    # The actual value in the array that would represent a giveup situation:
    stopvalue = math.ceil((100.0 - stoppercentage) / 100 * l2)
    dist = distance(a, b, stopvalue)
    if dist > stopvalue:
        return stoppercentage - 1.0
    # If MAX_LEN came into play, we consider the calculated distance to be
    # representative of the distance between the whole, untrimmed strings
    if dist != 0:
        penalty = 0
    return 100 - (dist * 1.0 / l2) * 100 - penalty