def match_mail(name, emails, threshold=3, exc=True):
        """
        Tries to match a name among a list of mails.

        @param      name        a name (first name last name separated by a space)
        @param      emails      list of emails
        @param      threshold   above this threshold, mails and names don't match
        @param      exc         raise an Exception if not found
        @return                 list of available mails, boolean

        The second results is True if no email were found in the list.
        """
        # we check the easy case
        if name in emails:
            return [(0, name)]

        pieces = [_.strip() for _ in ProjectsRepository._regex_split.split(
            remove_diacritics(name.lower()))]
        pieces.sort()
        pieces = " ".join(pieces)
        res = []
        for email in emails:
            spl = [_.strip() for _ in ProjectsRepository._regex_split.split(
                remove_diacritics(email.split("@")[0].lower()))]
            spl.sort()
            mail = " ".join(spl)
            d = edit_distance(mail, pieces)[0]
            res.append((d, email))
        res = [_ for _ in res if _[0] <= threshold]
        res.sort()
        if exc and len(res) == 0:
            raise ProjectsRepository.MailNotFound(
                "unable to find a mail for {0} among\n{1}".format(name, "\n".join(emails)))
        return res
    def match_mail(name, emails, threshold=3, exc=True):
        """
        Tries to match a name among a list of mails.

        @param      name        a name (first name last name separated by a space)
        @param      emails      list of emails
        @param      threshold   above this threshold, mails and names don't match
        @param      exc         raise an Exception if not found
        @return                 list of available mails, boolean

        The second results is True if no email were found in the list.
        """
        # we check the easy case
        if name in emails:
            return [(0, name)]

        pieces = [_.strip() for _ in ProjectsRepository._regex_split.split(
            remove_diacritics(name.lower()))]
        pieces.sort()
        pieces = " ".join(pieces)
        res = []
        for email in emails:
            spl = [_.strip() for _ in ProjectsRepository._regex_split.split(
                remove_diacritics(email.split("@")[0].lower()))]
            spl.sort()
            mail = " ".join(spl)
            d = edit_distance(mail, pieces)[0]
            res.append((d, email))
        res = [_ for _ in res if _[0] <= threshold]
        res.sort()
        if exc and len(res) == 0:
            raise ProjectsRepository.MailNotFound(
                "unable to find a mail for {0} among\n{1}".format(name, "\n".join(emails)))
        return res
Ejemplo n.º 3
0
 def split_name(name):
     name = remove_diacritics(name).split(" ")
     first = name[-1]
     last = " ".join(name[:-1])
     return first, last
 def split_name(name):
     name = remove_diacritics(name).split(" ")
     first = name[-1]
     last = " ".join(name[:-1])
     return first, last
Ejemplo n.º 5
0
 def test_accent(self):
     fLOG(
         __file__,
         self._testMethodName,
         OutputPrint=__name__ == "__main__")
     self.assertEqual(remove_diacritics("enguérand"), "enguerand")
Ejemplo n.º 6
0
 def test_accent(self):
     fLOG(__file__,
          self._testMethodName,
          OutputPrint=__name__ == "__main__")
     self.assertEqual(remove_diacritics("enguérand"), "enguerand")