crf++-0.58java调用

import java.io.File;

public class crf {
  static crf crf;
  private crf(){

  }
  public static crf getInstance(){
      if(crf==null){
          crf=new crf();
      }
      return crf;
  }
  public void crf_learn(String traindata,String model,String workDir){


        String cmd = "cmd.exe /c crf_learn template "+traindata+" "+model;
        File Dir = new File(workDir);
        Process p = null;
        try {
            p = Runtime.getRuntime().exec(cmd, null, Dir);
        } catch (Exception e) {
            e.printStackTrace();
        }
        p.destroy();

    }

    public void crf_test(String testdata, String model,String workDir){

        File out = new File(workDir+"out.txt");
        String st = "cmd.exe /c crf_test -m "+model+" " + testdata + ">"+out;
        File Dir = new File(workDir);

        Process q = null;
        try {
            q = Runtime.getRuntime().exec(st, null, Dir);
        } catch (Exception e) {
            e.printStackTrace();
        }
        q.destroy();
    }
}

你可能感兴趣的:(crf)