<commit_before>import re
from affixes import drop_prefixes, drop_suffixes
from itertools import combinations
import string
import split

def initial_initial(name):
    parts = name.split(' ')
    if parts:
        name = parts[0][0] + " " + " ".join(parts[1:])
    return name

def middle_initials(name):
    parts = name.split(' ')
    name = parts[0]
    for part in parts[1:-1]:
        name += " " + part[0]
    if len(parts) > 1:
        name += " " + parts[-1]
    return name

def last_only(name):
    return split.split(name)[2]

_funcs = {string.lower: 0.01,
          (lambda s: s.replace('.', '')): 0.02,
          (lambda s: s.replace(',', '')): 0.02,
          initial_initial: 0.03,
          middle_initials: 0.03,
          drop_prefixes: 0.05,
          drop_suffixes: 0.05,
          last_only: 0.20,}
# other things to consider:
# <NAME> -> Stephens, Michael
# accented characters -> unaccented equiv.
# just last name
# remove consecutive inner spaces (probably no penalty)
# some sort of soundex thing?

_combinations = []
for n in xrange(0, len(_funcs)):
    _combinations.extend(combinations(_funcs.items(), n))

def match(name1, name2):
    """
    >>> match("<NAME>", "<NAME>")
    1.0
    >>> abs(match("<NAME>", "<NAME>") - 0.99) < 0.001
    True
    >>> abs(match("<NAME>", "<NAME>") - 0.98) < 0.001
    True
    >>> abs(match("<NAME>", "<NAME>") - 0.98) < 0.001
    True
    >>> abs(match("<NAME>", "<NAME>") - 0.97) < 0.001
    True
    >>> abs(match("<NAME>", "Mr. <NAME>") - 0.95) < 0.001
    True
    >>> abs(match("Mr. <NAME>", "<NAME>, M.S.") - 0.90) < 0.001
    True
    >>> abs(match("Mr. <NAME>, Jr.", "Dr. <NAME>, USMC (Ret)") - 0.78) < 0.001
    True
    >>> abs(match("<NAME>", "<NAME>") - 0.97) < 0.001
    True
    >>> abs(match("<NAME>", "<NAME>") - 0.97) < 0.001
    True
    >>> abs(match("<NAME>", "Stephens") - 0.80) < 0.001
    True
    >>> match("<NAME>", "<NAME>")
    0.0
    >>> match("", " ")
    0.0
    """
    if name1 == name2:<commit_msg>match docstring<commit_after>import re
from affixes import drop_prefixes, drop_suffixes
from split import split
from itertools import combinations
import string

def initial_initial(name):
    pre, fp, lp, suff = split(name)
    if fp:
        fp = fp[0]
    return " ".join([p for p in [pre, fp, lp, suff] if p])

def middle_initials(name):
    parts = name.split(' ')
    name = parts[0]
    for part in parts[1:-1]:
        name += " " + part[0]
    if len(parts) > 1:
        name += " " + parts[-1]
    return name

def last_only(name):
    return split(name)[2]

_funcs = {string.lower: 0.01,
          (lambda s: s.replace('.', '')): 0.02,
          (lambda s: s.replace(',', '')): 0.02,
          initial_initial: 0.03,
          middle_initials: 0.03,
          drop_prefixes: 0.05,
          drop_suffixes: 0.05,
          last_only: 0.20,}
# other things to consider:
# <NAME> -> Stephens, Michael
# accented characters -> unaccented equiv.
# just last name
# remove consecutive inner spaces (probably no penalty)
# some sort of soundex thing?

_combinations = []
for n in xrange(0, len(_funcs)):
    _combinations.extend(combinations(_funcs.items(), n))

def match(name1, name2):
    """
    Provide a measure of the similarity between two name, considering factors
    such as differing word order ('<NAME>' and '<NAME>'), use of
    initials ('<NAME>' and '<NAME>') and
    various titles and honorifics ('<NAME>,
    Jr., USN', and '<NAME>').

    >>> match("<NAME>", "<NAME>")
    1.0
    >>> abs(match("<NAME>", "<NAME>") - 0.99) < 0.001
    True
    >>> abs(match("michaeL StepHens", "<NAME>") - 0.98) < 0.001
    True
    >>> abs(match("<NAME>", "<NAME>") - 0.98) < 0.001
    True
    >>> abs(match("<NAME>", "Mr. <NAME>") - 0.95) < 0.001
    True
    >>> abs(match("Mr. <NAME>", "<NAME>, M.S.") - 0.90) < 0.001
    True
    >>> abs(match("Mr. <NAME>, Jr.", "Dr. <NAME>, USMC (Ret)") - 0.78) < 0.001
    True
    >>> abs(match("<NAME>", "<NAME>") - 0.97) < 0.001
    True
    >>> abs(match("<NAME>", "<NAME>") - 0.97) < 0.001
    True
    >>> abs(match("<NAME>", "Stephens") - 0.80) < 0.001
    True
    >>> match("<NAME>", "<NAME>")
    0.0
    >>> match("", " ")
    0.0
    """
    if name1 == name2:
{'fraction_non_alphanumeric': 0.2052619104053093, 'fraction_numerical': 0.052382081061863, 'mean_word_length': 2.5823429541595924, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 135, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3556451', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1505, 'n_words': 396}