Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ readme = "README.md"
keywords = ["nlp", "stemming", "information", "retrieval", "language"]
license = "MIT/BSD-3-Clause"

[features]
default = ["serde"]
serde = ["dep:serde", "dep:serde_derive"]

[dependencies]
serde = "^1.0"
serde_derive = "^1.0"
serde = { version = "^1.0", optional = true }
serde_derive = { version = "^1.0", optional = true }
27 changes: 26 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
//! assert_eq!(en_stemmer.stem("fruitlessly"), "fruitless");
//! }
//! ```
#[cfg(feature="serde")]
extern crate serde;

#[cfg(feature="serde")]
#[macro_use]
extern crate serde_derive;

Expand All @@ -33,7 +36,8 @@ use snowball::algorithms;

/// Enum of all supported algorithms.
/// Check the [Snowball-Website](https://snowballstem.org/) for details.
#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum Algorithm {
Arabic,
Armenian,
Expand Down Expand Up @@ -322,4 +326,25 @@ mod tests {
}
}

#[cfg(feature = "serde")]
fn dummy_serialization_function<T: serde::Serialize>(x: T) {
drop(x)
}

#[cfg(feature = "serde")]
fn dummy_deserialization_function<T: serde::de::DeserializeOwned>(x: T) {
drop(x)
}


#[cfg(feature = "serde")]
#[test]
fn serialization() {
let algorithm = Algorithm::English;
dummy_deserialization_function(algorithm);

let algorithm2 = Algorithm::Spanish;
dummy_serialization_function(algorithm2);
}

}
14 changes: 7 additions & 7 deletions src/snowball/algorithms/armenian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ struct Context {
}

fn r_mark_regions(env: &mut SnowballEnv, context: &mut Context) -> bool {
context.i_pV = env.limit;
context.i_p2 = env.limit;
context.i_pV = env.limit as i32;
context.i_p2 = env.limit as i32;
let v_1 = env.cursor;
'lab0: loop {
'golab1: loop {
Expand All @@ -235,7 +235,7 @@ fn r_mark_regions(env: &mut SnowballEnv, context: &mut Context) -> bool {
}
env.next_char();
}
context.i_pV = env.cursor;
context.i_pV = env.cursor as i32;
'golab3: loop {
'lab4: loop {
if !env.out_grouping(G_v, 1377, 1413) {
Expand Down Expand Up @@ -272,15 +272,15 @@ fn r_mark_regions(env: &mut SnowballEnv, context: &mut Context) -> bool {
}
env.next_char();
}
context.i_p2 = env.cursor;
context.i_p2 = env.cursor as i32;
break 'lab0;
}
env.cursor = v_1;
return true;
}

fn r_R2(env: &mut SnowballEnv, context: &mut Context) -> bool {
if !(context.i_p2 <= env.cursor){
if !(context.i_p2 <= env.cursor as i32){
return false;
}
return true;
Expand Down Expand Up @@ -345,11 +345,11 @@ pub fn stem(env: &mut SnowballEnv) -> bool {
r_mark_regions(env, context);
env.limit_backward = env.cursor;
env.cursor = env.limit;
if env.cursor < context.i_pV {
if env.cursor < context.i_pV as usize {
return false;
}
let v_3 = env.limit_backward;
env.limit_backward = context.i_pV;
env.limit_backward = context.i_pV as usize;
let v_4 = env.limit - env.cursor;
r_ending(env, context);
env.cursor = env.limit - v_4;
Expand Down