2016-05-10 10 views
1

私はスタンフォードCoreNLP(01.2016バージョン)を使用しています。従属関係に句読点を残しておきたいと思います。私はあなたがコマンドラインからそれを実行するときにそれを行うためのいくつかの方法を見つけましたが、私は依存関係を抽出するJavaコードに関する何も見つかりませんでした。スタンフォード依存パーサーの句読法を維持する方法

ここは私の現在のコードです。私は句読点を含めたい など、

Annotation document = new Annotation(text); 

     Properties props = new Properties(); 

     props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse"); 

     props.setProperty("ssplit.newlineIsSentenceBreak", "always"); 

     props.setProperty("ssplit.eolonly", "true"); 

     props.setProperty("pos.model", modelPath1); 

     props.put("parse.model", modelPath); 

     StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

     pipeline.annotate(document); 

     LexicalizedParser lp = LexicalizedParser.loadModel(modelPath + lexparserNameEn, 

       "-maxLength", "200", "-retainTmpSubcategories"); 

     TreebankLanguagePack tlp = new PennTreebankLanguagePack(); 

     GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory(); 

     List<CoreMap> sentences = document.get(SentencesAnnotation.class); 

     for (CoreMap sentence : sentences) { 

      List<CoreLabel> words = sentence.get(CoreAnnotations.TokensAnnotation.class);    

      Tree parse = lp.apply(words); 

      GrammaticalStructure gs = gsf.newGrammaticalStructure(parse); 
      Collection<TypedDependency> td = gs.typedDependencies(); 

      parsedText += td.toString() + "\n"; 

依存関係の任意の種類は、私にとってはOK基本的な、型付けされ、崩壊:それは動作しますが、何の句読点は含まれません。事前に

おかげで、

答えて

1

あなたがlp.apply(words)を呼び出すことにより、一度CoreNLPてから、再度パーサを実行しているとして、あなたがここに余分な作業のかなりを行っています。

句読点付きの依存関係ツリー/グラフを取得する最も簡単な方法は、CoreNLPオプションparse.keepPunctを以下のように使用することです。

Annotation document = new Annotation(text); 
Properties props = new Properties(); 
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, parse"); 
props.setProperty("ssplit.newlineIsSentenceBreak", "always"); 
props.setProperty("ssplit.eolonly", "true"); 
props.setProperty("pos.model", modelPath1); 
props.setProperty("parse.model", modelPath); 
props.setProperty("parse.keepPunct", "true"); 

StanfordCoreNLP pipeline = new StanfordCoreNLP(props); 

pipeline.annotate(document); 

for (CoreMap sentence : sentences) { 
    //Pick whichever representation you want 
    SemanticGraph basicDeps = sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class); 
    SemanticGraph collapsed = sentence.get(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation.class); 
    SemanticGraph ccProcessed = sentence.get(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation.class); 
} 

文注釈オブジェクトストアSemanticGraphとして依存ツリー/グラフ。 TypedDependencyオブジェクトのリストが必要な場合は、メソッドtypedDependencies()を使用してください。たとえば、

List<TypedDependency> dependencies = basicDeps.typedDependencies(); 
+1

最後の 'true'は' 'true ''でなければなりません 'setProperty'は' String、String' – peer

関連する問題