Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial ratio #10

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
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