本文整理汇总了Java中net.ricecode.similarity.StringSimilarityServiceImpl类的典型用法代码示例。如果您正苦于以下问题:Java StringSimilarityServiceImpl类的具体用法?Java StringSimilarityServiceImpl怎么用?Java StringSimilarityServiceImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringSimilarityServiceImpl类属于net.ricecode.similarity包,在下文中一共展示了StringSimilarityServiceImpl类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: commandHint
import net.ricecode.similarity.StringSimilarityServiceImpl; //导入依赖的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.StringSimilarityServiceImpl; //导入依赖的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.StringSimilarityServiceImpl; //导入依赖的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);
}