Skip to main content

Measure

Struct Measure 

Source
pub struct Measure { /* private fields */ }
Expand description

Node similarity measurement calculator.

This struct calculates the content, child list and matched child list distance between nodes using the Q-gram distance algorithm.

Implementations§

Source§

impl Measure

Source

pub fn new() -> Self

Creates a new Measure instance.

Source

pub fn get_distance(&mut self, a: Option<&NodeRef>, b: Option<&NodeRef>) -> f64

Returns content distance between nodes.

The distance is normalized between 0.0 and 1.0 (MAX_DIST). Returns 1.0 if node types are incompatible (element vs text).

Source

pub fn string_dist_str(&mut self, a: &str, b: &str) -> i32

Calculates string distance using Q-gram algorithm.

Source

pub fn string_dist_chars(&mut self, a: &[char], b: &[char]) -> i32

Calculates string distance for char arrays using Q-gram algorithm.

Source

pub fn child_list_distance(&mut self, a: &NodeRef, b: &NodeRef) -> f64

Calculates child list distance between nodes.

This compares children by their content hashes to measure structural similarity. Returns ZERO_CHILDREN_MATCH (1.0) if both nodes have no children.

Source

pub fn matched_child_list_distance( &mut self, base: &NodeRef, branch: &NodeRef, _is_left: bool, ) -> i32

Calculates matched child list distance.

This measures how well children of a base node match children of a branch node, based on their matching relationships (not content hashes).

§Arguments
  • base - The base node
  • branch - The branch node
  • _is_left - Whether the branch is the left branch (unused, for API compatibility)

Trait Implementations§

Source§

impl Default for Measure

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.