https://github.com/sphericalkat/dart-fuzzywuzzy
A dart port of the popular fuzzywuzzy package
https://github.com/sphericalkat/dart-fuzzywuzzy
dart-library dart-port fuzzy-search fuzzywuzzy levenshtein null-safety
Last synced: 6 months ago
JSON representation
A dart port of the popular fuzzywuzzy package
- Host: GitHub
- URL: https://github.com/sphericalkat/dart-fuzzywuzzy
- Owner: SphericalKat
- License: gpl-2.0
- Created: 2021-03-27T20:15:32.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-06T04:46:21.000Z (7 months ago)
- Last Synced: 2025-04-02T12:13:41.846Z (6 months ago)
- Topics: dart-library, dart-port, fuzzy-search, fuzzywuzzy, levenshtein, null-safety
- Language: Dart
- Homepage: https://pub.dev/packages/fuzzywuzzy
- Size: 11.7 MB
- Stars: 47
- Watchers: 1
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# FuzzyWuzzy
[](https://github.com/SphericalKat/dart-fuzzywuzzy/actions/workflows/test.yml)
[](https://coveralls.io/github/SphericalKat/dart-fuzzywuzzy?branch=master)This is a Dart port of the popular [FuzzyWuzzy](https://github.com/seatgeek/fuzzywuzzy) python package. This algorithm uses [Levenshtein distance](https://en.wikipedia.org/wiki/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](https://pub.dev/packages/collection)).
- Pure Dart implementation of the superfast [python-Levenshtein](https://github.com/ztane/python-Levenshtein/).
- Simple to use.
- Lightweight.
- Massive props to the folks over at seatgeek for coming up with the [algorithm](https://chairnerd.seatgeek.com/fuzzywuzzy-fuzzy-string-matching-in-python/).## Get started
### Add dependency
```yaml
dependencies:
fuzzywuzzy:
```## Usage
First, import the package
```dart
import 'package:fuzzywuzzy/fuzzywuzzy.dart'
```### Simple ratio
```dart
ratio("mysmilarstring", "myawfullysimilarstirng") // 72
ratio("mysmilarstring", "mysimilarstring") // 97
```### Partial ratio
```dart
partialRatio("similar", "somewhresimlrbetweenthisstring") // 71
```### Token sort ratio
```dart
tokenSortPartialRatio("order words out of", "words out of order") // 100
tokenSortRatio("order words out of"," words out of order") // 100
```### Token set ratio
```dart
tokenSetRatio("fuzzy was a bear", "fuzzy fuzzy fuzzy bear") // 100
tokenSetPartialRatio("fuzzy was a bear", "fuzzy fuzzy fuzzy bear") // 100
```### Weighted ratio
```dart
weightedRatio("The quick brown fox jimps ofver the small lazy dog", "the quick brown fox jumps over the small lazy dog") // 97
```### Extract
```dart
extractOne(
query: 'cowboys',
choices: [
'Atlanta Falcons',
'New York Jets',
'New York Giants',
'Dallas Cowboys'
],
cutoff: 10,
) // (string Dallas Cowboys, score: 90, index: 3)
``````dart
extractTop(
query: 'goolge',
choices: [
'google',
'bing',
'facebook',
'linkedin',
'twitter',
'googleplus',
'bingnews',
'plexoogl'
],
limit: 4,
cutoff: 50,
) // [(string google, score: 83, index: 0), (string googleplus, score: 75, index: 5)]
```
```dart
extractAllSorted(
query: 'goolge',
choices: [
'google',
'bing',
'facebook',
'linkedin',
'twitter',
'googleplus',
'bingnews',
'plexoogl'
],
cutoff: 10,
) // [(string google, score: 83, index: 0), (string googleplus, score: 75, index: 5), (string plexoogl, score: 43, index: 7), (string bingnews, score: 29, index: 6), (string linkedin, score: 29, index: 3), (string facebook, score: 29, index: 2), (string bing, score: 23, index: 1), (string twitter, score: 15, index: 4)]
```
```dart
extractAll(
query: 'goolge',
choices: [
'google',
'bing',
'facebook',
'linkedin',
'twitter',
'googleplus',
'bingnews',
'plexoogl'
],
cutoff: 10,
) // [(string google, score: 83, index: 0), (string bing, score: 23, index: 1), (string facebook, score: 29, index: 2), (string linkedin, score: 29, index: 3), (string twitter, score: 15, index: 4), (string googleplus, score: 75, index: 5), (string bingnews, score: 29, index: 6), (string plexoogl, score: 43, index: 7)]
```
### Extract using any a list of any type
All `extract` methods can receive `List` and return `List>`
```dart
class TestContainer {
final String innerVal;
TestContainer(this.innerVal);
}extractOne(
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(); // (string Dallas Cowboys, score: 90, index: 3)
```