Stanford nlp 不兼容类型:无法将对象转换为CoreLabel

Stanford nlp 不兼容类型:无法将对象转换为CoreLabel,stanford-nlp,Stanford Nlp,我试图使用斯坦福代币器,并从其网站上获得以下示例: import java.io.FileReader; import java.io.IOException; import java.util.List; import edu.stanford.nlp.ling.CoreLabel; import edu.stanford.nlp.ling.HasWord; import edu.stanford.nlp.process.CoreLabelTokenFactory; import edu.s

我试图使用斯坦福代币器,并从其网站上获得以下示例:

import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.HasWord;
import edu.stanford.nlp.process.CoreLabelTokenFactory;
import edu.stanford.nlp.process.DocumentPreprocessor;
import edu.stanford.nlp.process.PTBTokenizer;

public class TokenizerDemo {

  public static void main(String[] args) throws IOException {
    for (String arg : args) {
      // option #1: By sentence.
      DocumentPreprocessor dp = new DocumentPreprocessor(arg);
      for (List sentence : dp) {
        System.out.println(sentence);
      }
      // option #2: By token
      PTBTokenizer ptbt = new PTBTokenizer(new FileReader(arg),
              new CoreLabelTokenFactory(), "");
      for (CoreLabel label; ptbt.hasNext(); ) {
        label = ptbt.next();
        System.out.println(label);
      }
    }
  }
}
当我试图编译它时,我得到以下错误:

TokenizerDemo.java:24: error: incompatible types: Object cannot be converted to CoreLabel
        label = ptbt.next();

有人知道原因是什么吗?如果您感兴趣,我将使用Java 1.8,并确保CLASSPATH包含jar文件。

尝试参数化
PTBTokenizer
类。例如:

PTBTokenizer<CoreLabel> ptbt = new PTBTokenizer<>(new FileReader(arg),
          new CoreLabelTokenFactory(), "");
PTBTokenizer ptbt=新的PTBTokenizer(新文件读取器(arg),
新CoreLabelTokenFactory(),“”);