NameComparisonToolkit 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package NameComparisonToolkit --version 1.0.0
NuGet\Install-Package NameComparisonToolkit -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NameComparisonToolkit" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NameComparisonToolkit --version 1.0.0
#r "nuget: NameComparisonToolkit, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NameComparisonToolkit as a Cake Addin
#addin nuget:?package=NameComparisonToolkit&version=1.0.0

// Install NameComparisonToolkit as a Cake Tool
#tool nuget:?package=NameComparisonToolkit&version=1.0.0

NameComparisonToolkit

A powerful and flexible .NET library for comparing names in a variety of ways. It allows you to compare names using different comparison types, as well as providing useful methods for tokenizing, containing, and intersecting names.

Table of Contents

Features

  • Compare names using a variety of comparison types
  • Generate full names from individual name components (first, middle, last, and suffix)
  • Retrieve a tokenized version of a name as a list of strings
  • Check if a name is contained within another name
  • Check if a name intersects with another name
  • Calculate similarity between names

Usage

First, import the library:

using NameComparisonToolkit;

Mext, create a Name object for each name you want to compare:

var name1 = new Name("John", "Doe");
var name2 = new Name("John", "Smith");

Comparing Names

Compare the two names using all available comparison types:

var name1 = new Name("John Jacob", "Doe Smith");
var name2 = new Name("John Jacob", "Smith Doe");

var matches = name1.Matches(name2);

foreach (var result in matches)
{
    Console.WriteLine($"Comparison Type: {result.ComparisonType}");
    Console.WriteLine($"Is Match: {result.IsMatch}");
    Console.WriteLine($"Similarity: {result.Similarity}");
}

Example output:

"ComparisonType": "Exact"
"IsMatch": false
"Similarity": 0.5
// ...

Compare the two names ignoring the order of the name parts:

var name1 = new Name("John Jacob", "Doe Smith");
var name2 = new Name("Jacob John", "Smith Doe");

var matchesIgnoreOrder = name1.MatchesIgnoreOrder(name2);

foreach (var result in matchesIgnoreOrder)
{
    Console.WriteLine($"Comparison Type: {result.ComparisonType}");
    Console.WriteLine($"Is Match: {result.IsMatch}");
    Console.WriteLine($"Similarity: {result.Similarity}");
}

Example output:

"ComparisonType": "Exact"
"IsMatch": true
"Similarity": 1.0
// ...

Containing Names

Check if the current name object is contained within the given name string:

var name1 = new Name("John Jacob", "Doe Smith");

var containsResult = name1.Contains("John Jacob Doe Smith is a test subject");

Console.WriteLine($"Comparison Type: {containsResult.ComparisonType}");
Console.WriteLine($"Contains: {containsResult.IsMatch}");
Console.WriteLine($"Similarity: {containsResult.Similarity}");

Example output:

"ComparisonType": "Exact"
"IsMatch": true
"Similarity": 1.0
// ...

Intersecting Names

Check if the given name object intersects with the current name object:

var name1 = new Name("John Jacob", "Doe Smith");
var name2 = new Name("John", "Smith");

var intersectsResult = name1.Intersects(name2);

Console.WriteLine($"Comparison Type: {intersectsResult.ComparisonType}");
Console.WriteLine($"Intersects: {intersectsResult.IsMatch}");
Console.WriteLine($"Similarity: {intersectsResult.Similarity}");

Example output:

"ComparisonType": "Exact"
"IsMatch": true
"Similarity": 0.5
// ...

Comparison Results

Each of the methods above returns a collection of ComparisonResult objects. Each ComparisonResult contains the comparison type, whether the names match, and the similarity score between the names.

To iterate through the results and print the comparison type, match status, and similarity:

foreach (var result in matches)
{
    Console.WriteLine($"Comparison Type: {result.ComparisonType}");
    Console.WriteLine($"Is Match: {result.IsMatch}");
    Console.WriteLine($"Similarity: {result.Similarity}");
}

Similarity Score

The similarity score is calculated for each comparison between two names, providing a quantitative measure of how similar the names are. The score ranges from 0.0 to 1.0, where 0.0 represents no similarity and 1.0 indicates an exact match. The similarity score takes into account both the matching characters and the length of the names being compared.

Here's a high-level explanation of how the similarity score is calculated:

  1. Compare the two names character by character.
  2. If the characters match, add 1 to the matching character count.
  3. Calculate the maximum possible matching character count based on the length of the names.
  4. Divide the matching character count by the maximum possible matching character count to get the similarity score.

The similarity score can be utilized to filter or rank results based on how closely the names match. For example, you can use the similarity score to show only the names with a similarity score above a certain threshold or to sort the results by similarity score in descending order.

Example:

var name1 = new Name("John Jacob", "Doe Smith");
var name2 = new Name("Jon Jacob", "Doe Smyth");

var matches = name1.Matches(name2);

foreach (var result in matches)
{
    Console.WriteLine($"Comparison Type: {result.ComparisonType}");
    Console.WriteLine($"Is Match: {result.IsMatch}");
    Console.WriteLine($"Similarity: {result.Similarity}");
}

// Filtering results based on similarity score
var similarityThreshold = 0.8;
var filteredResults = matches.Where(result => result.Similarity >= similarityThreshold);

// Sorting results by similarity score in descending order
var sortedResults = matches.OrderByDescending(result => result.Similarity);

Additional Features

The library also includes:

  • Methods for generating full names, tokenized names, and checking if a name is contained within another name
  • A collection of common name suffixes

Installation

This library is available as a NuGet package. To install, use the following command:

Using the .NET CLI:

dotnet add package NameComparisonToolkit

Using the Package Manager Console:

Install-Package NameComparisonToolkit

License

This library is released under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 207 12/5/2023
1.0.2 110 10/2/2023
1.0.1 156 5/19/2023
1.0.0 186 5/1/2023
0.0.4 173 4/21/2023
0.0.3 169 4/21/2023
0.0.2 161 4/21/2023
0.0.1 166 4/19/2023

This package takes name parts as strings, compares, then returns MatchResults object with data from multiple matching methods and a matching score