Comparing and Managing Names Using name-tools module in Python
While working with documents, we can have problems in which we need to work with Names. This article discusses the name-tools library which can help to perform this task. It can be used to manage and compare names. It currently includes English and Western Style names.
Use the below command to install the name-tools library:
pip install name_tools
Example 1: Working with split()
The split(), is used to divide the name into 4 parts namely, prefix ( Mr, Dr, etc) , first name, middle name, and suffix (Jr., II, etc).
('Mr.', 'Sandeep', 'Jain', 'Sr.') ('Mr.', 'Manjeet', 'Singh', '') ('Dr.', 'Robert', 'D', 'III')
Example 2: Working with canonicalize()
This function converts the name to its standard format: ‘Prefixes First Last, Suffixes’. The spaces are escaped and words are capitalized.
Mr. Sandeep Jain, Sr. Mr. Manjeet Singh Dr. Robert D 3
Example 3: Comparing names
Comparison of names is done using match(), which takes 2 names and compares to factors such as word orders, initials, honorifics, and titles. Giving each factor a specific weight.
0.95 0.8999999999999999 0.0
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course