diff --git a/code/common/vr_match.pl b/code/common/vr_match.pl new file mode 100644 index 000000000..bf2b7df4c --- /dev/null +++ b/code/common/vr_match.pl @@ -0,0 +1,16 @@ +sub phrase_match1 { + my ($phrase) = @_; + my (%list1); + my $d_min1 = 999; + my $set1 = 'abcdefghijklmnopqrstuvwxyz0123456789'; + my @phrases = &Voice_Cmd::voice_items('mh', 'no_category'); + for my $phrase2 (sort @phrases) { + my $d = pdistance($phrase, $phrase2, $set1, \&distance, {-cost => [0.5,0,4], -mode => 'set'}); +# my $brianlendist = abs(length($phrase)-length($phrase2)); +# $d = $brianlendist + $d; +# print_log "---------------- $phrase --- $phrase2 --- $d"; + push @{$list1{$d}}, $phrase2 if $d <= $d_min1; + $d_min1 = $d if $d < $d_min1; + } + return ${$list1{$d_min1}}[0]; +} \ No newline at end of file diff --git a/web/bin/runit.pl b/web/bin/runit.pl new file mode 100644 index 000000000..f4883b063 --- /dev/null +++ b/web/bin/runit.pl @@ -0,0 +1,38 @@ +return &runit(@ARGV); +sub runit { + my ($cmd) = "@_"; + #print_log "-------------------- Original Command: $cmd"; + $cmd =~ s/_/ /g; + #print_log "-------------------- Manipulated Command: $cmd"; + # Look for exact command matches + if (&process_external_command($cmd, 1, 'android', 'speak')) { + print_log "-------------------- Exact Command Match $cmd"; + return &html_page('', 'done'); + } + + # added by Brian: STRIP out articles and then check for exact command match + $cmd =~ s/the //g; + $cmd =~ s/to //g; + $cmd =~ s/turn //g; + + $cmd =~ s/an //g; + $cmd =~ s/make //g; + $cmd =~ s/switch //g; + + if (&process_external_command($cmd, 1, 'android', 'speak')) { + print_log "-------------------- Exact Command Match removing articles $cmd"; + return &html_page('', 'done'); + } + + # Look for nearest fuzzy match + my $cmd1 = &phrase_match1($cmd); + print_log "-------------------- Fuzzy Command Match $cmd1"; + &process_external_command($cmd1, 1, 'android', 'speak'); + return &html_page('', 'done'); + +# # Added by Brian: Give up +# print_log "-------------------- No command found $cmd"; +# play('file' => 'c:\mh\sounds\log.wav'); +# return &html_page('', 'No command found'); + +} \ No newline at end of file