pub trait Similarity {
    // Required method
    fn calculate(&self, a: &HpoTerm<'_>, b: &HpoTerm<'_>) -> f32;
}
Expand description

Trait for similarity score calculation between 2 HpoTerms

hpo already comes pre-loaded with several common and well established similarity algorithms that implement the Similarity trait: Builtins

use hpo::{Ontology, HpoTerm};
use hpo::similarity::Similarity;

struct Foo {}
impl Similarity for Foo {
    /// Calculate similarity based on length of the term names
    fn calculate(&self, a: &HpoTerm, b: &HpoTerm) -> f32 {
        return (a.name().len() - b.name().len()) as f32
    }
}

let ontology = Ontology::from_binary("tests/example.hpo").unwrap();
let term1 = ontology.hpo(12638u32).unwrap();
// ==> "Abnormal nervous system physiology"
let term2 = ontology.hpo(100547u32).unwrap();
// ==> "Abnormal forebrain morphology"

let ic = Foo{};

let similarity = ic.calculate(&term1, &term2);
assert_eq!(similarity, 5.0);

Required Methods§

source

fn calculate(&self, a: &HpoTerm<'_>, b: &HpoTerm<'_>) -> f32

calculates the actual similarity between term a and term b

Implementors§