0

I want to call CRF++ toolkit from a java program. I type the following:

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();

But, I have the the following error:

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

I 'm wondering if any one could help me?

Tevo D
  • 3,351
  • 21
  • 28
amibar
  • 31
  • 7
  • is .../template a file or a directory? Can you try it with only the latter file? I guess you messed up the commandline params. Have you tried running the same from a shell? – Fildor Oct 16 '12 at 15:12
  • I tried running the same from shell and I have the same – amibar Oct 16 '12 at 15:22
  • Have you tried using only one of the two files? **Or** perhaps "files" shall be a directory? have you tried just giving "/home/toshiba/Bureau/CRF++-0.54/example/atb/" ? – Fildor Oct 16 '12 at 15:25
  • I have the same while using one of the two files – amibar Oct 16 '12 at 15:29
  • template and .data are two files that should be exist in the command crf_learn !! – amibar Oct 16 '12 at 15:32
  • [Here](http://crfpp.googlecode.com/svn/trunk/doc/index.html#format), there are in deed several files given ... – Fildor Oct 16 '12 at 15:33
  • Do those files have to reside in the same dir as the executable? (Wild guess) – Fildor Oct 16 '12 at 15:34
  • of course, they should be in the same dir – amibar Oct 16 '12 at 15:37

2 Answers2

0

I don't think that's a bug in CRF++, since you are able to run it from command line. So the actual question is how to pass arguments properly when starting a process using Runtime.exec(). I would suggest trying the following:

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);

This may help since Runtime.exec() sometimes splits the command line into arguments in a rather strange fashion.

Another potential problem is mentioned here: Java Runtime.exec()

Community
  • 1
  • 1
Qnan
  • 3,714
  • 18
  • 15
0

There's a simple solution for this. Just write your command into a temporary file and execute that file as Runtime.getRuntime.exec("sh <temp-filename>"). Later you can delete this file. I will explain reason behind this if this solution works for you.

Mukund K Roy
  • 175
  • 1
  • 8