Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4c3d5f3
add score alignment struct
ljnsn Dec 8, 2024
83c1aab
partial_ratio v1
ljnsn Dec 8, 2024
f5c87d8
use batch comparator for partial ratio impl
ljnsn Dec 8, 2024
e8900f4
change short needle name
ljnsn Dec 9, 2024
5f8aae9
fix wrong call
ljnsn Dec 10, 2024
9d65c4b
unwrap to zero
ljnsn Dec 10, 2024
e23005a
add tests
ljnsn Dec 10, 2024
d98e40a
collect into vec for perf
ljnsn Dec 10, 2024
77fb71b
remove useless reconstruct
ljnsn Dec 10, 2024
b1f61bb
minor niceness improvement
ljnsn Dec 10, 2024
89f6094
don't multiply score by 100
ljnsn Dec 10, 2024
158e579
add alignment output type
ljnsn Dec 12, 2024
ef1e2be
derive clone and copy for score alignment
ljnsn Dec 12, 2024
e352abf
simplify code and improve typing
ljnsn Dec 12, 2024
1dee801
add test for partial_ratio_with_args returning None
ljnsn Jan 12, 2025
2ea22a8
fix comment
ljnsn Jan 12, 2025
42c6bf8
pass in charset
ljnsn Jan 12, 2025
e153709
fix: pass in batch comparator
ljnsn Jan 13, 2025
d5510ba
add PartialRatioBatchComparator
ljnsn Jan 13, 2025
01fc88c
tive tests better names
ljnsn Jan 26, 2025
0cdb9dd
use assert_delta
ljnsn Jan 26, 2025
d8d45cf
fix: return None if score lower than cutoff
ljnsn Jan 26, 2025
d5daf50
test: add more tests
ljnsn Jan 26, 2025
ef63376
fix: return 1 for two empty strings
ljnsn Jan 26, 2025
02ec7e7
add test for issue 257
ljnsn Jan 26, 2025
f0a679e
add test for issue 219
ljnsn Jan 26, 2025
7f8a332
fix: typo in test name
ljnsn Jan 21, 2026
e06bd33
implement optimized partial ratio for short strings
ljnsn Jan 21, 2026
81a7df9
fix: simplify and calculate full distance for windows
ljnsn Jan 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::distance::common::ScoreAlignment;
use std::fmt::Debug;

#[derive(Default, Copy, Clone)]
Expand Down Expand Up @@ -50,16 +51,19 @@ where
T: Copy,
{
type Output: Copy + Into<Option<T>> + PartialEq + Debug;
type AlignmentOutput: Copy + Into<Option<ScoreAlignment>> + PartialEq + Debug;

fn cutoff(&self) -> Option<T>;
fn score(&self, raw: T) -> Self::Output;
fn alignment(&self, raw: Option<ScoreAlignment>) -> Self::AlignmentOutput;
}

impl<T> SimilarityCutoff<T> for NoScoreCutoff
where
T: Copy + PartialEq + Debug,
{
type Output = T;
type AlignmentOutput = ScoreAlignment;

fn cutoff(&self) -> Option<T> {
None
Expand All @@ -68,13 +72,18 @@ where
fn score(&self, raw: T) -> Self::Output {
raw
}

fn alignment(&self, raw: Option<ScoreAlignment>) -> Self::AlignmentOutput {
raw.unwrap()
}
}

impl<T> SimilarityCutoff<T> for WithScoreCutoff<T>
where
T: Copy + PartialOrd + Debug,
{
type Output = Option<T>;
type AlignmentOutput = Option<ScoreAlignment>;

fn cutoff(&self) -> Option<T> {
Some(self.0)
Expand All @@ -83,4 +92,8 @@ where
fn score(&self, raw: T) -> Self::Output {
(raw >= self.0).then_some(raw)
}

fn alignment(&self, raw: Option<ScoreAlignment>) -> Self::AlignmentOutput {
raw
}
}
1 change: 1 addition & 0 deletions src/distance.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod common;
pub mod damerau_levenshtein;
pub mod hamming;
pub mod indel;
Expand Down
15 changes: 15 additions & 0 deletions src/distance/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
Tuple like object describing the position of the compared strings in
src and dest.

It indicates that the score has been calculated between
src[src_start:src_end] and dest[dest_start:dest_end]
*/
#[derive(PartialEq, Debug, Clone, Copy)]
pub struct ScoreAlignment {
pub score: f64,
pub src_start: usize,
pub src_end: usize,
pub dest_start: usize,
pub dest_end: usize,
}
Loading