本文整理匯總了Java中org.apache.commons.lang3.StringUtils.removePattern方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.removePattern方法的具體用法?Java StringUtils.removePattern怎麽用?Java StringUtils.removePattern使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang3.StringUtils
的用法示例。
在下文中一共展示了StringUtils.removePattern方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
public void run() throws Exception {
final File file = new File(inputFile);
if (!file.exists() || !file.isFile()) {
System.err.format("unable to access file %s\n", inputFile);
System.exit(2);
}
// Open file
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
// Initialize RestTemplate
RestTemplate restTemplate = new RestTemplate();
if (textAsJson) {
List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters();
converters.add(new ExtendedMappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(converters);
}
// Read each line
String line = null;
while ((line = br.readLine()) != null) {
// Check if label indicator is up front
String label = null;
if (line.matches("^\\d:\\s.*")) {
label = line.substring(0, 1);
}
// Just in case
line = StringUtils.removePattern(line, "^\\d:\\s");
String[] fields = line.split(",");
// Maybe strip quotes
for (int i = 0; i < fields.length; i++) {
final String field = fields[i];
if (field.matches("^\".*\"$")) {
fields[i] = field.substring(1, field.length() - 1);
}
}
int[] shape = (isSequential) ?
new int[] { 1, 1, fields.length} :
new int[] { 1, fields.length};
INDArray array = Nd4j.create(shape);
for (int i=0; i<fields.length; i++) {
// TODO: catch NumberFormatException
Double d = Double.parseDouble(fields[i]);
int[] idx = (isSequential) ?
new int[]{0, 0, i} :
new int[]{0, i};
array.putScalar(idx, d);
}
Inference.Request request = new Inference.Request(Nd4jBase64.base64String(array));
final Object response = restTemplate.postForObject(
inferenceEndpoint,
request,
Inference.Response.Classify.class);
System.out.format("Inference response: %s\n", response.toString());
if (label != null) {
System.out.format(" Label expected: %s\n", label);
}
}
br.close();
}
示例2: handle
import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類
@Override
protected String handle(String input, String second) {
return StringUtils.removePattern(input, second);
}