我想在这个网站https://stanfordnlp.github.io/CoreNLP/api.html上运行简单的程序 我的计划
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Properties;
import edu.stanford.nlp.ling.CoreAnnotations.NamedEntityTagAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.SentencesAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.util.CoreMap;
public class StanfordClass {
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
String text = "What is the Weather in Mumbai right now?";
Annotation document = new Annotation(text);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
for(CoreMap sentence: sentences) {
// traversing the words in the current sentence
// a CoreLabel is a CoreMap with additional token-specific methods
for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
// this is the text of the token
String word = token.get(TextAnnotation.class);
// this is the POS tag of the token
String pos = token.get(PartOfSpeechAnnotation.class);
// this is the NER label of the token
String ne = token.get(NamedEntityTagAnnotation.class);
System.out.println(String.format("Print: word: [%s] pos: [%s] ne: [%s]",word, pos, ne));
}
}
}
}
但是在线程“main”java.lang.OutOfMemoryError中获取Exception:Java堆空间
我尝试了什么 1.如果我从上面的代码中删除了ner(命名实体识别器)属性,即props.setProperty(“annotators”,“tokenize,ssplit,pos,lemma,parse”); 然后代码运行正常。 2.但是我需要ner(命名实体识别器)因此我在eclipse.ini文件中增加堆大小达1g并且确保这个大小足够用于该程序并且还确保在这种情况下堆大小不是问题。我觉得缺少了一些东西,但没有得到。
经过大量搜索后,Using Stanford CoreNLP得到答案
使用以下答案: - 1.Windows - >偏好 2.Java - >已安装的JRE 3.选择JRE并单击“编辑” 4.在默认VM参数字段中,键入“-Xmx1024M”。 (或者你的记忆偏好,1GB的ram是1024) 5.单击完成或确定。