FuzzyWuzzy
This is a Dart port of the popular FuzzyWuzzy python package. This algorithm uses Levenshtein distance to calculate similarity between strings.
I personally needed to use this for my own search algorithms, and there weren't any packages as good as my experience with FuzzyWuzzy was, so here we are. Enjoy!
Just one dependency (collection ).
Pure Dart implementation of the superfast python-Levenshtein .
Simple to use.
Lightweight.
Massive props to the folks over at seatgeek for coming up with the algorithm .
Get started
Add dependency
dependencies:
fuzzywuzzy: <latest version>
Usage
First, import the package
import 'package:fuzzywuzzy/fuzzywuzzy.dart'
Simple ratio
ratio ("mysmilarstring" , "myawfullysimilarstirng" )
ratio ("mysmilarstring" , "mysimilarstring" )
Partial ratio
partialRatio ("similar" , "somewhresimlrbetweenthisstring" )
Token sort ratio
tokenSortPartialRatio ("order words out of" , "words out of order" )
tokenSortRatio ("order words out of" ," words out of order" )
Token set ratio
tokenSetRatio ("fuzzy was a bear" , "fuzzy fuzzy fuzzy bear" )
tokenSetPartialRatio ("fuzzy was a bear" , "fuzzy fuzzy fuzzy bear" )
Weighted ratio
weightedRatio ("The quick brown fox jimps ofver the small lazy dog" , "the quick brown fox jumps over the small lazy dog" )
Extract
extractOne (
query: 'cowboys' ,
choices: [
'Atlanta Falcons' ,
'New York Jets' ,
'New York Giants' ,
'Dallas Cowboys'
],
cutoff: 10 ,
)
extractTop (
query: 'goolge' ,
choices: [
'google' ,
'bing' ,
'facebook' ,
'linkedin' ,
'twitter' ,
'googleplus' ,
'bingnews' ,
'plexoogl'
],
limit: 4 ,
cutoff: 50 ,
)
extractAllSorted (
query: 'goolge' ,
choices: [
'google' ,
'bing' ,
'facebook' ,
'linkedin' ,
'twitter' ,
'googleplus' ,
'bingnews' ,
'plexoogl'
],
cutoff: 10 ,
)
extractAll (
query: 'goolge' ,
choices: [
'google' ,
'bing' ,
'facebook' ,
'linkedin' ,
'twitter' ,
'googleplus' ,
'bingnews' ,
'plexoogl'
],
cutoff: 10 ,
)
Extract using any a list of any type
All extract methods can receive List<T> and return List<ExtractedResult<T>>
class TestContainer {
final String innerVal;
TestContainer (this .innerVal);
}
extractOne<TestContainer >(
query: 'cowboys' ,
choices: [
'Atlanta Falcons' ,
'New York Jets' ,
'New York Giants' ,
'Dallas Cowboys'
].map ((e) => TestContainer (e)).toList (),
cutoff: 10 ,
getter: (x) => x.innerVal
).toString ();