2015-06-16 4 views
0

Я пытаюсь leematize предложения, используя Стэнфордский NLP, используя следующий кодStanford CoreNLP - Leematisation слов

import java.util.*; 
import edu.stanford.nlp.pipeline.*; 
import edu.stanford.nlp.ling.*; 
import edu.stanford.nlp.ling.CoreAnnotations.*; 
import edu.stanford.nlp.util.CoreMap; 

public class Entry 
{ 
    public static void main(String[] args) 
    { 
     Properties props = new Properties(); 
     props.put("annotators", "tokenize, ssplit, pos, lemma"); 
     StanfordCoreNLP pipeline; 
     pipeline = new StanfordCoreNLP(props, false); 
     String text = "This is my text"; 
     Annotation document = pipeline.process(text); 

     for(CoreMap sentence: document.get(SentencesAnnotation.class)) 
     { 
      for(CoreLabel token: sentence.get(TokensAnnotation.class)) 
      { 
       String word = token.get(TextAnnotation.class); 
       String lemma = token.get(LemmaAnnotation.class); 
       System.out.println("lemmatized version :" + lemma); 
      } 
     } 
    } 
} 

Компилятор бросает мне следующую ошибку

Exception in thread "main" java.lang.RuntimeException: edu.stanford.nlp.io.RuntimeIOException : Unrecoverable error while loading a tagger model 
at edu.stanford.nlp.pipeline.StanfordCoreNLP$4.create(StanfordCoreNLP.java:558) 
at edu.stanford.nlp.pipeline.AnnotatorPool.get(AnnotatorPool.java:85) 
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:267) 
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:129) 
at Entry.main(Entry.java:14) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:483) 
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) 
Caused by : edu.stanford.nlp.io.RuntimeIOException : Unrecoverable error while loading a tagger model 
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:763) 
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:294) 
at edu.stanford.nlp.tagger.maxent.MaxentTagger.<init>(MaxentTagger.java:259) 
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.loadModel(POSTaggerAnnotator.java:97) 
at edu.stanford.nlp.pipeline.POSTaggerAnnotator.<init>(POSTaggerAnnotator.java:77) 
at edu.stanford.nlp.pipeline.StanfordCoreNLP$4.create(StanfordCoreNLP.java:556) 
... 9 more 
Caused by : java.io.IOException : Unable to resolve "edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger" as either class path, filename or URL 
at edu.stanford.nlp.io.IOUtils.getInputStreamFromURLOrClasspathOrFileSystem(IOUtils.java:446) 
at edu.stanford.nlp.tagger.maxent.MaxentTagger.readModelAndInit(MaxentTagger.java:758) 
... 14 more 

Я скачал банку файлы библиотеки CoreNLP, и я использую Idea IntelliJ. Невозможно понять ошибку, Кто-нибудь знает?

+0

Файл, на который ссылается это IOException, должен находиться в пути к классам или находиться по отношению к рабочему каталогу приложения, поэтому проверьте это. Он находится внутри банки, убедитесь, что jar находится на пути к классам. Для установки рабочего каталога при работе внутри Idea посмотрите их документацию. – Thomas

+0

Другой вариант - поместить файл тегатора на сервер и вызвать его через http – farrellmr

ответ

0

Возможно, вам не хватает * models.jar. Если память не является серьезной проблемой, я обнаружил, что компиляция полного пакета corenlp в одну банку (включая модели) - это самый простой способ развертывания StanfordNLP.

несложный способ клонировать Git репо и построить банку:

git clone https://github.com/stanfordnlp/CoreNLP.git 
cd CoreNLP 
ant jar 

Затем, в любое время компиляции и запуска убедитесь, что вы включаете в результате банку:

javac -cp /path/to/javanlp-core.jar my.java 

EDIT: Это мне кажется, что способ простенький, скорее всего, будет строить с maven и включать в себя Stanford NLP в качестве зависимости, но если вы ищете более легкий вес, тогда это работает.

Смежные вопросы