简体   繁体   English

使用Stanford CoreNLP

[英]Using Stanford CoreNLP

I am trying to get around using the Stanford CoreNLP. 我正在尝试使用Stanford CoreNLP。 I used some code from the web to understand what is going on with the coreference tool. 我使用Web上的一些代码来了解coreference工具的用途。 I tried running the project in Eclipse but keep encountering an out of memory exception. 我尝试在Eclipse中运行该项目但仍遇到内存不足异常。 I tried increasing the heap size but there isnt any difference. 我尝试增加堆大小,但没有任何区别。 Any ideas on why this keeps happening? 关于为什么会这种情况发生的任何想法? Is this a code specific problem? 这是特定于代码的问题吗? Any directions of using CoreNLP would be awesome. 任何使用CoreNLP的方向都会很棒。

EDIT - Code Added 编辑 - 已添加代码

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);      
        }

   }
}

I found similar problem when building small application using Stanford CoreNLP in Eclipse. 我在Eclipse中使用Stanford CoreNLP构建小型应用程序时发现了类似的问题。
Increasing Eclipse's heap size will not solve your problem. 增加Eclipse的堆大小不会解决您的问题。
After doing search, it is ant build tool heap size that should be increased, but I have no idea how to do that. 在进行搜索之后,应该增加ant构建工具堆大小,但我不知道该怎么做。
So I give up Eclipse and use Netbeans instead. 所以我放弃Eclipse并改用Netbeans。

PS: You will eventually get out of memory exception with default setting in Netbeans. PS: Netbeans中的默认设置最终会导致内存不足。 But it can easily solved by adjust setting -Xms per application basis. 但它可以通过调整设置-Xms每个应用程序轻松解决。

Fix for eclipse: You can configure this in eclipse preference as follows 修复eclipse:你可以在eclipse偏好中配置如下

  1. Windows -> Preferences ( on mac it's: eclipse ->preferences) Windows - >首选项(在Mac上:eclipse - >首选项)
  2. Java -> Installed JREs Java - >已安装的JRE
  3. Select the JRE and click on Edit 选择JRE并单击Edit
  4. On the default VM arguments field, type in "-Xmx1024M". 在默认的VM参数字段中,键入“-Xmx1024M”。 (or your memory preference, for 1GB of ram its 1024) (或者你的记忆偏好,1GB的RAM是1024)
  5. Click on finish or OK. 点击完成或确定。

I think you can define the heap size in right-click->run->run-configurations under the VM arguments. 我认为您可以在VM参数下的右键单击 - >运行 - >运行配置中定义堆大小。 i have tested it on mac and it works. 我已经在Mac上测试了它,它的工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM