3 import java.io.IOException;
6 import edu.stanford.nlp.ie.crf.CRFClassifier;
7 import edu.stanford.nlp.ling.CoreAnnotations.AnswerAnnotation;
8 import edu.stanford.nlp.ling.CoreLabel;
10 /** https://stanfordnlp.github.io/CoreNLP/api.html */
12 public static void classify(String str) throws ClassCastException, ClassNotFoundException, IOException {
13 CRFClassifier<CoreLabel> classifier;
14 List<List<CoreLabel>> out;
17 classifier = CRFClassifier.getDefaultClassifier();
18 out = classifier.classify(str);
20 for (List<CoreLabel> labels: out)
21 for (CoreLabel l: labels) {
22 cat = l.getString(AnswerAnnotation.class);
24 System.out.println(cat + " " + w);
28 public static void main(String[] args) throws Exception {
29 classify("I live in Washington.");