我的主要问题是我不知道如何从 GrammaticalStructure 中提取节点。我在 java netbeans 中使用englishPCFG.ser。我的目标是了解屏幕的质量,例如:
iphone 4的屏幕很棒。
我想提取屏幕,很棒。如何提取 NN (screen) 和 VP (great) ?
我写的代码是:
LexicalizedParser lp = new LexicalizedParser("C:\\englishPCFG.ser");
lp.setOptionFlags(new String[]{"-maxLength", "80", "-retainTmpSubcategories"});
String sent ="the screen is very good.";
Tree parse = (Tree) lp.apply(Arrays.asList(sent));
parse.pennPrint();
System.out.println();
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
GrammaticalStructureFactory gsf = tlp.grammaticalStructureFactory();
GrammaticalStructure gs = gsf.newGrammaticalStructure(parse);
Collection tdl = gs.typedDependenciesCollapsed();