2012-01-23 118 views
7

我想解決使用斯坦福CoreNLP。我使用了Web上的一些代碼來了解coreference工具正在發生什麼。我嘗試在Eclipse中運行該項目,但仍遇到內存不足異常。我試圖增加堆大小,但沒有任何區別。任何想法爲什麼這種情況繼續發生?這是一個代碼特定的問題?任何使用CoreNLP的方向都很棒。使用斯坦福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);  
     } 

    } 
} 
+0

在這裏發佈代碼 –

+0

@Pangea添加代碼。 –

+0

我用-Xms4g在eclipse中使用corenlp,它工作正常。 – alienCoder

回答

4

我建立在Eclipse中使用斯坦福CoreNLP小應用程序時,發現了類似的問題。
增加Eclipse的堆大小並不能解決您的問題。
做了搜索之後,它是ant構建工具應該增加堆大小,但我不知道該怎麼做。
所以我放棄了Eclipse並改用Netbeans。

PS:在Netbeans中,您最終會遇到內存不足的情況。但通過調整設置-Xms可以輕鬆解決每個應用程序的基礎。

  • 爪哇 - >安裝的JRE
  • 選擇

  • +0

    謝謝!這是一個拯救生命的人!這個記憶問題讓我瘋狂!你怎麼知道問題出在螞蟻身上? –

    +0

    我做了一些Google搜索。讓我知道如果你找到方法來設置螞蟻堆大小。 – Khairul

    +0

    [This](http://soenkerohde.com/2008/06/change-eclipse-ant-settings-when-you-run-out-of-memory/)網站有一個答案,但我不知道爲什麼它仍然沒有工作。另外,如果你在線,我想和你聊聊! –

    3

    修正了日食: - - >首選項(Eclipse的>首選項在Mac上它的),你可以在Eclipse的偏好如下

    1. 配置Windows此JRE並單擊編輯
    2. 在默認VM參數字段中,輸入「-Xmx1024M」。 (或者你的內存偏好,對於1GB的內存條,它的1024)
    3. 點擊完成或確定。
    2

    我認爲你可以在VM參數下右鍵單擊 - >運行 - >運行配置來定義堆大小。我已經在Mac上測試過它,它工作。