4

for example the names are

  • abdulah
  • abdullah
  • abdola
  • abdollah
  • S abdullah
  • abdul
  • aabdullah

Now for this I will create a Linq query in C#, the string for example is textString = "abdolah" in result I expect all of them.

var data = db.TableList.where(a=>a.Name.Contains(textString).ToList();

so the question is how or is there any built in library for comparing names in .Net

phuzi
  • 12,078
  • 3
  • 26
  • 50
SAR
  • 1,765
  • 3
  • 18
  • 42
  • Search the web about `fuzzy search`. – aybe Feb 24 '21 at 08:58
  • @searched but could not fine any specific library or class, in php or other there are many helper but kindly if some one know may be experience such so it will make the path shorter for me – SAR Feb 24 '21 at 08:59
  • It depends on how you define "similarity"... – Maciej Los Feb 24 '21 at 09:02
  • https://github.com/JakeBayer/FuzzySharp – aybe Feb 24 '21 at 09:02
  • For this, apache solr can be used – onedevteam.com Feb 24 '21 at 09:02
  • https://nugetmusthaves.com/Tag/fuzzy – aybe Feb 24 '21 at 09:03
  • in c# , is it okay if i calculate the size of string or like that some trick – SAR Feb 24 '21 at 09:03
  • https://github.com/DanHarltey/Fastenshtein – JL0PD Feb 24 '21 at 09:05
  • https://stackoverflow.com/questions/2993087/linq-to-sql-soundex-possible Not sure if it works on all types of words. I have tried it on jon and john, works ok but not sure about 'abdul' and 'aabdullah'. Worth giving it a try. – Allen King Feb 24 '21 at 09:10
  • 1
    Fuzzy wont be perfect, if you have a lot of culture. You have name. Name have known variation. And it's culture related. Spanish Juan is more Juancho than chinese Jwan. I will build simple tree from know list of variation. for the common culture. And levenshtein based on how deep in the tree i am. – Drag and Drop Feb 24 '21 at 09:10
  • I would suggest trying to improve performance of the search so it can be made for each key-press. So the user gets a list of possible candidates, and can quickly try variations or make the search more narrow or broad. – JonasH Feb 24 '21 at 09:29
  • if you mean select2, that can not help in this point – SAR Feb 24 '21 at 09:32

1 Answers1

2

As I suggested above, fastest way to get started is to try one of the libraries I mentioned.

Here's a program wrote in 2 minutes using https://github.com/JakeBayer/FuzzySharp:

Result:

enter image description here

Code:

using System;
using System.IO;
using FuzzySharp;
using FuzzySharp.PreProcess;

namespace zzzzzzzz
{
    internal static class Program
    {
        private static void Main(string[] args)
        {
            var referenceName = "Abdallah";
            var referenceGoal = 80;

            var names = @"
abdulah
abdullah
abdola
abdollah
S abdullah
abdul
aabdullah";

            using (var reader = new StringReader(names))
            {
                while (true)
                {
                    var line = reader.ReadLine();

                    if (line == null)
                        break;

                    var ratio = Fuzz.Ratio(referenceName, line, PreprocessMode.Full);
                    var success = ratio >= referenceGoal;

                    Console.Write($"Current = '{line}', Ratio = {ratio}, Result = ");

                    var color = Console.ForegroundColor;
                    Console.ForegroundColor = success ? ConsoleColor.Green : ConsoleColor.Red;
                    Console.Write($"{(success ? "PASS" : "FAIL")}{Environment.NewLine}");
                    Console.ForegroundColor = color;
                }
            }
        }
    }
}

NuGet package of the library: https://www.nuget.org/packages/FuzzySharp/2.0.2

Edit:

I've tried your example here and I got 100% (obviously)

enter image description here

aybe
  • 15,516
  • 9
  • 57
  • 105
  • https://social.technet.microsoft.com/wiki/contents/articles/26805.c-calculating-percentage-similarity-of-2-strings.aspx i have try this what is your suggestion on this – SAR Feb 24 '21 at 09:26
  • You should definitely give a try to the library I suggested, writing your own or your basing yourself off a snippet is unllikely to work well. If you can't use a library, you can always study how they did it! – aybe Feb 24 '21 at 09:31
  • my result and urs are not same, i am using fuzzy too for example (var ratio = Fuzz.Ratio("Abdallah","Abdallah") = 57 ) but yours is 71 – SAR Feb 24 '21 at 09:41
  • Check out my edit, it just works fine here. – aybe Feb 24 '21 at 09:47