Kronosinhaven

Friday, July 8, 2011

NER dedection using standford NER

import edu.stanford.nlp.ie.AbstractSequenceClassifier;
import edu.stanford.nlp.ie.crf.CRFClassifier;
import java.util.ArrayList;


public class nameEntities {

public static String serializedClassifier = "./res/ner-eng-ie.crf-4-conll.ser.gz";
public static AbstractSequenceClassifier classifier = CRFClassifier.getClassifierNoExceptions(serializedClassifier);




public static ArrayList findNamedEntity(String sentance)
{
ArrayList arr=new ArrayList();

try {

String taggedSentance=classifier.testStringInlineXML(sentance);
String temp="";

while(taggedSentance.contains(""))
{
temp=taggedSentance.substring(taggedSentance.indexOf(""), taggedSentance.indexOf("")+"".length());
taggedSentance=taggedSentance.replace(temp, "");
arr.add(temp.trim());
}

while(taggedSentance.contains(""))
{
temp=taggedSentance.substring(taggedSentance.indexOf(""), taggedSentance.indexOf("")+"".length());
taggedSentance=taggedSentance.replace(temp, "");
arr.add(temp.trim());
}

while(taggedSentance.contains(""))
{
temp=taggedSentance.substring(taggedSentance.indexOf(""), taggedSentance.indexOf("")+"".length());
taggedSentance=taggedSentance.replace(temp, "");
arr.add(temp.trim());
}

while(taggedSentance.contains(""))
{
temp=taggedSentance.substring(taggedSentance.indexOf(""), taggedSentance.indexOf("")+"".length());
taggedSentance=taggedSentance.replace(temp, "");
arr.add(temp.trim());
}



} catch (Exception e) {
e.printStackTrace();
}
return arr;
}


}

No comments:

Post a Comment