stringmatcher 1.0.0

  • Readme
  • Changelog
  • Installing
  • new46

StringMatcher #

This is a library for fuzzy comparison of two strings. It supports 3 types of comparison - char, word, and ngram.

This library, in turn, is also a nice wrapper over various comparison algorithms that you can also implement yourself.

Usage #

Each instance of the class when calling 3 functions - similar, partialSimilar, partialSimilarOne returns a measure of similarity (StringMatcherValue) expressed in a ratio, percent, distance.

similar

This is a normal function that returns the result of comparing 2 strings.

import 'package:stringmatcher/stringmatcher.dart';

void main() {

  var s1 = 'fizz';
  var s2 = 'fizz';
  var sim = StringMatcher(term: Term.char, algorithm: Levenshtein());
  print(sim.similar(s1, s2).ratio);
}

Output:

1.0

partialSimilar

This is a normal function that returns the result of comparing the source string among a list of strings.

import 'package:stringmatcher/stringmatcher.dart';

void main() {

  var source = 'buzz';
  var listStrings = ['dart', 'flutter', 'anime', 'buzz'];

  var sim = StringMatcher(term: Term.char, algorithm: Levenshtein());
  print(sim.partialSimilar(source, listStrings,
        (a, b) => a.ratio.compareTo(b.ratio),
        selector: (x) => x.percent,
        limit: 3));
}

Output:

[[buzz, 100.0], [flutter, 14.28571428571429], [dart, 0.0]]

partialSimilarOne

The same as partial Similar, but returns the very first element instead of a list.

import 'package:stringmatcher/stringmatcher.dart';

void main() {

  var source = 'buzz';
  var listStrings = ['dart', 'flutter', 'anime', 'buzz'];

  var sim = StringMatcher(term: Term.char, algorithm: Levenshtein());
  print(sim.partialSimilarOne(source, listStrings,
        (a, b) => a.ratio.compareTo(b.ratio),
        selector: (x) => x.percent));
}

Output:

[buzz, 100.0]

Custom algorithm #

You can also implement your own algorithms.

import 'package:stringmatcher/stringmatcher.dart';

class FakeAlgorithm implements Algorithm {
  @override
  double getRatio(List<String> first, List<String> second) {
    return 1.0;
  }

}

void main() {

  var s1 = 'fizz';
  var s2 = 'buzz';
  var sim = StringMatcher(term: Term.char, algorithm: FakeAlgorithm());
  print(sim.similar(s1, s2).ratio);
}

Output:

1.0

Support types #

When calling functions of the similar type, you can pass certain data types as 2 strings.

StringMatcher supports the following types:

  • String
  • List
  • List<List (Not implemented)

1.0.0 #

  • Initial version, created by Stagehand

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  stringmatcher: ^1.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:stringmatcher/stringmatcher.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
46
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15

Health suggestions

Fix lib/src/algs/cosine.dart. (-0.50 points)

Analysis of lib/src/algs/cosine.dart reported 1 hint:

line 2 col 8: Unused import: 'dart:math'.

Fix lib/src/algs/jaro.dart. (-0.50 points)

Analysis of lib/src/algs/jaro.dart reported 1 hint:

line 2 col 8: Unused import: 'dart:math'.

Format lib/src/algorithm.dart.

Run dartfmt to format lib/src/algorithm.dart.

Fix additional 5 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/algs/levenshtein.dart (Run dartfmt to format lib/src/algs/levenshtein.dart.)
  • lib/src/extends.dart (Run dartfmt to format lib/src/extends.dart.)
  • lib/src/stringmatcher_base.dart (Run dartfmt to format lib/src/stringmatcher_base.dart.)
  • lib/src/stringmatcher_value.dart (Run dartfmt to format lib/src/stringmatcher_value.dart.)
  • lib/stringmatcher.dart (Run dartfmt to format lib/stringmatcher.dart.)

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and stringmatcher.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.8.0 <3.0.0
meta ^1.1.0 1.2.2 1.3.0-nullsafety
tuple ^1.0.3 1.0.3
Transitive dependencies
matcher 0.12.8
path 1.7.0
quiver 2.1.3
stack_trace 1.9.5
Dev dependencies
pedantic ^1.8.0
test ^1.6.0