Skip to content

Commit

Permalink
docs(readme): add a readme detailing usage
Browse files Browse the repository at this point in the history
Signed-off-by: SphericalKat <[email protected]>
  • Loading branch information
SphericalKat committed Mar 27, 2021
1 parent 6c2feab commit 5f19d9a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 5 deletions.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# FuzzyWuzzy

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!

- No dependencies.
- 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](http://chairnerd.seatgeek.com/fuzzywuzzy-fuzzy-string-matching-in-python/).

## Get started

### Add dependency

```yaml
dependencies:
fuzzywuzzy: 0.1.0 # latest version
```
## 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
```
2 changes: 1 addition & 1 deletion lib/algorithms/weighted_ratio.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:math';

import '../applicable.dart';
import '../fuzzy_search.dart';
import '../fuzzywuzzy.dart';

class WeightedRatio implements Applicable {
static const UNBASE_SCALE = 0.95;
Expand Down
4 changes: 2 additions & 2 deletions lib/fuzzy_search.dart → lib/fuzzywuzzy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ int tokenSetPartialRatio(String s1, String s2) {
return TokenSet().apply(s1, s2, PartialRatio());
}

/// Calculates a weighted ratio between [s1] and [s2] using several different
/// fuzzy matching algorithms
/// Calculates a weighted ratio between [s1] and [s2] using the best option from
/// the above fuzzy matching algorithms
///
/// Example:
/// ```dart
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# See https://dart.dev/tools/pub/glossary#lockfile
packages: {}
sdks:
dart: ">=2.7.0 <3.0.0"
dart: ">=2.12.0 <3.0.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ homepage: "https://github.com/sphericalkat/dart-fuzzywuzzy"
description: An implementation of the popular fuzzywuzzy package in dart

environment:
sdk: ">=2.7.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

0 comments on commit 5f19d9a

Please sign in to comment.