패키지, 저장소 및 앱 카테고리 검색

패키지 상세v2.2.0

string_similarity

Dice 계수를 기반으로 두 문자열 간의 유사도를 찾습니다. 이는 보통 레벤슈타인 거리보다 더 좋습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
8만
좋아요
129
Pub 점수
160

패키지 설치

flutter pub add string_similarity

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

string_similarity 패키지는 Levenshtein 거리보다 일반적으로 더 정확하고 빠른 방법인 Dice 계수를 사용하여 두 문자열 간의 유사도 수준을 계산합니다. 퍼지 매칭, 오타 수정, 텍스트 데이터에서 중복 감지와 같은 작업에 이상적입니다. 알고리즘은 문자열 간 공유 바이그램을 평가하여 0(일치 없음)에서 1(정확한 일치) 사이의 유사도 점수를 생성합니다. 이 가벼운 유틸리티는 Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼을 지원하며, 효율적인 문자열 비교가 필요한 크로스플랫폼 애플리케이션에 매우 유용합니다.

사용 사례

  • 사용자 입력에서의 퍼지 검색
  • 근접 중복 텍스트 항목 감지
  • 자동 수정 제안
  • 데이터 중복 제거
  • 소스 간 제품 이름 일치
  • 맞춤법 수정

주요 기능

  • 정확도에 Dice 계수를 사용합니다
  • 레벤슈타인과 비교하여 빠른 성능
  • 크로스 플랫폼 호환성
  • 명확한 유사도 점수를 가진 간단한 API
  • 대소문자 구분 없는 비교를 처리합니다
  • 영문이 아닌 문자를 지원합니다

적합한 대상

  • 텍스트 처리 앱
  • 검색 및 자동 완성 기능
  • 데이터 정제 워크플로
  • 사용자 친화적인 입력 검증
  • 빠른 문자열 매칭이 필요한 응용 프로그램

고려 사항

  • 짧은에서 중간 길이의 문자열에 가장 적합
  • 매우 긴 텍스트에 최적화되지 않음
  • 부분 단어 매칭을 지원하지 않습니다
  • 문자열에서 문자열로의 비교에 제한됨
  • 정지어 또는 스테밍에 대한 내장 처리 없음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

string_similarity

pub package license: MIT

A fast, dependency-free Dart package for measuring the similarity between two strings with the Sørensen–Dice coefficient.

Use it for fuzzy search, spelling suggestions, duplicate detection, and ranking the closest match from a list.

✨ Why string_similarity?

  • Simple extension methods and static methods
  • Scores from 0.0 (completely different) to 1.0 (identical)
  • Best-match search with individual ratings and the winning index
  • No runtime dependencies
  • Works on every platform supported by Dart and Flutter

📦 Installation

dart pub add string_similarity

Then import the package:

import 'package:string_similarity/string_similarity.dart';

🚀 Compare two strings

final score = 'healed'.similarityTo('sealed');

print(score); // 0.8

The equivalent static method is:

final score = StringSimilarity.compareTwoStrings('healed', 'sealed');

🏆 Find the best match

final result = 'healed'.bestMatch([
  'edward',
  'sealed',
  'theatre',
]);

print(result.bestMatch.target); // sealed
print(result.bestMatch.rating); // 0.8
print(result.bestMatchIndex); // 1

Every candidate and its score remain available in result.ratings.

The equivalent static method is:

final result = StringSimilarity.findBestMatch(
  'healed',
  ['edward', 'sealed', 'theatre'],
);

🧠 How it works

The package compares adjacent character pairs (bigrams) using the Sørensen–Dice coefficient. Whitespace is removed before comparison. Letter case and diacritics are kept, so Cote, cote, and côte are different values.

🔡 Case-insensitive comparison

Normalize both strings before comparing them:

final score = 'DART'.toLowerCase().similarityTo('dart'.toLowerCase());

print(score); // 1.0

🧩 Available methods

API Returns Description
value.similarityTo(other) double Compares two nullable strings.
value.bestMatch(targets) BestMatch Rates every nullable target and selects the best one.
StringSimilarity.compareTwoStrings(first, second) double Static alternative to similarityTo.
StringSimilarity.findBestMatch(value, targets) BestMatch Static alternative to bestMatch.

BestMatch provides:

  • ratings: every target and its score
  • bestMatch: the highest-rated target
  • bestMatchIndex: the winning target's original index

⚙️ Behavior and edge cases

Input Result
Two identical values, including null or '' 1.0
Only one value is null or empty 0.0
Different values where either has fewer than two characters 0.0
Several targets share the highest score The first one wins
The target list is empty Throws ArgumentError

🔎 Comparison details

  • Whitespace is ignored, but punctuation is not.
  • Comparison is case-sensitive and diacritic-sensitive.
  • The algorithm works on UTF-16 code units rather than grapheme clusters, so some emoji and combined Unicode characters may not behave like visible characters.
  • Sørensen–Dice measures shared bigrams. It is not a drop-in replacement for edit-distance algorithms such as Levenshtein distance.

📄 License

Licensed under the permissive MIT License.

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트