SimHashDocumentEncoder

Struct SimHashDocumentEncoder 

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

SimHash Document Encoder.

Encodes documents and text into SDRs where similar documents will have similar representations. Uses the SimHash algorithm with SHA3/SHAKE256 hashing.

§Example

use mokosh::encoders::{SimHashDocumentEncoder, SimHashDocumentEncoderParams, Encoder};

let encoder = SimHashDocumentEncoder::new(SimHashDocumentEncoderParams {
    size: 400,
    active_bits: 21,
    ..Default::default()
}).unwrap();

let tokens = vec!["hello".to_string(), "world".to_string()];
let sdr = encoder.encode_to_sdr(tokens).unwrap();
assert_eq!(sdr.get_sum(), 21);

Implementations§

Source§

impl SimHashDocumentEncoder

Source

pub fn new(params: SimHashDocumentEncoderParams) -> Result<Self>

Creates a new SimHash Document Encoder.

Source

pub fn size_param(&self) -> UInt

Returns the size.

Source

pub fn active_bits(&self) -> UInt

Returns the number of active bits.

Source

pub fn encode_tokens(&self, tokens: &[String], output: &mut Sdr) -> Result<()>

Encode a list of tokens.

Source

pub fn encode_string(&self, input: &str, output: &mut Sdr) -> Result<()>

Encode a string by splitting on whitespace.

Trait Implementations§

Source§

impl Clone for SimHashDocumentEncoder

Source§

fn clone(&self) -> SimHashDocumentEncoder

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SimHashDocumentEncoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Encoder<&str> for SimHashDocumentEncoder

Convenience implementation for string slices.

Source§

fn dimensions(&self) -> &[UInt]

Returns the dimensions of the output SDR.
Source§

fn size(&self) -> usize

Returns the total size of the output SDR.
Source§

fn encode(&self, value: &str, output: &mut Sdr) -> Result<()>

Encodes a value into an SDR. Read more
Source§

fn encode_to_sdr(&self, value: T) -> Result<Sdr>

Encodes a value and returns a new SDR.
Source§

impl Encoder<String> for SimHashDocumentEncoder

Convenience implementation for String.

Source§

fn dimensions(&self) -> &[UInt]

Returns the dimensions of the output SDR.
Source§

fn size(&self) -> usize

Returns the total size of the output SDR.
Source§

fn encode(&self, value: String, output: &mut Sdr) -> Result<()>

Encodes a value into an SDR. Read more
Source§

fn encode_to_sdr(&self, value: T) -> Result<Sdr>

Encodes a value and returns a new SDR.
Source§

impl Encoder<Vec<String>> for SimHashDocumentEncoder

Source§

fn dimensions(&self) -> &[UInt]

Returns the dimensions of the output SDR.
Source§

fn size(&self) -> usize

Returns the total size of the output SDR.
Source§

fn encode(&self, value: Vec<String>, output: &mut Sdr) -> Result<()>

Encodes a value into an SDR. Read more
Source§

fn encode_to_sdr(&self, value: T) -> Result<Sdr>

Encodes a value and returns a new SDR.

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V