2015-11-21 50 views
6
給出的公開信息提取

我試圖運行NLP使用在官方網站上給出的指令由斯坦福大學給出的openIE:http://nlp.stanford.edu/software/openie.shtml錯誤運行由斯坦福

java -mx1g -cp stanford-openie.jar:stanford-openie-models.jar edu.stanford.nlp.naturalli.OpenIE mytextfile.txt 

,但我收到以下錯誤:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<clinit>(StanfordCoreNLP.java:99) 
at edu.stanford.nlp.naturalli.OpenIE.main(OpenIE.java:679) 
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory 
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 
... 2 more 

當我再次運行提供的Java代碼:

package edu.stanford.nlp.naturalli; 

import edu.stanford.nlp.ie.util.RelationTriple; 
import edu.stanford.nlp.ling.CoreAnnotations; 
import edu.stanford.nlp.pipeline.Annotation; 
import edu.stanford.nlp.pipeline.StanfordCoreNLP; 
import edu.stanford.nlp.util.CoreMap; 

import java.util.Collection; 
import java.util.List; 
import java.util.Properties; 

public class OpenIEDemo { 

public static void main(String[] args) throws Exception { 
// Create the Stanford CoreNLP pipeline 
Properties props = new Properties(); 
props.setProperty("annotators", "tokenize,ssplit,pos,depparse,natlog,openie"); 
StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

// Annotate an example document. 
Annotation doc = new Annotation("Obama was born in Hawaii. He is our president."); 
pipeline.annotate(doc); 

// Loop over sentences in the document 
for (CoreMap sentence : doc.get(CoreAnnotations.SentencesAnnotation.class)) { 

    // Get the OpenIE triples for the sentence 
    Collection<RelationTriple> triples = sentence.get(NaturalLogicAnnotations.RelationTriplesAnnotation.class); 

    // Print the triples 
    for (RelationTriple triple : triples) { 
    System.out.println(triple.confidence + "\t" + 
     triple.subjectLemmaGloss() + "\t" + 
     triple.relationLemmaGloss() + "\t" + 
     triple.objectLemmaGloss()); 
    } 

    // Alternately, to only run e.g., the clause splitter: 
    List<SentenceFragment> clauses = new OpenIE(props).clausesInSentence(sentence); 
    for (SentenceFragment clause : clauses) { 
    System.out.println(clause.parseTree); 
    } 
} 
} 
} 

我得到了下一個錯誤:

Adding annotator tokenize 
TokenizerAnnotator: No tokenizer type provided. Defaulting to PTBTokenizer. 
Adding annotator ssplit 
Adding annotator pos 
Reading POS tagger model from edu/stanford/nlp/models/pos-tagger/english-left3words/english-left3words-distsim.tagger ... done [0,7 sec]. 
Adding annotator depparse 
Loading depparse model file: edu/stanford/nlp/models/parser/nndep/english_UD.gz ... 
PreComputed 100000, Elapsed Time: 1.159 (s) 
Initializing dependency parser done [3,5 sec]. 
Adding annotator natlog 
Exception in thread "main" java.lang.IllegalArgumentException: annotator "natlog" requires annotator "parse" 
at edu.stanford.nlp.pipeline.StanfordCoreNLP.construct(StanfordCoreNLP.java:297) 
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:126) 
at edu.stanford.nlp.pipeline.StanfordCoreNLP.<init>(StanfordCoreNLP.java:122) 
at stnfrd.OpenIEDemo.main(OpenIEDemo.java:33) 
/home/ue/.cache/netbeans/8.1/executor-snippets/run.xml:53: Java returned: 1 
BUILD FAILED (total time: 4 seconds) 

任何幫助將不勝感激。

+0

好了,第一個錯誤,你缺少的SLF4J庫。你能發佈整個錯誤,而不是僅僅那些部分? –

+0

謝謝你的幫助:) –

+0

我會修改問題來顯示整個代碼 –

回答

7
  1. 第一個錯誤是,你沒有SLF4J罐子,這是目前包括在GitHub上的最新版本:https://github.com/stanfordnlp/CoreNLP或者你可以在這裏找到特定的jar:http://www.slf4j.org/download.html

  2. 第二個錯誤是由「natlog」需要「解析」引起的。更改 「depparse」 到 「分析」:

    props.setProperty("annotators", "tokenize,ssplit,pos,parse,natlog,openie"); 
    
+0

對於那些誰下載文件從slf4j.org網站,你只需要slf4j-simple- [version] .jar和slf4j-api- [version] .jar – rj2700