搜索插件、代码仓与 APP 分类

插件详情v1.2.0

fuzzywuzzy

Dart 中流行的 fuzzywuzzy 包的实现,适用于您所有的模糊字符串匹配/搜索需求!

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
7.2万
喜欢数
153
Pub 分数
150

安装插件

flutter pub add fuzzywuzzy

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Fuzzywuzzy 是一个 Dart 实现的流行模糊字符串匹配库,可实现准确且灵活的字符串比较,适用于搜索、去重和数据校验等任务。它使用 Levenshtein 距离和基于标记的方法等算法计算字符串之间的相似度得分,非常适合处理拼写错误、变体和近似匹配。该包支持 Android、iOS、Web、macOS、Windows 和 Linux 等多个平台,确保广泛的兼容性。它轻量且易于通过 Flutter pub 集成。

适合场景

  • 带拼写错误的文本搜索
  • 数据去重
  • 跨数据集的名称匹配
  • 带有容差的自动建议
  • 将用户输入与数据库条目匹配

主要特点

  • Levenshtein 距离评分
  • 令牌排序和集合比率
  • 不区分大小写的匹配
  • 跨平台支持
  • 简单的 API 集成

适合对象

  • 需要强大字符串匹配功能的开发者
  • 用户生成文本输入的应用程序
  • 数据清洗管道
  • 搜索功能支持容错

使用建议

  • 在大型数据集上可能较慢
  • 未针对实时高频匹配进行优化
  • 需要仔细调整阈值以保证准确性

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

FuzzyWuzzy

Tests Coverage Status

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") // 72
ratio("mysmilarstring", "mysimilarstring")        // 97
Partial ratio
partialRatio("similar", "somewhresimlrbetweenthisstring") // 71
Token sort ratio
tokenSortPartialRatio("order words out of", "words out of order") // 100
tokenSortRatio("order words out of","  words out of order")       // 100
Token set ratio
tokenSetRatio("fuzzy was a bear", "fuzzy fuzzy fuzzy bear")         // 100
tokenSetPartialRatio("fuzzy was a bear", "fuzzy fuzzy fuzzy bear")  // 100
Weighted ratio
weightedRatio("The quick brown fox jimps ofver the small lazy dog", "the quick brown fox jumps over the small lazy dog") // 97
Extract
extractOne(
        query: 'cowboys',
        choices: [
          'Atlanta Falcons',
          'New York Jets',
          'New York Giants',
          'Dallas Cowboys'
        ],
        cutoff: 10,
      ) // (string Dallas Cowboys, score: 90, index: 3)
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)]
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)]
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<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(); // (string Dallas Cowboys, score: 90, index: 3)

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目