Fast, configurable lexical similarity scoring for UTF-8 text.
Fuzler combines token overlap, grapheme-aware edit distance, and bounded partial matching in a Rust NIF scheduled on a dirty CPU scheduler.
similarity_score/2 is the compact API. compare/2 explains the component
scores, while similarity_scores/2 and top_matches/3 process collections
with a single native call.
Examples
iex> Fuzler.similarity_score("Hello, WORLD!", "hello world")
1.0
iex> Fuzler.similarity_score("bella ciao", "ciao bella")
0.7
iex> Fuzler.similarity_score("café", "café")
1.0
iex> comparison = Fuzler.compare("needle", "some text with needle inside")
iex> comparison.score
0.6
iex> Fuzler.top_matches("milano", ["Roma", "Milano", "Milano Centrale"], 2)
[
%Fuzler.Match{value: "Milano", score: 1.0, index: 1},
%Fuzler.Match{value: "Milano Centrale", score: 0.75, index: 2}
]Scores are symmetric, rounded to two decimal places, and always in
0.0..1.0. Fuzler measures lexical similarity; it does not understand
synonyms or semantic meaning.
Summary
Functions
Returns the version of the scoring algorithm used by this release.
Returns a detailed breakdown of a comparison.
Returns the lexical similarity between two UTF-8 strings.
Scores every target against one query in a single dirty-CPU NIF call.
Returns the best limit targets ordered by descending similarity.
Types
@type score() :: float()
A similarity value in the inclusive range 0.0..1.0.
Functions
@spec algorithm_version() :: String.t()
Returns the version of the scoring algorithm used by this release.
@spec compare(String.t(), String.t(), [Fuzler.Options.option()]) :: Fuzler.Comparison.t()
Returns a detailed breakdown of a comparison.
token_score is nil when both normalised inputs contain a single token.
matched_text contains the normalised target window when partial matching
wins over the full-string score.
@spec similarity_score(String.t(), String.t(), [Fuzler.Options.option()]) :: score()
Returns the lexical similarity between two UTF-8 strings.
See Fuzler.Options for the accepted options. The two-argument form uses
the documented defaults.
@spec similarity_scores(String.t(), [String.t()], [Fuzler.Options.option()]) :: [ score() ]
Scores every target against one query in a single dirty-CPU NIF call.
The returned scores preserve the input order. The batch is limited by the
:max_batch_size option.
@spec top_matches(String.t(), [String.t()], non_neg_integer(), [ Fuzler.Options.option() ]) :: [ Fuzler.Match.t() ]
Returns the best limit targets ordered by descending similarity.
Equal scores retain input order. Each %Fuzler.Match{} includes the
original value and its zero-based input index.