本文整理汇总了Java中com.darkprograms.speech.util.StringUtil类的典型用法代码示例。如果您正苦于以下问题:Java StringUtil类的具体用法?Java StringUtil怎么用?Java StringUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringUtil类属于com.darkprograms.speech.util包,在下文中一共展示了StringUtil类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseResponse
import com.darkprograms.speech.util.StringUtil; //导入依赖的package包/类
/**
* Parses the response into a Google Response
* @param rawResponse The raw String you want to parse
* @param gr The GoogleResponse you want to parse into ti.
*/
private void parseResponse(String rawResponse, GoogleResponse gr){
if(rawResponse == null || !rawResponse.contains("\"result\"")){ return; }
if(rawResponse.contains("\"confidence\":")){
String confidence = StringUtil.substringBetween(rawResponse, "\"confidence\":", "}");
gr.setConfidence(confidence);
}
else{
gr.setConfidence(String.valueOf(1d));
}
String array = StringUtil.trimString(rawResponse, "[", "]");
if(array.contains("[")){
array = StringUtil.trimString(array, "[", "]");
}
String[] parts = array.split(",");
gr.setResponse(parseTranscript(parts[0]));
for(int i = 1; i<parts.length; i++){
gr.getOtherPossibleResponses().add(parseTranscript(parts[i]));
}
}
示例2: parseResponse
import com.darkprograms.speech.util.StringUtil; //导入依赖的package包/类
/**
* Parses the String into a GoogleResponse object
*
* @param rawResponse
* The String you want to parse
* @param gr
* the GoogleResponse object to save the data into.
*/
private void parseResponse(String rawResponse , GoogleResponse gr) {
if (rawResponse == null || !rawResponse.contains("\"result\"") || rawResponse.equals("{\"result\":[]}")) {
return;
}
gr.getOtherPossibleResponses().clear(); // Emptys the list
if (rawResponse.contains("\"confidence\":")) {
String confidence = StringUtil.substringBetween(rawResponse, "\"confidence\":", "}");
gr.setConfidence(confidence);
} else {
gr.setConfidence(String.valueOf(1));
}
String response = StringUtil.substringBetween(rawResponse, "[{\"transcript\":\"", "\"}],");
if (response == null) {
response = StringUtil.substringBetween(rawResponse, "[{\"transcript\":\"", "\",\"");
}
gr.setResponse(response);
gr.setFinalResponse(rawResponse.contains("\"final\":true"));
String[] currentHypos = rawResponse.split("\\[\\{\"transcript\":\"");
for (int i = 2; i < currentHypos.length; i++) {
String cleaned = currentHypos[i].substring(0, currentHypos[i].indexOf('\"'));
gr.getOtherPossibleResponses().add(cleaned);
}
}
示例3: parseResponse
import com.darkprograms.speech.util.StringUtil; //导入依赖的package包/类
/**
* Parses the String into a GoogleResponse object
*
* @param rawResponse The String you want to parse
* @param gr the GoogleResponse object to save the data into.
*/
private void parseResponse(String rawResponse, GoogleResponse gr) {
if (rawResponse == null || !rawResponse.contains("\"result\"")
|| rawResponse.equals("{\"result\":[]}")) {
return;
}
gr.getOtherPossibleResponses().clear(); // Emptys the list
if (rawResponse.contains("\"confidence\":")) {
String confidence = StringUtil.substringBetween(rawResponse, "\"confidence\":", "}");
gr.setConfidence(confidence);
} else {
gr.setConfidence(String.valueOf(1));
}
String response = StringUtil.substringBetween(rawResponse, "[{\"transcript\":\"", "\"}],");
gr.setResponse(response);
String[] currentHypos = rawResponse.split("\\[\\{\"transcript\":\"");
for (int i = 2; i < currentHypos.length; i++) {
String cleaned = currentHypos[i].substring(0, currentHypos[i].indexOf("\""));
gr.getOtherPossibleResponses().add(cleaned);
}
}
示例4: parseResponse
import com.darkprograms.speech.util.StringUtil; //导入依赖的package包/类
/**
* Parses the String into a GoogleResponse object
* @param rawResponse The String you want to parse
* @param gr the GoogleResponse object to save the data into.
*/
private void parseResponse(String rawResponse, GoogleResponse gr){
if(rawResponse == null || !rawResponse.contains("\"result\"")
|| rawResponse.equals("{\"result\":[]}")){ return; }
gr.getOtherPossibleResponses().clear(); // Emptys the list
if(rawResponse.contains("\"confidence\":")){
String confidence = StringUtil.substringBetween(rawResponse, "\"confidence\":", "}");
gr.setConfidence(confidence);
}
else{
gr.setConfidence(String.valueOf(1));
}
String response = StringUtil.substringBetween(rawResponse, "[{\"transcript\":\"", "\"}],");
if (response == null) {
response = StringUtil.substringBetween(rawResponse, "[{\"transcript\":\"", "\",\"");
}
gr.setResponse(response);
gr.setFinalResponse(rawResponse.contains("\"final\":true"));
String[] currentHypos = rawResponse.split("\\[\\{\"transcript\":\"");
for(int i = 2; i<currentHypos.length; i++){
String cleaned = currentHypos[i].substring(0, currentHypos[i].indexOf("\""));
gr.getOtherPossibleResponses().add(cleaned);
}
}
示例5: parseTranscript
import com.darkprograms.speech.util.StringUtil; //导入依赖的package包/类
/**
* Cleans up the transcript portion of the String
* @param s The string you want to process.
* @return The reformated string.
*/
private String parseTranscript(String s){
String tmp = s.substring(s.indexOf(":")+1);
if(s.endsWith("}")){
tmp = tmp.substring(0, tmp.length()-1);
}
tmp = StringUtil.stripQuotes(tmp);
return tmp;
}