Stanford CoreNLP-线程中的异常;“主要”;java.lang.OutOfMemoryError:java堆空间

Stanford CoreNLP-线程中的异常;“主要”;java.lang.OutOfMemoryError:java堆空间,java,stanford-nlp,eclipse-neon,Java,Stanford Nlp,Eclipse Neon,我正在尝试运行此网站上提供的简单程序 我的节目 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; im

我正在尝试运行此网站上提供的简单程序
我的节目

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));
          }
        }
    }
}  
导入java.io.BufferedReader;
导入java.io.BufferedWriter;
导入java.io.FileNotFoundException;
导入java.io.FileReader;
导入java.io.FileWriter;
导入java.io.IOException;
导入java.io.PrintWriter;
导入java.util.List;
导入java.util.Properties;
导入edu.stanford.nlp.ling.CoreAnnotations.NamedEntityTagAnnotation;
导入edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;
导入edu.stanford.nlp.ling.CoreAnnotations.SentencesAnotation;
导入edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;
导入edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;
导入edu.stanford.nlp.ling.corelab;
导入edu.stanford.nlp.pipeline.Annotation;
导入edu.stanford.nlp.pipeline.StanfordCoreNLP;
导入edu.stanford.nlp.util.CoreMap;
公共课斯坦福德课{
公共静态void main(字符串[]args)引发异常{
Properties props=新属性();
props.setProperty(“注释器”、“标记化、ssplit、pos、引理、ner、解析”);
StanfordCoreNLP管道=新的StanfordCoreNLP(道具);
String text=“孟买现在的天气如何?”;
注释文档=新注释(文本);
管道注释(文件);
列出句子=document.get(SentencesAnnotation.class);
for(CoreMap句子:句子){
//遍历当前句子中的单词
//CoreLabel是一个CoreMap,具有额外的令牌特定方法
for(CoreLabel标记:句子.get(TokensAnnotation.class)){
//这是令牌的文本
String word=token.get(TextAnnotation.class);
//这是令牌的POS标记
String pos=token.get(speechannotation.class的一部分);
//这是令牌的NER标签
字符串ne=token.get(NamedEntityTagAnnotation.class);
System.out.println(String.format(“Print:word:[%s]pos:[%s]ne:[%s]”,word,pos,ne));
}
}
}
}  
但是在线程“main”java.lang.OutOfMemoryError中获取异常:java堆空间

我尝试的
1.如果我从上述代码中删除了ner(命名实体识别器)属性,即props.setProperty(“注释器”、“标记化”、“ssplit”、“pos”、“引理”、“解析”)
然后代码运行正常。

2.但我需要ner(命名实体识别器),因此我将eclipse.ini文件中的堆大小增加到1g,并确保此大小对于该程序来说足够大,同时确保在这种情况下堆大小不是问题。我认为缺少了一些东西,但没有得到答案。

经过大量搜索,这里得到了答案

使用以下答案:-
1.Windows->首选项
2.Java->已安装的JRE
3.选择JRE并单击编辑
4.在默认VM参数字段中,键入“-Xmx1024M”。(或者您的内存偏好,1GB的ram是1024)

5.单击“完成”或“确定”。

您是否检查了占用更多内存的方法?我应该如何检查?这适用于Java 5,但我使用的是Java 8,堆大小高达1gb,对于这个简单的程序来说太多了哦,对不起,我忘了用这个了,我用过eclipse内存分析器,没有内存方面的问题,我必须在它工作之前将堆空间设置为4GB。i、 e.“-Xmx4096M”但后来,它成功了!:)在任务管理器(Windows10)中观看Eclipse时,在演示程序完成之前,内存占用上升到5.9GB。毫不奇怪,自然语言处理需要大量RAM。