# How to solve Fuzzy logic string compare operations in .net core RSS

## 10 replies

Last post Jun 14, 2019 09:19 AM by Sherry Chen

• fatihbarut

Member

92 Points

534 Posts

### How to solve Fuzzy logic string compare operations in .net core

Hi all,

I need to compare sentences for similarity (and get the result as percentage) using fuzzy logic.

Is there any easy way to do it in .net core?

thanks

Participant

840 Points

497 Posts

### Re: How to solve Fuzzy logic string compare operations in .net core

Hi, Fatihbarut

Below Sample code :

```private static void NameMatching()
{
//name matching
string input = "Jensn";
string[] surnames = new string[] {
"Benson",
"Geralds",
"Johannson",
"Johnson",
"Jensen",
"Jordon",
"Stratford",
"Wilkins"
};

Console.WriteLine("Dice Coefficient for Jensn:");
foreach (var name in surnames)
{
double dice = input.DiceCoefficient(name);
Console.WriteLine("\t{0} against {1}",
dice.ToString("###,###.00000"), name);
}

Console.WriteLine();
Console.WriteLine("Levenshtein Edit Distance for Jensn:");
foreach (var name in surnames)
{
int leven = input.LevenshteinDistance(name);
Console.WriteLine("\t{0} against {1}", leven, name);
}

Console.WriteLine();
Console.WriteLine("Longest Common Subsequence for Jensn:");
foreach (var name in surnames)
{
var lcs = input.LongestCommonSubsequence(name);
Console.WriteLine("\t{0}, {1} against {2}",
lcs.Item2.ToString("###,###.00000"), lcs.Item1, name);
}

Console.WriteLine();
string mp = input.ToDoubleMetaphone();
Console.WriteLine("Double Metaphone for Jensn: {0}", mp);
foreach (var name in surnames)
{
string nameMp = name.ToDoubleMetaphone();
Console.WriteLine("\t{0} metaphone for {1}", nameMp, name);
}
}```

http://www.tsjensen.com/blog/post/2011/05/27/Four+Functions+For+Finding+Fuzzy+String+Matches+In+C+Extensions

Ashish Jain
• fatihbarut

Member

92 Points

534 Posts

### Re: How to solve Fuzzy logic string compare operations in .net core

thanks a lot but could you expand this example to sentence?

because I need to compare sentences with white spaces and several words.

• bruce (sqlwo...

All-Star

56784 Points

14951 Posts

### Re: How to solve Fuzzy logic string compare operations in .net core

Jun 11, 2019 02:52 PM|bruce (sqlwork.com)|LINK

it is for python, but almost all fuzzy logic examples are for python (the most popular AI language).

bruce (sqlwork.com)
• fatihbarut

Member

92 Points

534 Posts

### Re: How to solve Fuzzy logic string compare operations in .net core

thanks a lot but I kinda need ready pack solution

• PatriceSc

All-Star

47690 Points

17659 Posts

### Re: How to solve Fuzzy logic string compare operations in .net core

Hi,

And the db you are using is ? Seems you want some kind of full text search ?

Edit: according to a previous post you are using MySQL. See perhaps if https://dev.mysql.com/doc/refman/8.0/en/fulltext-search.html#function_match could be used ?

• fatihbarut

Member

92 Points

534 Posts

### Re: How to solve Fuzzy logic string compare operations in .net core

I dont think full text search solves my problem

I really need fuzzy logic string comparison of sentences

• Sherry Chen

Contributor

2030 Points

606 Posts

### Re: How to solve Fuzzy logic string compare operations in .net core

Jun 12, 2019 05:43 AM|Sherry Chen|LINK

Hi fatihbarut ,

Try to refer to  the following links  which involves Fuzzy string comparison and comparison of strings as sentence

https://stackoverflow.com/questions/24948750/implement-smart-search-fuzzy-string-comparison

Best Regards ,

Sherry

MSDN Community Support
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
• PatriceSc

All-Star

47690 Points

17659 Posts

### Re: How to solve Fuzzy logic string compare operations in .net core

And the final goal is ? You don't compare a user input to db stored  data ? What about synonyms or conjugation ?

For now it could go from using an already suggested algorithm once the sentence is maybe splited into words (and more likely you'll need to start with something simple and enhance over time) to using an existing library or product (for example maybe a bot framework if this is what you are trying to do ?)

• fatihbarut

Member

92 Points

534 Posts

### Re: How to solve Fuzzy logic string compare operations in .net core

Is there anyone who knows how to use one of these packages?

https://www.nuget.org/packages?q=fuzzy+logic

• Sherry Chen

Contributor

2030 Points

606 Posts

### Re: How to solve Fuzzy logic string compare operations in .net core

Jun 14, 2019 09:19 AM|Sherry Chen|LINK

Hi fatihbarut ,

#### fatihbarut

Is there anyone who knows how to use one of these packages?

https://www.nuget.org/packages?q=fuzzy+logic

Refer to the below links on FuzzyStrings.NetStandard package which may be helpful :

https://nugetmusthaves.com/Package/FuzzyStrings.NetStandard

https://github.com/rangp/fuzzystrings

Best Regards ,

Sherry

MSDN Community Support