def test_retrieve_nicknames_for_name_with_successful_name(self):
     """
     Can retrieve nicknames for a name that we know has nicknames?
     """
     generated_names = retrieve_nicknames_for_name(self.first_name)
     generated_names.sort()
     expected_names = ['Jim', 'Jimmie', 'Jimmy', 'Jamie']
     expected_names.sort()
     self.assertListEqual(generated_names, expected_names)
Exemple #2
0
    def _enumerate_full_name_representations(self):
        """
        Enumerate a person's full name in the common ways full names can be represented.
        Includes common nicknames for the person's first name and middle name/initial when the
        person has a middle name.  Full names generated are intended to be compared to
        full names obtained from API services, email servers, etc.

        For example:
        Variants of *James Herbert Bond* include, but aren't limited to the following:

        * James Bond
        * Bond James
        * James Herbert Bond
        * James H Bond
        * Jimmy Bond
        * Bond, James
        * Bond, James Herbert
        * Bond, Jim Herbert

        .. todo::
            * Migrate to use the `get_[f]ml_name_variations()` functions.
            * Remove some of the noise via nickname probability mappings

        :return: None
        """
        fml_patterns = [
            '{f} {m} {l}',   '{m} {l} {f}',   '{l} {f} {m}',
            '{f}, {m}, {l}', '{m}, {l}, {f}', '{l}, {f}, {m}',
            '{l}, {f} {m}'
        ]
        fl_patterns = ['{f} {l}', '{l} {f}', '{l}, {f}']
        first_name, middle_name, last_name = self.person.first_name, None, self.person.last_name
        if self.person.has_middle_name():
            middle_name = self.person.middle_name

        # TODO: Remove some of the noise via nickname probability mappings
        # Build a list of potential first names. E.g. Robert > Bob or Johnathan > John > Jon
        nick_names = retrieve_nicknames_for_name(first_name)
        first_names = [first_name]
        first_names.extend(nick_names)

        # Generate our list of potential full name variants
        generated_names = set()
        for first in first_names:
            # Add full first/last name variants
            for pattern in fl_patterns:
                generated_names.add(pattern.format(f=first, l=last_name))

            # Add full first/middle/last name variants, including middle initial variants
            for pattern in fml_patterns if middle_name else []:
                generated_names.add(pattern.format(f=first, m=middle_name, l=last_name))
                generated_names.add(pattern.format(f=first, m=middle_name[0], l=last_name))

        self.full_name_representations = generated_names
 def test_retrieve_nicknames_for_name_with_fake_name(self):
     """
     Do we receive an empty list for a name without nicknames?
     """
     generated_names = retrieve_nicknames_for_name('abcdefg')
     self.assertListEqual(generated_names, [])