Skip to content

Commit

Permalink
Merge pull request #1298 from Barsik-sus/wca_change_suggestion_library
Browse files Browse the repository at this point in the history
READY: (wca): Replace Eddie library with TextDistance for command suggestion
  • Loading branch information
Wandalen authored Apr 15, 2024
2 parents 65af586 + f4ce672 commit 846aca6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions module/move/wca/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ full = [ "enabled", "on_unknown_suggest" ]
enabled = []

# This configuration suggests an action to be done when the command is unknown. In this case, when an unknown command is encountered, the system might suggest alternatives
on_unknown_suggest = [ "eddie" ]
on_unknown_suggest = [ "dep:textdistance" ]

[[bench]]
name = "bench"
Expand All @@ -49,7 +49,7 @@ former = { workspace = true, features = [ "default" ] }
## external
log = "0.4"
#closure = "0.3"
eddie = { version = "0.4", optional = true } # fuzzy commands search
textdistance = { version = "1.0", optional = true } # fuzzy commands search

[dev-dependencies]
test_tools = { workspace = true }
Expand Down
5 changes: 3 additions & 2 deletions module/move/wca/src/ca/verifier/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ pub( crate ) mod private
#[ cfg( feature = "on_unknown_suggest" ) ]
fn suggest_command< 'a >( dictionary : &'a Dictionary, user_input: &str ) -> Option< &'a str >
{
let jaro = eddie::JaroWinkler::new();
use textdistance::{ Algorithm, JaroWinkler };
let jaro = JaroWinkler::default();
let sim = dictionary
.commands
.iter()
.map( |( name, c )| ( jaro.similarity( name, user_input ), c ) )
.map( |( name, c )| ( jaro.for_str( name, user_input ).nsim(), c ) )
.max_by( |( s1, _ ), ( s2, _ )| s1.total_cmp( s2 ) );
if let Some(( sim, variant )) = sim
{
Expand Down

0 comments on commit 846aca6

Please sign in to comment.