java - Compare two strings without Apache StringUtils -


hi working voice command project. want receive user's voice @ first want check matches , want according command. this, found way match strings using org.apache.commons.lang3.stringutils find many trouble this. ex:- face problem when go import apache's external library android studio. question that:- there other way compare user's voice data , specific command without using apache's stringutils method? please if can

there many string functions can use compare strings, example

   if (result.equals("hello")) {          dosomething();    } 

compares 2 strings

   result.startswith("search for") {          dosomething()    } 

checks beginning of result

   result.matches("yes|sure") {          dosomething()    } 

checks result regular expression.

you can find in java textbook. see example

https://docs.oracle.com/javase/tutorial/java/data/comparestrings.html

if want use levenshtein distance can insert following function in code:

public int levenshteindistance (string s0, string s1) {                               int len0 = s0.length() + 1;                                                          int len1 = s1.length() + 1;                                                           // array of distances                                                            int[] cost = new int[len0];                                                          int[] newcost = new int[len0];                                                        // initial cost of skipping prefix in string s0                                      (int = 0; < len0; i++) cost[i] = i;                                           // dynamically computing array of distances                                        // transformation cost each letter in s1                                         (int j = 1; j < len1; j++) {                                                         // initial cost of skipping prefix in string s1                                      newcost[0] = j;                                                                       // transformation cost each letter in s0                                         for(int = 1; < len0; i++) {                                                          // matching current letters in both strings                                          int match = (s0.charat(i - 1) == s1.charat(j - 1)) ? 0 : 1;                           // computing cost each transformation                                            int cost_replace = cost[i - 1] + match;                                              int cost_insert  = cost[i] + 1;                                                      int cost_delete  = newcost[i - 1] + 1;                                                // keep minimum cost                                                                 newcost[i] = math.min(math.min(cost_insert, cost_delete), cost_replace);         }                                                                                     // swap cost/newcost arrays                                                          int[] swap = cost; cost = newcost; newcost = swap;                               }                                                                                     // distance cost transforming letters in both strings             return cost[len0 - 1];                                                           } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -