1
我使用NER模塊3.3.1沒有問題,但是當我試圖用NER模塊3.6.0(或任何比去年更高版本),我得到了以下異常:錯誤運行斯坦福NER模型3.6.0
[java] Loading classifier from ./lib/stanford-ner-2015-12-09/classifiers/english.muc.7class.distsim.crf.ser.gz ... Exception in thread "main" java.lang.ClassCastException: java.lang.Integer (in module: java.base) cannot be cast to edu.stanford.nlp.sequences.FeatureFactory (in module: Unnamed Module)
[java] at edu.stanford.nlp.ie.crf.CRFClassifier.loadClassifier(CRFClassifier.java:2606)
[java] at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1622)
[java] at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1677)
[java] at edu.stanford.nlp.ie.AbstractSequenceClassifier.loadClassifier(AbstractSequenceClassifier.java:1664)
[java] at edu.stanford.nlp.ie.crf.CRFClassifier.getClassifier(CRFClassifier.java:2832)
[java] at sss.texttools.Cleaner.ner(Cleaner.java:67)
[java] at sss.lucene.LuceneManager.getAnswer(LuceneManager.java:114)
[java] at sss.main.Main.main(Main.java:114)
下面是代碼:
import edu.stanford.nlp.ie.AbstractSequenceClassifier;
import edu.stanford.nlp.ie.crf.*;
import edu.stanford.nlp.ling.CoreLabel;
import java.io.IOException;
public class Cleaner {
private String serializedClassifier="./lib/stanford-ner-2015-12-09/classifiers/english.muc.7class.distsim.crf.ser.gz";
public String ner(String str) throws IOException, ClassNotFoundException {
AbstractSequenceClassifier<CoreLabel> classifier = CRFClassifier.getClassifier(serializedClassifier);
String taggedStr = classifier.classifyToString(str);
return taggedStr;
}
PS 1:我使用的是Java版本1.8,和follwing文件NERDemo.java。
PS 2:我得到了同樣的情況放在POS機上標註器相同的異常。