邮件地址与姓名的词语相似性

2024-09-21 03:20:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题和简单的词有点不同相似性问题是,有什么算法可以用来计算邮件地址和名称之间的相似性。你知道吗

    for example:
    mail Abd_tml_1132@gmail.com
    Name Abdullah temel
    levenstein,hamming distance  11
    jaro distance  0.52

但最有可能的是,这个邮件地址属于这个名字。你知道吗


Tags: name名称com算法forexamplemail相似性
2条回答

没有直接套餐,但这可以解决您的问题:

将电子邮件id放入列表

a = 'Abd_tml_1132@gmail.com'
rest = a.split('@', 1)[0] # Removing @
result = ''.join([i for i in rest if not i.isdigit()]) ## Removing digits as no names contains digits in them
list_of_email_words =result.split('_') # making a list of all the words. The separator can be changed from _ or . w.r.t to email id
list_of_email_words = list(filter(None, list_of_email_words )) # remove any blank values

为列表命名:

b = 'Abdullah temel'
list_of_name_words =b.split(' ')

对两个列表应用模糊匹配:

score =[]
for i in range(len(list_of_email_words)):
    for j in range(len(list_of_name_words)):
        d = fuzz.partial_ratio(list_of_email_words[i],list_of_name_words[j])
        score.append(d)

现在您只需要检查score的任何元素是否大于您可以定义的阈值。例如:

threshold = 70
if any(x>threshold for x in score):
    print ("matched")

fuzzyfuzzy可以帮助您找到所需的解决方案。首先使用regex从字符串中删除'@'和域名。你将有2个字符串如下-

from fuzzywuzzy import fuzz as fz
str1 = "Abd_tml_1132"
str2 = "Abdullah temel"

count_ratio = fz.ratio(str1,str2)
print(count_ratio)

输出-

46

相关问题 更多 >

    热门问题