Skip to content

Commit

Permalink
emails
Browse files Browse the repository at this point in the history
  • Loading branch information
philipperemy committed Oct 11, 2024
1 parent 6d79fee commit 78de5d9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions names_dataset/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ def try_to_split_with_two_last_names(nd: NameDataset, email: str):
candidate1 = most_common[0][0]
candidate2, candidate3 = extract_names_from_email(nd, email.replace(candidate1, ''))

if candidate2 is None or candidate3 is None:
# if candidate2 is not None:
# return candidate1, None, None
# if candidate3 is not None:
# return candidate1, candidate3, None
return candidate1, None, None

fn1, ln1 = _infer_first_and_last_names(candidate1, candidate2, nd)
fn2, ln2 = _infer_first_and_last_names(candidate1, candidate3, nd)
fn3, ln3 = _infer_first_and_last_names(candidate2, candidate3, nd)
Expand Down
43 changes: 43 additions & 0 deletions tests/test_from_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,49 @@

class TestEmail(unittest.TestCase):

def test_bugs_1(self):
# http://philipperemy.ddns.net:9999/[email protected]
# http://philipperemy.ddns.net:9999/[email protected]
# It seems that always expect at least 2 parameters.
# If you try: http://philipperemy.ddns.net:9999/[email protected] it works but not form
# http://philipperemy.ddns.net:9999/[email protected]
# or
# http://philipperemy.ddns.net:9999/[email protected]
inputs = [
'[email protected]',
'[email protected]',
'[email protected]'
]

outputs = [
['remy', None],
[None, 'remy'],
['remy', None],
]

outputs2 = [
['remy', None, None],
['remy', None, None],
['remy', None, None],
['remy', None, None],
]

nd = NameDataset()
for input_, output_, output2_ in zip(inputs, outputs, outputs2):
first_name, last_name = extract_names_from_email(nd, input_)
print(input_)
print('output=', first_name, last_name)
print('expected=', output_[0], output_[1])
self.assertEqual(output_[0], first_name)
self.assertEqual(output_[1], last_name)

first_name, last_name, last_name2 = try_to_split_with_two_last_names(nd, input_)

self.assertEqual(output2_[0], first_name)
self.assertEqual(output2_[1], last_name)
self.assertEqual(output2_[2], last_name2)
print('[OK]')

def test_with_three_3(self):
inputs = [
'perezmartiisabel',
Expand Down

0 comments on commit 78de5d9

Please sign in to comment.