利用英语语法关系 - 依赖解析器获得短语动词

时间:2015-10-11 14:59:54

标签: java nlp stanford-nlp

我有以下代码正确识别短语动词,但屈服似乎很棘手。我想采用短语动词部分(复合:prt(来,下))。我读过斯坦福的依赖手册,但没有找到任何帮助。我花了两倍的时间搞清楚我在做错的地方。

import edu.stanford.nlp.trees.*;
import edu.stanford.nlp.parser.lexparser.*;
import edu.stanford.nlp.process.*;
import java.util.Collection;
import java.util.*;
import java.io.*;

class dependencyParser {
   public static void main(String []args) throws Exception {
      String text = "Come down from the tree.";
      TreebankLanguagePack tlp = new PennTreebankLanguagePack();
      GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
      LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz");
      //lp.setOptionFlags(new String[]{"-maxLength", "500", "-retainTmpSubcategories"});
      TokenizerFactory tokenizerFactory = PTBTokenizer.factory( new CoreLabelTokenFactory(), "");
      List wordList = tokenizerFactory.getTokenizer(new StringReader(text)).tokenize();
      Tree tree = lp.apply(wordList);



System.out.println(tree);

  GrammaticalStructure gs = gsf.newGrammaticalStructure(tree);
  Collection<TypedDependency> typedDependencies = gs.typedDependenciesCollapsed();
 // System.out.println(tdl);
 // Main.writeImage(tree,tdl, "image.png",3);
  System.out.println();

  for(TypedDependency td : gs.typedDependencies()) {
  if(td.reln().equals(EnglishGrammaticalRelations.PHRASAL_VERB_PARTICLE)) {
              System.out.println( td);
  }
  }

 }
}

0 个答案:

没有答案