Skip to content

Commit

Permalink
added serde support for more structures
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Feb 13, 2025
1 parent e131fab commit 18ce89e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Weights {
}
}

#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
pub enum DistanceThreshold {
///The distance threshold is expressed as a ratio of the total length of the text fragment under consideration, should be in range 0-1
Ratio(f32),
Expand Down Expand Up @@ -107,7 +107,8 @@ impl FromStr for DistanceThreshold {
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(default)]
pub struct SearchParameters {
/// Maximum anagram distance. The difference in characters (regardless of order)
pub max_anagram_distance: DistanceThreshold,
Expand Down Expand Up @@ -303,15 +304,15 @@ pub struct Distance {
pub samecase: bool,
}

#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum StopCriterion {
Exhaustive,

/// Stop when we find an exact match with a lexical weight higher or equal than the specified value here
StopAtExactMatch,
}

#[derive(Debug, Clone, PartialEq, PartialOrd)]
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
pub enum VariantReference {
///The current item is a reference for a variant. The score expressed similarity from the
///variant to the reference.
Expand Down
9 changes: 6 additions & 3 deletions src/vocab.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use bitflags::bitflags;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use crate::types::*;

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct VocabValue {
pub text: String,

Expand All @@ -28,6 +29,8 @@ pub struct VocabValue {
}

bitflags! {
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
pub struct VocabType: u8 {
/// Indexed for variant matching
const NONE = 0b00000000;
Expand Down Expand Up @@ -94,15 +97,15 @@ pub type VocabEncoder = HashMap<String, VocabId>;

///Frequency handling in case of duplicate items (may be across multiple lexicons), the
///associated with it.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum FrequencyHandling {
Sum,
Max,
Min,
Replace,
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct VocabParams {
///Column containing the Text (if any, 0-indexed)
pub text_column: u8,
Expand Down

0 comments on commit 18ce89e

Please sign in to comment.