【问题标题】:Using Stanford CoreNLP使用斯坦福 CoreNLP
【发布时间】:2012-01-23 05:29:44
【问题描述】:

我正在尝试使用 Stanford CoreNLP。我使用网络上的一些代码来了解共指工具发生了什么。我尝试在 Eclipse 中运行该项目,但一直遇到内存不足异常。我尝试增加堆大小,但没有任何区别。关于为什么这种情况不断发生的任何想法?这是特定于代码的问题吗?任何使用 CoreNLP 的方向都很棒。

编辑 - 添加代码

import edu.stanford.nlp.dcoref.CorefChain;
import edu.stanford.nlp.dcoref.CorefCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;


import java.util.Iterator;
import java.util.Map;
import java.util.Properties;


public class testmain {

    public static void main(String[] args) {

        String text = "Viki is a smart boy. He knows a lot of things.";
        Annotation document = new Annotation(text);
        Properties props = new Properties();
        props.put("annotators", "tokenize, ssplit, pos, parse, dcoref");
        StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
        pipeline.annotate(document);


        Map<Integer, CorefChain> graph = document.get(CorefCoreAnnotations.CorefChainAnnotation.class);



        Iterator<Integer> itr = graph.keySet().iterator();

        while (itr.hasNext()) {

             String key = itr.next().toString();

             String value = graph.get(key).toString();

             System.out.println(key + " " + value);      
        }

   }
}

【问题讨论】:

  • 我在 Eclipse 中使用 corenlp 和 -Xms4g,它工作正常。

标签: java eclipse nlp stanford-nlp


【解决方案1】:

我在 Eclipse 中使用 Stanford CoreNLP 构建小型应用程序时发现了类似的问题。
增加 Eclipse 的堆大小不会解决您的问题。
进行搜索后,应该增加 ant build tool 堆大小,但我不知道该怎么做。
所以我放弃了 Eclipse,改用 Netbeans。

PS:您最终会在 Netbeans 中使用默认设置出现内存不足异常。但是可以通过调整每个应用程序的设置 -Xms 来轻松解决。

【讨论】:

  • 谢谢!那可是救命啊!这个内存问题让我发疯了!你是怎么发现问题出在蚂蚁身上的?
  • 我做了一些谷歌搜索。如果您找到设置 ant 堆大小的方法,请告诉我。
  • [This] (soenkerohde.com/2008/06/…) 网站有答案,但我不确定为什么它仍然不起作用。另外,如果你在线,我想和你聊天!
  • 此刻我做不到。我要出去了你可以给我发一封电子邮件 [kyu dot helf at gmail dot com]
  • 改用 Netbeans 是避免内存不足异常的唯一方法吗?
【解决方案2】:

修复 Eclipse:您可以在 Eclipse 首选项中进行如下配置

  1. Windows -> 首选项(在 Mac 上是:eclipse -> 首选项)
  2. Java -> 已安装的 JRE
  3. 选择 JRE 并单击编辑
  4. 在默认 VM 参数字段中,输入“-Xmx1024M”。 (或您的内存偏好,对于 1GB 的 ram 其 1024)
  5. 点击完成或确定。

【讨论】:

    【解决方案3】:

    我认为您可以在 VM 参数下的右键单击->运行->运行配置中定义堆大小。我已经在 mac 上测试过了,它可以工作。

    【讨论】:

      猜你喜欢
      • 2019-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-05
      • 1970-01-01
      相关资源
      最近更新 更多