本文整理匯總了Java中net.ricecode.similarity.LevenshteinDistanceStrategy類的典型用法代碼示例。如果您正苦於以下問題:Java LevenshteinDistanceStrategy類的具體用法?Java LevenshteinDistanceStrategy怎麽用?Java LevenshteinDistanceStrategy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LevenshteinDistanceStrategy類屬於net.ricecode.similarity包,在下文中一共展示了LevenshteinDistanceStrategy類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: commandHint
import net.ricecode.similarity.LevenshteinDistanceStrategy; //導入依賴的package包/類
private String commandHint(String command) {
if (command == null || command.isEmpty()) {
return "";
}
SimilarityStrategy strategy = new LevenshteinDistanceStrategy();
StringSimilarityService service = new StringSimilarityServiceImpl(strategy);
double score = 0;
double s;
String result = "";
List<String> crowdinCommands = new LinkedList<>();
crowdinCommands.add(COMMAND_UPLOAD);
crowdinCommands.add(COMMAND_UPLOAD_SOURCES);
crowdinCommands.add(COMMAND_TRANSLATIONS);
crowdinCommands.add(COMMAND_UPLOAD_TRANSLATIONS);
crowdinCommands.add(COMMAND_LINT);
crowdinCommands.add(COMMAND_DOWNLAOD);
crowdinCommands.add(COMMAND_DOWNLAOD_TRANSLATIONS);
crowdinCommands.add(COMMAND_GENERATE);
crowdinCommands.add(COMMAND_PROJECT);
crowdinCommands.add(COMMAND_LIST_PROJECT);
crowdinCommands.add(COMMAND_SOURCES);
crowdinCommands.add(COMMAND_LIST);
crowdinCommands.add(COMMAND_LIST_SOURCES);
crowdinCommands.add(COMMAND_LIST_TRANSLATIONS);
crowdinCommands.add(COMMAND_HELP);
crowdinCommands.add(COMMAND_PUSH);
crowdinCommands.add(COMMAND_PULL);
for (String cmd : crowdinCommands) {
s = service.score(cmd, command);
if (s > score) {
score = s;
result = cmd;
}
}
if (score < 0.5) {
result = "";
}
return result;
}
示例2: getDifference
import net.ricecode.similarity.LevenshteinDistanceStrategy; //導入依賴的package包/類
/**
* Get the difference value of a string.
*
* @param first First value.
* @param second Second value.
*
* @return The string difference value.
*/
public static double getDifference(String first, String second) {
// Make sure both strings are equal
if(first == null || second == null)
return 1.0;
// Create a string comparison server
StringSimilarityService service = new StringSimilarityServiceImpl(new LevenshteinDistanceStrategy());
// Determine the difference score and return it's absolute value
return Math.abs(service.score(first, second) - 1.0);
}
示例3: getDifference
import net.ricecode.similarity.LevenshteinDistanceStrategy; //導入依賴的package包/類
/**
* Get the difference of two strings.
*
* @param first First string
* @param second Second string
*
* @return The difference value
*/
public static double getDifference(String first, String second) {
// Make sure the strings are valid.
if (first == null || second == null) {
return 1.0;
}
// Create a string similarity service instance, to allow comparison
StringSimilarityService service = new StringSimilarityServiceImpl(new LevenshteinDistanceStrategy());
// Determine the difference value, return the result
return Math.abs(service.score(first, second) - 1.0);
}