2016-06-12 7 views
0

私はStanfordNLPを稼動させています。次のようにStanfordNLP Openieが失敗する

私のMavenの依存構造がある:

<dependency> 
 
    <groupId>edu.stanford.nlp</groupId> 
 
    <artifactId>stanford-corenlp</artifactId> 
 
    <version>3.6.0</version> 
 
</dependency> 
 
<dependency> 
 
    <groupId>edu.stanford.nlp</groupId> 
 
    <artifactId>stanford-corenlp</artifactId> 
 
    <version>3.6.0</version> 
 
    <classifier>models</classifier> 
 
</dependency>

次のように私のコードはうまく動作します:

@Test 
public void testTA() throws Exception 
{ 

    Path p = Paths.get("s.txt"); 

    byte[] encoded = Files.readAllBytes(p); 
    String s = new String(encoded); 

    Properties props = new Properties(); 
    props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse, ner, dcoref"); 
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

    // read some text in the text variable 
    String text = s; 

    StringBuffer sb = new StringBuffer(); 

    sb.append(text); 
    sb.append(
      "\n\n\n\n\n\n\n===================================================================\n\n\n\n\n\n\n\n\n\n\n"); 

    // create an empty Annotation just with the given text 
    Annotation document = new Annotation(text); 

    // run all Annotators on this text 
    pipeline.annotate(document); 

    // these are all the sentences in this document 
    // a CoreMap is essentially a Map that uses class objects as keys and 
    // has values with custom types 
    List<CoreMap> sentences = document.get(SentencesAnnotation.class); 

    sb.append(
      "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n+++++++++++++++++++++++SENTENCES++++++++++++++++++++++++++++\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); 
    for (CoreMap sentence : sentences) 
    { 
     // traversing the words in the current sentence 
     // a CoreLabel is a CoreMap with additional token-specific methods 
     sb.append("\n\n\n==============SENTENCE==============\n\n\n"); 
     sb.append(sentence.toString()); 
     sb.append("\n"); 
     for (CoreLabel token : sentence.get(TokensAnnotation.class)) 
     { 
      // this is the text of the token 
      sb.append("\n==============TOKEN==============\n"); 
      String word = token.get(TextAnnotation.class); 
      sb.append(word); 
      sb.append(" : "); 
      // this is the POS tag of the token 
      String pos = token.get(PartOfSpeechAnnotation.class); 
      // this is the NER label of the token 
      sb.append(pos); 
      sb.append(" : "); 
      String lemma = token.get(LemmaAnnotation.class); 
      sb.append(lemma); 
      sb.append(" : "); 
      String ne = token.get(NamedEntityTagAnnotation.class); 
      sb.append(ne); 
      sb.append("\n"); 

     } 

     // this is the parse tree of the current sentence 
     Tree tree = sentence.get(TreeAnnotation.class); 
     sb.append("\n\n\n=====================TREE==================\n\n\n"); 
     sb.append(tree.toString()); 

     // this is the Stanford dependency graph of the current sentence 
     SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class); 
     sb.append("\n\n\n"); 
     sb.append(dependencies.toString()); 
    } 

しかし、私はパイプラインにopenieを追加するとき、コードは失敗します。

props.setProperty( "annotators"、 "tokenize、ssplit、pos、lemma、parse、ner、dcoref、openie");

次のように私が手にエラーがある:

注釈「openieは、」注釈「NATLOGは」

誰もがこの上で私を助言することができます必要が?

答えて

1

答えは、パイプライン内の注釈が互いに依存する可能性があることです。 パイプラインにnatlogを追加するだけです。 最初に依存関係を追加する必要があります。

  • openyの前にnatlogをパイプラインに挿入する必要があります。
  • depparseは

    • 解析がdcoref前に、パイプライン内にある必要があり、

  • をNATLOG前脇としてパイプライン内でなければなりません。
+1

GitHubコード(つまり、3.6.0以降のCoreNLPのバージョン)では、パーズアノテータを既にお持ちの場合は、natlogの前にdepparseを追加しなくても実際に離れることができます。しかし、今のところ、annotatorsリストに 'lemma'と' openie'の間に 'depparse、natlog'を追加する必要があります。 –

+0

ありがとう、また、SOのstandfordNLPをサポートしている皆さん、ありがとうございます。本当に役に立ちました! – Jake

+0

@Gabor、あなたまたは同僚が次の質問を見ることができる場合:http://stackoverflow.com/questions/37803277/stanford-ner-abstractsequenceclassifier-vs-namedentitytagannotation 私はそれがコミュニティを助けてください。 – Jake

関連する問題