gpt4 book ai didi

java - 多次使用 agrep.exe 的 Java ProcessBuilder

转载 作者:太空宇宙 更新时间:2023-11-04 13:47:12 29 4
gpt4 key购买 nike

我的Java程序需要启动agrep.exe,其参数包含大矩阵中所有元素对的参数,并获取两个字符串的匹配错误数。我写了一段代码,但是运行速度很慢。我可以加快这部分代码的速度吗?或者,也许你可以建议我一些 agrep 函数的 java 实现?

public static double getSignatureDistance(String one, String two) throws IOException, InterruptedException {
String strReprOne = one.replace(".*","").replace("\\.",".");
String strReprTwo = two.replace(".*","").replace("\\.",".");

PrintWriter writer = new PrintWriter("tmp.txt", "UTF-8");
writer.print(strReprTwo);
writer.close();

List<String> cmd = new ArrayList<>();
cmd.add("agrep.exe");
cmd.add("-B");
cmd.add(one);
cmd.add("tmp.txt");

ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectErrorStream(true);
Process proc = pb.start();

BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream()));

StringBuilder lineBuilder = new StringBuilder();
String line = "";
char[] buf = new char[2];
while (in.read(buf) == 2) {
lineBuilder.append(buf);
}
line = lineBuilder.toString();

Pattern p = Pattern.compile("(\\d+)\\serror");
Matcher m = p.matcher(line);
double agrep = 0;
if(m.find()) {
agrep = Double.valueOf(m.group(1));
}

in.close();
proc.destroy();

double length = strReprOne.length();
return agrep/length;
}

我可以使用 FREJ 库来实现此目的吗?比如对字符串进行匹配,得到匹配结果,然后乘以匹配区域的长度?

最佳答案

没有人知道,所以我使用了 FREJ 库。

关于java - 多次使用 agrep.exe 的 Java ProcessBuilder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30710570/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com