Are there any Fuzzy Search or String Similarity Functions libraries written for C#? [closed]
Asked Answered
M

8

71

There are similar question, but not regarding C# libraries I can use in my source code.

Thank you all for your help.

I've already saw lucene, but I need something more easy to search for similar strings and without the overhead of the indexing part.

The answer I marked has got two very easy algorithms, and one uses LINQ too, so it's perfect.

Manmade answered 17/9, 2008 at 14:24 Comment(1)
Why this is off-topic escapes me. The OP is asking if there is a function in a library that SO supports in-depth.Discharge
S
35

Levenshtein distance implementation:

I have a .NET 1.1 project in which I use the latter. It's simplistic, but works perfectly for what I need. From what I remember it needed a bit of tweaking, but nothing that wasn't obvious.

Superannuated answered 17/9, 2008 at 14:38 Comment(5)
Why do you say "Using LINQ" ? None of these implementations uses Linq...Defensible
Actually these implementations are identical, except that the latter uses Substring, which is much slower than using the indexer because it creates new String instances each time...Defensible
Indeed you are correct. I could have sworn that there was some LINQ-love in it, or at least that the headline claimed it was LINQy or something.Superannuated
What if I have 100,000 entries to search, and I want to show the top 20 candidates each time?Absently
Dead link may now be here dotnetperls.com/levenshteinConductor
L
33

you can also look at the very impressive library titled Sam's String Metrics https://github.com/StefH/SimMetrics.Net . this includes a host of algorithms.

  • Hamming distance
  • Levenshtein distance
  • Needleman-Wunch distance or Sellers Algorithm
  • Smith-Waterman distance
  • Gotoh Distance or Smith-Waterman-Gotoh distance
  • Block distance or L1 distance or City block distance
  • Monge Elkan distance
  • Jaro distance metric
  • Jaro Winkler
  • SoundEx distance metric
  • Matching Coefficient
  • Dice’s Coefficient
  • Jaccard Similarity or Jaccard Coefficient or Tanimoto coefficient
  • Overlap Coefficient
  • Euclidean distance or L2 distance
  • Cosine similarity
  • Variational distance
  • Hellinger distance or Bhattacharyya distance
  • Information Radius (Jensen-Shannon divergence)
  • Harmonic Mean
  • Skew divergence
  • Confusion Probability
  • Tau
  • Fellegi and Sunters (SFS) metric
  • TFIDF or TF/IDF
  • FastA
  • BlastP
  • Maximal matches
  • q-gram
  • Ukkonen Algorithms
Libriform answered 8/7, 2009 at 2:4 Comment(3)
The link in this answer is giving me a 403 error. You can use the Wayback Machine instead.Hughey
I believe the .NET version of the library mentioned above is here. After I converted it to Visual Studio 2010, and updated NUnit references, it builds. It also passes 87 tests.Nuke
I found a .net library version of this library on SimMetrics.Net on GitHub. The same as the suggestion from @dalenewman, just on github perhaps?Vankirk
T
14

They are not my own invention, but they are my favorites and I've just blogged about them and published my own tweaked versions of Dice Coefficient, Levenshtein Distance, Longest Common Subsequence and Double Metaphone in a blog post called Four Functions for Finding Fuzzy String Matches in C# Extensions.

Thier answered 28/5, 2011 at 1:42 Comment(3)
These are ready-made in a class that you can just drop into your project. This is the easy man's way to go.Fran
code now on GitHub github.com/tylerjensen/duovia-fuzzystringsSarsen
Updated link to the blog post: tsjensen.com/blog/post/2011/05/27/…Tapley
P
2

Have you taken a look at Lucene.net? It is a port of the Java Lucene search engine API to the .Net platform. That library offers a lot of search functionality. I played around with it a year or so ago, so don't take my suggestion as based on tons of experience. I saw it in the book Windows Developer Power Tools and took it for a test drive. You might look through their API documentation to see if it offers something like the Fuzzy Search for which you are looking.

Primp answered 17/9, 2008 at 14:33 Comment(3)
Could you please tell how to get the degree of similarity using Lucene?Specialty
Sorry, I have not used it professionally. As I mentioned in my post, I just played around with it probably around 2007/2008.Primp
Maybe the book Lucene in Action, 2ed could tell how to get the degree of similarity.Reisfield
W
1

This code project paper has a string similarity function using the Levenshtein distance.

Wallaby answered 17/9, 2008 at 14:35 Comment(0)
P
1

There is the following Levenshtein Distance Algorithm which assigns a value to the similarity of two strings (well, the difference actually), that could be used to build upon: http://www.merriampark.com/ldcsharp.htm

Picked answered 17/9, 2008 at 14:37 Comment(0)
C
0

The Beagle Project for Linux is written in c# (mono) and is a google-desktop like search tool. It may have some code in there for these kind of string matching.

If I recall correctly, it uses the Lucene library for searching and retrieving data. Maybe that can be useful for your project too.

Centralization answered 17/9, 2008 at 14:28 Comment(0)
T
0

I have used "Ternary Search Tree Dictionary in C#" (http://www.codeproject.com/KB/recipes/tst.aspx) to search for similar strings.

Regards, Patricio

Teofilateosinte answered 17/9, 2008 at 16:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.