locked
How to solve Fuzzy logic string compare operations in .net core RRS feed

  • Question

  • User283528319 posted

    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

    Tuesday, June 11, 2019 9:02 AM

All replies

  • User-1038772411 posted

    Hi, Fatihbarut

    Below Sample code :

    private static void NameMatching()
    {
        //name matching
        string input = "Jensn";
        string[] surnames = new string[] { 
            "Adams",
            "Benson",
            "Geralds",
            "Johannson",
            "Johnson",
            "Jensen",
            "Jordon",
            "Madsen",
            "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);
        }
    }

    Please Refer Below Link for More Understanding

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

    Tuesday, June 11, 2019 10:07 AM
  • User283528319 posted

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

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

    Tuesday, June 11, 2019 12:39 PM
  • User-474980206 posted

    try this article:

       https://bommaritollc.com/2014/06/12/fuzzy-match-sentences-python/

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

     

    Tuesday, June 11, 2019 2:52 PM
  • User283528319 posted

    thanks a lot but I kinda need ready pack solution

    Tuesday, June 11, 2019 3:10 PM
  • User753101303 posted

    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 ?

    Tuesday, June 11, 2019 4:32 PM
  • User283528319 posted

    I dont think full text search solves my problem

    I really need fuzzy logic string comparison of sentences

    Tuesday, June 11, 2019 5:08 PM
  • User-854763662 posted

    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

    http://www.matifnadeem.com/2013/05/compare-similarity-of-two-strings-in.html

    Best Regards ,

    Sherry

    Wednesday, June 12, 2019 5:43 AM
  • User753101303 posted

    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 ?)

    Wednesday, June 12, 2019 7:26 AM
  • User283528319 posted

    I was trying to ask

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

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

    Wednesday, June 12, 2019 7:36 AM
  • User-854763662 posted

    Hi fatihbarut ,

    fatihbarut

    I was trying to ask

    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

    Friday, June 14, 2019 9:19 AM