Package crfplusplus

Source Code of crfplusplus.Crf

package crfplusplus;
/***************************************************************************
Clinical Named Entity Recognizer and Normalizer(Clinical NERC), (v0.1).
Copyright (C) 2013  Azad Dehghan

Contact:  a.dehghan@manchester.ac.uk
*****************************************************************************/
import java.util.ArrayList;
import org.chasen.crfpp.Tagger;

public class Crf {

  /**
   * load libraries
   */
  static {
      try {
        System.loadLibrary("CRFPP");
      } catch (UnsatisfiedLinkError e) {
        System.err.println("Cannot load the example native code.\nMake sure your LD_LIBRARY_PATH contains \'.\'\n" + e);
        System.exit(1);
      }
    }
 
  public static String run(String model, ArrayList<String> list)
  {
    String taggedResult = "";

    //set model and parameters
    Tagger tagger = new Tagger("-m " + model);
    // clear internal context
    tagger.clear();
     
    String fVector = "";
    for(String s : list)
    {
      fVector += s;
    }
    //apply model / tag
    tagger.parse(fVector);

    /**
     * get and refine tagged context
     */
    for (int i = 0; i < tagger.size(); ++i) {
      for (int j = 0; j < tagger.xsize(); ++j) {}
      taggedResult +=  tagger.x(i, 0) + "\t" + tagger.y2(i) + "\n"; //get filename:TokenId and predicted label
    }
    tagger.delete();
   
  return taggedResult;
  }
}
TOP

Related Classes of crfplusplus.Crf

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.