首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >斯坦福CoreNLP -线程“主”java.lang.OutOfMemoryError中的异常: Java堆空间

斯坦福CoreNLP -线程“主”java.lang.OutOfMemoryError中的异常: Java堆空间
EN

Stack Overflow用户
提问于 2017-12-26 06:15:22
回答 1查看 2.7K关注 0票数 4

我试图在这个网站https://stanfordnlp.github.io/CoreNLP/api.html上运行一个简单的程序

我的程序

代码语言:javascript
复制
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.lang.OutOfMemoryError中获得异常:Java堆空间

我试过什么

  1. 如果我从上述代码中删除ner (命名实体识别器)属性,即props.setProperty("annotators","tokenize,ssplit,pos,引理,解析“); 然后代码就可以正常运行了。 2.但是我需要ner(命名实体识别器),因此我将eclipse.ini文件中的堆大小增加到1g,并确保对于这个程序来说,这么大的大小已经足够了,而且在这种情况下,堆大小也不是问题。我想有什么东西不见了,但还没明白。
EN

回答 1

Stack Overflow用户

发布于 2017-12-27 09:44:23

在大量搜索得到答案之后,Using Stanford CoreNLP

使用以下答案:-

1.Windows ->首选项

2.安装了Java ->

3.选择JRE并单击Edit

4.在默认VM参数字段中,键入"-Xmx1024M“。(或者您的内存首选项,对于1GB的ram,是1024)

5.点击finish或OK。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47974590

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档