我只是打從StanfordNLP的內臟奇數異常,當試圖來標記:斯坦福標記者NullPointerException異常
顯示java.lang.NullPointerException在 edu.stanford.nlp.process.PTBLexer.zzRefill( PTBLexer.java:24511)在 edu.stanford.nlp.process.PTBLexer.next(PTBLexer.java:24718)在 edu.stanford.nlp.process.PTBTokenizer.getNext(PTBTokenizer.java:276) 在 EDU .stanford.nlp.process.PTBTokenizer.getNext(PTBTokenizer.java:163) at edu.stanford.nlp.process.AbstractTokenizer.hasNext(AbstractTokeniz er.java:55) 在 edu.stanford.nlp.process.DocumentPreprocessor $ PlainTextIterator.primeNext(DocumentPreprocessor.java:270) 在 edu.stanford.nlp.process.DocumentPreprocessor $ PlainTextIterator.hasNext(DocumentPreprocessor.java: 334)
導致它看起來像這樣的代碼:
DocumentPreprocessor dp = new DocumentPreprocessor(new StringReader( tweet)); // unigrams for (List<HasWord> sentence : dp) { for (HasWord word : sentence) { // do stuff } } // bigrams for (List<HasWord> sentence : dp) { //<< exception is thrown here Iterator<HasWord> it = sentence.iterator(); String st1 = it.next().word(); while (it.hasNext()) { String st2 = it.next().word(); String bigram = st1 + " " + st2; // do stuff st1 = st2; } }
這是怎麼回事?這跟我做了兩次循環令牌嗎?