2017-12-26 3 views
1
나는이 웹 사이트에서 사용 가능한 간단한 프로그램을 실행하려고

https://stanfordnlp.github.io/CoreNLP/api.html
내 프로그램스탠포드 CoreNLP - 스레드의 예외 "주요"java.lang.OutOfMemoryError와 : Java 힙 공간

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 힙 공간

내가 NER (개체 명 인식기)를 제거하면 내가
1. 시도 ​​무엇 적절한 ty from code 즉 props.setProperty ("annotators", "tokenize, ssplit, pos, lemma, parse");
그러면 코드가 제대로 실행됩니다.
2. 그러나 ner (엔티티 인식기)가 필요합니다. 따라서 eclipse.ini 파일에서 힙 크기를 1g까지 늘리십시오.이 정도의 크기가이 프로그램에 충분하고 힙 크기가이 문제에서 문제가 아닌지 확인하십시오. 케이스. 나는 뭔가 빠져 있지만 그것을 얻지 못한다고 생각한다.

+0

메모리를 더 많이 차지하는 방법을 확인 했습니까? – meditat

+0

어떻게 확인해야합니까? –

+0

이것은 자바 5까지 적용 가능하지만 자바 8과 힙 크기를 1GB까지 사용하는 것은이 간단한 프로그램에 너무 많은 것입니다 –

답변

0

검색을 많이 여기 Using Stanford CoreNLP

를 사용하여 다음과 같은 대답 원치 도착 후 : -
1.Windows -> 환경 설정
2.Java -> 설치된 JRE를
3.Select JRE를 클릭 on 편집
4. 기본 VM 인수 필드에 "-Xmx1024M"을 입력하십시오. (또는 귀하의 메모리 환경 설정, 램 1GB의 경우 1024)
5. 마침을 클릭하거나 확인을 클릭하십시오.

+0

작동하기 전에 힙 공간을 4GB로 설정해야했습니다. 즉 "-Xmx4096M"그러나 그렇습니다! :) 작업 관리자 (Windows 10)에서 Eclipse를 보는 동안 데모 프로그램이 끝나기 직전에 메모리 풋 프린트가 5.9GB까지 올라갔습니다. 놀랄 일도 아니고 자연 언어 처리에는 많은 RAM이 필요합니다. – LionelGoulet