本文整理汇总了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);
}