我想从java程序调用CRF++工具包。我键入以下内容:
Process process = runtime.exec("/home/toshiba/Bureau/CRF++-0.54/.libs/lt-crf_learn /home/toshiba/Bureau/CRF++-0.54/example/atb/template /home/toshiba/Bureau/CRF++-0.54/example/atb/tr_java.data");
process.waitFor();但是,我有以下错误:
CRF++: Yet Another CRF Tool Kit
Copyright (C) 2005-2009 Taku Kudo, All rights reserved.
Usage: /home/toshiba/Bureau/CRF++-0.54/.libs/lt-crf_learn [options] files
-f, --freq=INT use features that occuer no less than INT(default 1)
-m, --maxiter=INT set INT for max iterations in LBFGS routine(default 10k)
-c, --cost=FLOAT set FLOAT for cost parameter(default 1.0)
-e, --eta=FLOAT set FLOAT for termination criterion(default 0.0001)
-C, --convert convert text model to binary model
-t, --textmodel build also text model file for debugging
-a, --algorithm=(CRF|MIRA) select training algorithm
-p, --thread=INT number of threads(default 1)
-H, --shrinking-size=INT set INT for number of iterations variable needs to be optimal before considered for shrinking. (default 20)
-v, --version show the version and exit
-h, --help show this help and exit我想知道有没有人能帮我一下?
发布于 2012-10-17 23:20:54
我不认为这是CRF++中的错误,因为您可以从命令行运行它。因此,实际的问题是在使用Runtime.exec()启动进程时如何正确地传递参数。我建议尝试以下几种方法:
String[] cmd = {"/home/toshiba/Bureau/CRF++-0.54/.libs/lt-crf_learn",
"/home/toshiba/Bureau/CRF++-0.54/example/atb/template",
"/home/toshiba/Bureau/CRF++-0.54/example/atb/tr_java.data"};
Process p = Runtime.getRuntime().exec(cmd);这可能会有所帮助,因为Runtime.exec()有时会以一种相当奇怪的方式将命令行拆分为参数。
这里提到了另一个潜在的问题:Java Runtime.exec()
发布于 2012-12-04 01:57:10
对此有一个简单的解决方案。只需将您的命令写入一个临时文件并以Runtime.getRuntime.exec("sh <temp-filename>")身份执行该文件。稍后您可以删除此文件。如果这个解决方案对你有效,我会解释背后的原因。
https://stackoverflow.com/questions/12917239
复制相似问题