Skip to content

Commit

Permalink
emails
Browse files Browse the repository at this point in the history
  • Loading branch information
philipperemy committed Oct 1, 2024
1 parent c0424d2 commit 02cc791
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ def split():
first_name, last_name = extract_names_from_email(nd, q)
if first_name is not None:
result_first_name = nd.search(first_name)['first_name']
if result_first_name is not None:
result_first_name['name'] = first_name
else:
result_first_name = None
if last_name is not None:
result_last_name = nd.search(last_name)['last_name']
if result_last_name is not None:
result_last_name['name'] = last_name
else:
result_last_name = None
result_first_name['name'] = first_name
result_last_name['name'] = last_name
result = {
'first_name': result_first_name,
'last_name': result_last_name
Expand Down
13 changes: 9 additions & 4 deletions names_dataset/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,25 @@ def _infer_best_split(nd: NameDataset, full_name: str):

def _general_score(nd: NameDataset, candidate: str):
c = nd.search(candidate)
s1 = _compute_score(c['first_name'])
s2 = _compute_score(c['last_name'])
return max(s1, s2)
if c['first_name'] is not None and c['last_name'] is not None:
s1 = _compute_score(c['first_name'])
s2 = _compute_score(c['last_name'])
return max(s1, s2)
return float('-inf')


def extract_names_from_email(nd: NameDataset, email: str):
email = email.strip()
if '' in email:
email = email.split(' ')[0]
if '@' not in email:
email += '@gmail.com'

email = ''.join([e for e in list(email) if not e.isnumeric()])

prefix, suffix = email.split('@')

no_names = ['contact', 'sales', 'info', 'hello', 'reply']
no_names = ['contact', 'sales', 'info', 'hello', 'reply', 'service', 'client']
for no_name in no_names:
if no_name in prefix:
return None, None
Expand Down

0 comments on commit 02cc791

Please sign in to comment.