搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案